Class DelegatingEList<E>

All Implemented Interfaces:
Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, SequencedCollection<E>, EList<E>
Direct Known Subclasses:
DelegatingEList.UnmodifiableEList, DelegatingNotifyingListImpl

public abstract class DelegatingEList<E> extends AbstractEList<E> implements Cloneable, Serializable
A highly extensible delegating list implementation.
See Also:
  • Constructor Details

    • DelegatingEList

      public DelegatingEList()
      Creates an empty instance.
    • DelegatingEList

      public DelegatingEList(Collection<? extends E> collection)
      Creates an instance that is a copy of the collection.
      Parameters:
      collection - the initial contents of the list.
  • Method Details

    • delegateList

      protected abstract List<E> delegateList()
      Returns the list that acts as the backing store.
      Returns:
      the list that acts as the backing store.
    • size

      public int size()
      Returns the number of objects in the list.
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in interface List<E>
      Specified by:
      size in class AbstractCollection<E>
      Returns:
      the number of objects in the list.
    • delegateSize

      protected int delegateSize()
      Returns the number of objects in the backing store list.
      Returns:
      the number of objects in the backing store list.
    • isEmpty

      public boolean isEmpty()
      Returns whether the list has zero size.
      Specified by:
      isEmpty in interface Collection<E>
      Specified by:
      isEmpty in interface List<E>
      Overrides:
      isEmpty in class AbstractCollection<E>
      Returns:
      whether the list has zero size.
    • delegateIsEmpty

      protected boolean delegateIsEmpty()
      Returns whether the backing store list has zero size.
      Returns:
      whether the backing store list has zero size.
    • contains

      public boolean contains(Object object)
      Returns whether the list contains the object.
      Specified by:
      contains in interface Collection<E>
      Specified by:
      contains in interface List<E>
      Overrides:
      contains in class AbstractCollection<E>
      Parameters:
      object - the object in question.
      Returns:
      whether the list contains the object.
    • delegateContains

      protected boolean delegateContains(Object object)
      Returns whether the backing store list contains the object.
      Parameters:
      object - the object in question.
      Returns:
      whether the backing store list contains the object.
    • containsAll

      public boolean containsAll(Collection<?> collection)
      Returns whether the list contains each object in the collection.
      Specified by:
      containsAll in interface Collection<E>
      Specified by:
      containsAll in interface List<E>
      Overrides:
      containsAll in class AbstractCollection<E>
      Returns:
      whether the list contains each object in the collection.
      See Also:
    • delegateContainsAll

      protected boolean delegateContainsAll(Collection<?> collection)
      Returns whether the backing store list contains each object in the collection.
      Returns:
      whether the backing store list contains each object in the collection.
      See Also:
    • indexOf

      public int indexOf(Object object)
      Returns the position of the first occurrence of the object in the list.
      Specified by:
      indexOf in interface List<E>
      Overrides:
      indexOf in class AbstractList<E>
      Parameters:
      object - the object in question.
      Returns:
      the position of the first occurrence of the object in the list.
    • delegateIndexOf

      protected int delegateIndexOf(Object object)
      Returns the position of the first occurrence of the object in the backing store list.
      Parameters:
      object - the object in question.
      Returns:
      the position of the first occurrence of the object in the backing store list.
    • lastIndexOf

      public int lastIndexOf(Object object)
      Returns the position of the last occurrence of the object in the list.
      Specified by:
      lastIndexOf in interface List<E>
      Overrides:
      lastIndexOf in class AbstractList<E>
      Parameters:
      object - the object in question.
      Returns:
      the position of the last occurrence of the object in the list.
    • delegateLastIndexOf

      protected int delegateLastIndexOf(Object object)
      Returns the position of the last occurrence of the object in the backing store list.
      Parameters:
      object - the object in question.
      Returns:
      the position of the last occurrence of the object in the backing store list.
    • toArray

      public Object[] toArray()
      Returns an array containing all the objects in sequence.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<E>
      Overrides:
      toArray in class AbstractCollection<E>
      Returns:
      an array containing all the objects in sequence.
    • delegateToArray

      protected Object[] delegateToArray()
      Returns an array containing all the objects in the backing store list in sequence.
      Returns:
      an array containing all the objects in the backing store list in sequence.
    • toArray

      public <T> T[] toArray(T[] array)
      Returns an array containing all the objects in sequence.
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<E>
      Overrides:
      toArray in class AbstractCollection<E>
      Parameters:
      array - the array that will be filled and returned, if it's big enough; otherwise, a suitably large array of the same type will be allocated and used instead.
      Returns:
      an array containing all the objects in sequence.
    • delegateToArray

      protected <T> T[] delegateToArray(T[] array)
      Returns an array containing all the objects in the backing store list in sequence.
      Parameters:
      array - the array that will be filled and returned, if it's big enough; otherwise, a suitably large array of the same type will be allocated and used instead.
      Returns:
      an array containing all the objects in sequence.
    • get

      public E get(int index)
      Returns the object at the index. This implementation delegates to resolve so that clients may transform the fetched object.
      Specified by:
      get in interface List<E>
      Specified by:
      get in class AbstractList<E>
      Parameters:
      index - the position in question.
      Returns:
      the object at the index.
      Throws:
      IndexOutOfBoundsException - if the index isn't within the size range.
      See Also:
    • delegateGet

      protected E delegateGet(int index)
      Returns the object at the index in the backing store list.
      Parameters:
      index - the position in question.
      Returns:
      the object at the index.
      Throws:
      IndexOutOfBoundsException - if the index isn't within the size range.
    • basicGet

      protected E basicGet(int index)
      Returns the object at the index without resolving it.
      Overrides:
      basicGet in class AbstractEList<E>
      Parameters:
      index - the position in question.
      Returns:
      the object at the index.
      Throws:
      IndexOutOfBoundsException - if the index isn't within the size range.
      See Also:
    • primitiveGet

      protected E primitiveGet(int index)
      Description copied from class: AbstractEList
      Returns the object at the index without resolving it and without range checking the index.
      Specified by:
      primitiveGet in class AbstractEList<E>
      Parameters:
      index - the position in question.
      Returns:
      the object at the index.
      See Also:
    • setUnique

      public E setUnique(int index, E object)
      Sets the object at the index and returns the old object at the index; it does no ranging checking or uniqueness checking. This implementation delegates to didSet and didChange.
      Specified by:
      setUnique in class AbstractEList<E>
      Parameters:
      index - the position in question.
      object - the object to set.
      Returns:
      the old object at the index.
      See Also:
    • delegateSet

      protected E delegateSet(int index, E object)
      Sets the object at the index in the backing store list and returns the old object at the index.
      Parameters:
      object - the object to set.
      Returns:
      the old object at the index.
    • addUnique

      public void addUnique(E object)
      Adds the object at the end of the list; it does no uniqueness checking. This implementation delegates to didAdd and didChange. after uniqueness checking.
      Specified by:
      addUnique in class AbstractEList<E>
      Parameters:
      object - the object to be added.
      See Also:
    • delegateAdd

      protected void delegateAdd(E object)
      Adds the object at the end of the backing store list.
      Parameters:
      object - the object to be added.
    • addUnique

      public void addUnique(int index, E object)
      Adds the object at the given index in the list; it does no ranging checking or uniqueness checking. This implementation delegates to didAdd and didChange.
      Specified by:
      addUnique in class AbstractEList<E>
      Parameters:
      object - the object to be added.
      See Also:
    • delegateAdd

      protected void delegateAdd(int index, E object)
      Adds the object at the given index in the backing store list.
      Parameters:
      object - the object to be added.
    • addAllUnique

      public boolean addAllUnique(Collection<? extends E> collection)
      Adds each object of the collection to the end of the list; it does no uniqueness checking. This implementation delegates to didAdd and didChange.
      Specified by:
      addAllUnique in class AbstractEList<E>
      Parameters:
      collection - the collection of objects to be added.
      See Also:
    • addAllUnique

      public boolean addAllUnique(int index, Collection<? extends E> collection)
      Adds each object of the collection at each successive index in the list and returns whether any objects were added; it does no ranging checking or uniqueness checking. This implementation delegates to didAdd and didChange.
      Specified by:
      addAllUnique in class AbstractEList<E>
      Parameters:
      index - the index at which to add.
      collection - the collection of objects to be added.
      Returns:
      whether any objects were added.
      See Also:
    • addAllUnique

      public boolean addAllUnique(Object[] objects, int start, int end)
      Adds each object from start to end of the array at the index of list and returns whether any objects were added; it does no ranging checking or uniqueness checking. This implementation delegates to delegatedAdd, didAdd, and didChange.
      Specified by:
      addAllUnique in class AbstractEList<E>
      Parameters:
      objects - the objects to be added.
      start - the index of first object to be added.
      end - the index past the last object to be added.
      Returns:
      whether any objects were added.
      See Also:
    • addAllUnique

      public boolean addAllUnique(int index, Object[] objects, int start, int end)
      Adds each object from start to end of the array at each successive index in the list and returns whether any objects were added; it does no ranging checking or uniqueness checking. This implementation delegates to delegatedAdd, didAdd, and didChange.
      Specified by:
      addAllUnique in class AbstractEList<E>
      Parameters:
      index - the index at which to add.
      objects - the objects to be added.
      start - the index of first object to be added.
      end - the index past the last object to be added.
      Returns:
      whether any objects were added.
      See Also:
    • remove

      public boolean remove(Object object)
      Removes the object from the list and returns whether the object was actually contained by the list. This implementation uses indexOf to find the object and delegates to remove(int) in the case that it finds the object.
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface List<E>
      Overrides:
      remove in class AbstractEList<E>
      Parameters:
      object - the object to be removed.
      Returns:
      whether the object was actually contained by the list.
    • removeAll

      public boolean removeAll(Collection<?> collection)
      Removes each object of the collection from the list and returns whether any object was actually contained by the list.
      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface List<E>
      Overrides:
      removeAll in class AbstractEList<E>
      Parameters:
      collection - the collection of objects to be removed.
      Returns:
      whether any object was actually contained by the list.
    • remove

      public E remove(int index)
      Removes the object at the index from the list and returns it. This implementation delegates to didRemove and didChange.
      Specified by:
      remove in interface List<E>
      Specified by:
      remove in class AbstractEList<E>
      Parameters:
      index - the position of the object to remove.
      Returns:
      the removed object.
      Throws:
      IndexOutOfBoundsException - if the index isn't within the size range.
    • delegateRemove

      protected E delegateRemove(int index)
      Removes the object at the index from the backing store list and returns it.
      Returns:
      the removed object.
      Throws:
      IndexOutOfBoundsException - if the index isn't within the size range.
    • retainAll

      public boolean retainAll(Collection<?> collection)
      Removes from the list each object not contained by the collection and returns whether any object was actually removed. This delegates to remove(int) in the case that it finds an object that isn't retained.
      Specified by:
      retainAll in interface Collection<E>
      Specified by:
      retainAll in interface List<E>
      Overrides:
      retainAll in class AbstractEList<E>
      Parameters:
      collection - the collection of objects to be retained.
      Returns:
      whether any object was actually removed.
    • clear

      public void clear()
      Clears the list of all objects.
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface List<E>
      Overrides:
      clear in class AbstractList<E>
    • doClear

      protected void doClear(int oldSize, Object[] oldData)
      Does the actual job of clearing all the objects.
      Parameters:
      oldSize - the size of the list before it is cleared.
      oldData - old values of the list before it is cleared.
    • delegateClear

      protected void delegateClear()
      Clears the backing store list of all objects.
    • move

      public E move(int targetIndex, int sourceIndex)
      Moves the object at the source index of the list to the target index of the list and returns the moved object. This implementation delegates to didMove and didChange.
      Specified by:
      move in interface EList<E>
      Specified by:
      move in class AbstractEList<E>
      Parameters:
      targetIndex - the new position for the object in the list.
      sourceIndex - the old position of the object in the list.
      Returns:
      the moved object.
      Throws:
      IndexOutOfBoundsException - if either index isn't within the size range.
    • delegateMove

      protected E delegateMove(int targetIndex, int sourceIndex)
      Moves the object at the source index in the backing store list by removing it and adding it at the new target index.
      Parameters:
      targetIndex - the new position for the object in the list.
      sourceIndex - the old position of the object in the list.
      Returns:
      the moved object.
      Throws:
      IndexOutOfBoundsException - if either index isn't within the size range.
      Since:
      2.3
    • equals

      public boolean equals(Object object)
      Returns whether the object is a list with corresponding equal objects. This implementation uses either equals or "==" depending on useEquals.
      Specified by:
      equals in interface Collection<E>
      Specified by:
      equals in interface List<E>
      Overrides:
      equals in class AbstractEList<E>
      Returns:
      whether the object is a list with corresponding equal objects.
      See Also:
    • delegateEquals

      protected boolean delegateEquals(Object object)
      Returns whether the object is a list with corresponding equal objects to those in the backing store list.
      Returns:
      whether the object is a list with corresponding equal objects.
    • hashCode

      public int hashCode()
      Returns a hash code computed from each object's hash code.
      Specified by:
      hashCode in interface Collection<E>
      Specified by:
      hashCode in interface List<E>
      Overrides:
      hashCode in class AbstractEList<E>
      Returns:
      a hash code.
    • delegateHashCode

      protected int delegateHashCode()
      Returns the hash code of the backing store list.
      Returns:
      a hash code.
    • toString

      public String toString()
      Returns a string of the form "[object1, object2]".
      Overrides:
      toString in class AbstractEList<E>
      Returns:
      a string of the form "[object1, object2]".
    • delegateToString

      protected String delegateToString()
      Returns a the string form of the backing store list.
      Returns:
      a the string form of the backing store list.
    • delegateIterator

      protected Iterator<E> delegateIterator()
      Returns an iterator over the backing store list.
      Returns:
      an iterator.
    • delegateListIterator

      protected ListIterator<E> delegateListIterator()
      Returns a list iterator over the backing store list.
      Returns:
      a list iterator.
    • basicList

      protected List<E> basicList()
      Returns an unsafe list that provides a non-resolving view of the backing store list.
      Specified by:
      basicList in class AbstractEList<E>
      Returns:
      an unsafe list that provides a non-resolving view of the backing store list.
    • delegateBasicList

      protected List<E> delegateBasicList()
      Returns an unsafe list that provides a non-resolving view of the backing store list.
      Returns:
      an unsafe list that provides a non-resolving view of the backing store list.