Class Key1List.ReadOnlyKey1List<E,​K>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess, ICollection<E>, IListable<E>
    Enclosing class:
    Key1List<E,​K>

    protected static class Key1List.ReadOnlyKey1List<E,​K>
    extends Key1List<E,​K>
    A read-only version of Key1List. It is used to implement both unmodifiable and immutable lists. Note that the client cannot change the list, but the content may change if the underlying list is changed.
    See Also:
    Serialized Form
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        UID for serialization
        See Also:
        Constant Field Values
    • Constructor Detail

      • ReadOnlyKey1List

        protected ReadOnlyKey1List​(Key1List<E,​K> that)
        Private constructor used internally.
        Parameters:
        that - list to create an immutable view of
    • Method Detail

      • doEnsureCapacity

        protected void doEnsureCapacity​(int capacity)
        Description copied from class: IList
        Increases the capacity of this list instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.
        Overrides:
        doEnsureCapacity in class KeyListImpl<E>
        Parameters:
        capacity - the desired minimum capacity
      • doAdd

        protected boolean doAdd​(int index,
                                E elem)
        Description copied from class: IList
        Helper method for adding an element to the list. This is the only method which really adds an element. Override if you need to validity checks before adding.
        Overrides:
        doAdd in class KeyListImpl<E>
        Parameters:
        index - index where element should be added (-1 means it is up to the implementation to choose the index)
        elem - element to add
        Returns:
        true if element has been added, false otherwise
      • doSet

        protected E doSet​(int index,
                          E elem)
        Description copied from class: IList
        Helper method for setting an element in the list. This is the only method which really sets an element. Override if you need to validity checks before setting.
        Overrides:
        doSet in class KeyListImpl<E>
        Parameters:
        index - index where element will be placed
        elem - element to set
        Returns:
        old element which was at the position
      • doReSet

        protected E doReSet​(int index,
                            E elem)
        Description copied from class: IList
        Sets an element at specified position. This method is used internally if existing elements will be moved etc. Override if you need to validity checks.
        Overrides:
        doReSet in class KeyListImpl<E>
        Parameters:
        index - index where element will be placed
        elem - element to set
        Returns:
        old element which was at the position
      • doRemove

        protected E doRemove​(int index)
        Description copied from class: IList
        Helper method to remove an element. This is the only method which really removes an element. Override if you need to validity checks before removing.
        Overrides:
        doRemove in class KeyListImpl<E>
        Parameters:
        index - index of element to remove
        Returns:
        removed element
      • doRemoveAll

        protected void doRemoveAll​(int index,
                                   int len)
        Description copied from class: IList
        Remove specified range of elements from list.
        Overrides:
        doRemoveAll in class KeyListImpl<E>
        Parameters:
        index - index of first element to remove
        len - number of elements to remove
      • doClear

        protected void doClear()
        Overrides:
        doClear in class IList<E>
      • doModify

        protected void doModify()
        Description copied from class: IList
        This method is called internally before elements are allocated or freed. Override if you need to validity checks.
        Overrides:
        doModify in class IList<E>
      • removeByKey

        protected E removeByKey​(int keyIndex,
                                java.lang.Object key)
        Description copied from class: KeyListImpl
        Removes element by key. If there are duplicates, only one element is removed.
        Overrides:
        removeByKey in class KeyListImpl<E>
        Parameters:
        keyIndex - key index
        key - key of element to remove
        Returns:
        removed element or null if no element has been removed
      • removeAllByKey

        protected IList<E> removeAllByKey​(int keyIndex,
                                          java.lang.Object key)
        Description copied from class: KeyListImpl
        Removes element by key. If there are duplicates, all elements are removed.
        Overrides:
        removeAllByKey in class KeyListImpl<E>
        Parameters:
        keyIndex - key index
        key - key of element to remove
        Returns:
        true if elements have been removed, false otherwise
      • putByKey

        protected E putByKey​(int keyIndex,
                             E elem,
                             boolean replace)
        Description copied from class: KeyListImpl
        Put element by key into list.
        Overrides:
        putByKey in class KeyListImpl<E>
        Parameters:
        keyIndex - key index
        elem - element to put
        replace - true to replace an existing element with the same key, false to let the element unchanged
        Returns:
        element with the same key (i.e. element which was replaced if replace is true / which was left unchanged if false), null if no element with the same key has been found
      • invalidateKey

        protected void invalidateKey​(int keyIndex,
                                     java.lang.Object oldKey,
                                     java.lang.Object newKey,
                                     E elem)
        Description copied from class: KeyListImpl
        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.
        Overrides:
        invalidateKey in class KeyListImpl<E>
        Parameters:
        keyIndex - key index
        oldKey - old key value
        newKey - new key value
        elem - element to invalidate (can be null if there are no duplicates with this key)
      • error

        private void error()
        Throw exception if an attempt is made to change an immutable list.