Class Key1Collection<E,​K>

  • Type Parameters:
    E - type of elements stored in the collection
    K - type of key
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, ICollection<E>
    Direct Known Subclasses:
    Key1Set

    public class Key1Collection<E,​K>
    extends KeyCollectionImpl<E>
    Key1Collection implements a collection with 1 key. This key can be accessed fast. It can provide fast access to its elements like a Set. The elements allowed in the collection can be constraint (null/duplicate values).
    See Also:
    Key1List, Serialized Form
    • Constructor Detail

      • Key1Collection

        protected Key1Collection()
        Protected constructor used by builder or derived collections.
    • Method Detail

      • put

        public E put​(E elem)
        Description copied from class: KeyCollectionImpl
        Adds or replaces element. If there is no such element, the element is added. If there is such an element, the element is replaced. So said simply, it is a shortcut for the following code:
         remove(elem);
         add(elem);
         
        However the method is atomic in the sense that all or none operations are executed. So if there is already such an element, but adding the new one fails due to a constraint violation, the old element remains in the list.
        Overrides:
        put in class KeyCollectionImpl<E>
        Parameters:
        elem - element
        Returns:
        element which has been replaced or null otherwise
      • invalidate

        public void invalidate​(E elem)
        Description copied from class: KeyCollectionImpl
        Invalidate element, i.e. all keys of the element are extracted again and stored in the key maps. Old key values are removed if needed. You must call an invalidate method if an element's key value has changed after adding it to the collection.
        Overrides:
        invalidate in class KeyCollectionImpl<E>
        Parameters:
        elem - element to invalidate
      • getKey1Mapper

        public java.util.function.Function<E,​K> getKey1Mapper()
        Returns mapper for key map.
        Returns:
        mapper for key map
      • asMap1

        public java.util.Map<K,​E> asMap1()
        Returns a map view to the key map. The collection can be modified through the map as long as the constraint are not violated. The collections returned by the methods entrySet(), keySet(), and values() are immutable however.
        Returns:
        map view to key map
        Throws:
        java.lang.IllegalArgumentException - if the key map cannot be viewed as Map
      • containsKey1

        public boolean containsKey1​(K key)
        Checks whether an element with specified key exists.
        Parameters:
        key - key
        Returns:
        true if element with specified key exists, otherwise false
      • getByKey1

        public E getByKey1​(K key)
        Returns element with specified key. If there are several elements with the same key, the one added first will be returned.
        Parameters:
        key - key
        Returns:
        element with specified key or null
      • getAllByKey1

        public Key1Collection<E,​K> getAllByKey1​(K key)
        Returns all elements with specified key.
        Parameters:
        key - key
        Returns:
        all elements with specified key (never null)
      • getCountByKey1

        public int getCountByKey1​(K key)
        Returns the number of elements with specified key.
        Parameters:
        key - key
        Returns:
        number of elements with specified key
      • removeByKey1

        public E removeByKey1​(K key)
        Removes element with specified key. If there are several elements with the same key, the one added first will be removed.
        Parameters:
        key - key
        Returns:
        element with specified key or null
      • removeAllByKey1

        public Key1Collection<E,​K> removeAllByKey1​(K key)
        Removes all elements with specified key.
        Parameters:
        key - key
        Returns:
        removed elements with specified key (never null)
      • getAllKeys1

        public IList<K> getAllKeys1()
        Returns list containing all keys in element order.
        Returns:
        list containing all keys
      • getDistinctKeys1

        public java.util.Set<K> getDistinctKeys1()
        Returns all distinct keys in the same order as in the key map.
        Returns:
        distinct keys
      • putByKey1

        public E putByKey1​(E elem)
        Adds element by key. If there is no such element, the element is added. If there is such an element, the element is replaced. So said simply, it is a shortcut for the following code:
         removeByKey1(elem.getKey1());
         add(elem);
         
        However the method is atomic in the sense that all or none operations are executed. So if there is already such an element, but adding the new one fails due to a constraint violation, the old element remains in the list.
        Parameters:
        elem - element
        Returns:
        element with the same key which has been replaced or null otherwise
      • invalidateKey1

        public void invalidateKey1​(K oldKey,
                                   K newKey,
                                   E elem)
        Invalidate key value of element. You must call an invalidate method if an element's key value has changed after adding it to the collection.
        Parameters:
        oldKey - old key value
        newKey - new key value
        elem - element to invalidate (can be null if there are no duplicates with this key)
      • filter

        public Key1Collection<E,​K> filter​(java.util.function.Predicate<? super E> filter)
        Description copied from interface: ICollection
        Create a new collection by applying the specified filter to all elements. The returned collection has the same type as the original one.
        Specified by:
        filter in interface ICollection<E>
        Overrides:
        filter in class KeyCollectionImpl<E>
        Parameters:
        filter - filter predicate
        Returns:
        created list