Class KeyList<E>

  • Type Parameters:
    E - type of elements stored in the list
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Deque<E>, java.util.List<E>, java.util.Queue<E>, java.util.RandomAccess, ICollection<E>
    Direct Known Subclasses:
    KeyList.ImmutableKeyList

    public class KeyList<E>
    extends KeyListImpl<E>
    KeyList implements a list. It can provide fast access to its elements like a Set. The elements allowed in the list can be constraint (null/duplicate values).
    See Also:
    Serialized Form
    • Constructor Detail

      • KeyList

        protected KeyList()
        Protected constructor used by builder or derived collections.
      • KeyList

        protected KeyList​(boolean copy,
                          KeyList<E> that)
    • Method Detail

      • getBuilder

        protected KeyList.Builder<E> getBuilder()
        Returns:
        builder to use in extending classes
      • copy

        public KeyList<E> copy()
        Description copied from class: IList
        Returns a shallow copy of this list. The new list will contain the same elements as the source list, i.e. the elements themselves are not copied. The capacity of the list will be set to the number of elements, i.e. size and capacity are equal. This returned list will be modifiable, i.e. an unmodifiable list will become modifiable again. This method is identical to clone() except that it returns an object with the exact type.
        Specified by:
        copy in interface ICollection<E>
        Overrides:
        copy in class KeyListImpl<E>
        Returns:
        a modifiable copy of this list
      • clone

        public java.lang.Object clone()
        Description copied from class: IList
        Returns a shallow copy of this list. The new list will contain the same elements as the source list, i.e. the elements themselves are not copied. The capacity of the list will be set to the number of elements, i.e. size and capacity are equal. This returned list will be modifiable, i.e. an unmodifiable list will become modifiable again. It is advised to use copy() which is identical except that it returns an object with the exact type.
        Overrides:
        clone in class KeyListImpl<E>
        Returns:
        a modifiable copy of this list
      • crop

        public KeyList<E> crop()
        Description copied from class: KeyListImpl
        Returns a copy this list but without elements. The new list will have the same type as this list and use the same comparator, ordering, etc.
        Specified by:
        crop in interface ICollection<E>
        Overrides:
        crop in class KeyListImpl<E>
        Returns:
        an empty copy of this list
      • getAll

        public IList<E> getAll​(E elem)
        Description copied from class: IList
        Returns all elements in the list equal to the specified element.
        Overrides:
        getAll in class KeyListImpl<E>
        Parameters:
        elem - element to look for
        Returns:
        all elements in the list equal to the specified element
      • count

        public int count​(E elem)
        Description copied from class: IList
        Counts how many times the specified element is contained in the list.
        Overrides:
        count in class KeyListImpl<E>
        Parameters:
        elem - element to count
        Returns:
        count how many times the specified element is contained in the list
      • removeAll

        public IList<E> removeAll​(E elem)
        Description copied from class: IList
        Removes all equal elements.
        Overrides:
        removeAll in class KeyListImpl<E>
        Parameters:
        elem - element
        Returns:
        removed equal elements (never null)
      • getDistinct

        public java.util.Set<E> getDistinct()
        Description copied from class: IList
        Returns distinct elements in the list.
        Overrides:
        getDistinct in class KeyListImpl<E>
        Returns:
        distinct elements in the list
      • put

        public E put​(E elem)
        Description copied from class: KeyListImpl
        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:
         if (contains(elem)) {
           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 KeyListImpl<E>
        Parameters:
        elem - element
        Returns:
        element which has been replaced or null otherwise
      • unmodifiableList

        public KeyList<E> unmodifiableList()
        Description copied from class: IList
        Returns an unmodifiable view of this list. This method allows modules to provide users with "read-only" access to internal lists. Query operations on the returned list "read through" to the specified list, and attempts to modify the returned list, whether direct or via its iterator, result in an UnsupportedOperationException. If this list is already unmodifiable, it is returned unchanged.
        Specified by:
        unmodifiableList in class IList<E>
        Returns:
        an unmodifiable view of the specified list