org.eclipse.emf.common.util

Class ArrayDelegatingEList<E>

    • Field Summary

      • Fields inherited from class java.util.AbstractList

        modCount
    • Constructor Summary

      Constructors 
      Modifier Constructor and Description
        ArrayDelegatingEList()
      Creates an empty instance with no initial capacity.
        ArrayDelegatingEList(java.util.Collection<? extends E> collection)
      Creates an instance that is a copy of the collection.
      protected ArrayDelegatingEList(java.lang.Object[] data)
      Creates an initialized instance that directly uses the given arguments.
    • Method Summary

      Methods 
      Modifier and Type Method and Description
      boolean addAllUnique(java.util.Collection<? extends E> collection)
      Adds each object of the collection to the end of the list; it does no uniqueness checking.
      boolean addAllUnique(int index, java.util.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.
      boolean addAllUnique(int index, java.lang.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.
      boolean addAllUnique(java.lang.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.
      void addUnique(E object)
      Adds the object at the end of the list; it does no uniqueness checking.
      void addUnique(int index, E object)
      Adds the object at the given index in the list; it does no ranging checking or uniqueness checking.
      protected E assign(java.lang.Object[] data, int index, E object)
      Assigns the object into the data storage at the given index and returns the object that's been stored.
      E basicGet(int index)
      Returns the object at the index without resolving it.
      protected java.util.Iterator<E> basicIterator()
      Returns a read-only iterator that does not resolve objects.
      protected java.util.List<E> basicList()
      Returns an unsafe list that provides a non-resolving view of the underlying data storage.
      protected java.util.ListIterator<E> basicListIterator()
      Returns a read-only list iterator that does not resolve objects.
      protected java.util.ListIterator<E> basicListIterator(int index)
      Returns a read-only list iterator advanced to the given index that does not resolve objects.
      void clear()
      Clears the list of all objects.
      java.lang.Object clone()
      Returns a shallow copy of this list.
      boolean contains(java.lang.Object object)
      Returns whether the list contains the object.
      protected java.lang.Object[] copy()
      Returns a copy of the existing data array.
      abstract java.lang.Object[] data()
      Returns direct unsafe access to the underlying data storage.
      E get(int index)
      Returns the object at the index.
      protected java.lang.Object[] grow(int size)
      Grows the capacity of the list to exactly the new size.
      int indexOf(java.lang.Object object)
      Returns the position of the first occurrence of the object in the list.
      boolean isEmpty()
      Returns whether the list has zero size.
      java.util.Iterator<E> iterator()
      Returns an iterator.
      int lastIndexOf(java.lang.Object object)
      Returns the position of the last occurrence of the object in the list.
      java.util.ListIterator<E> listIterator()
      Returns a list iterator.
      java.util.ListIterator<E> listIterator(int index)
      Returns a list iterator advanced to the given index.
      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.
      protected java.lang.Object[] newData(int capacity)
      Returns new allocated data storage.
      protected E primitiveGet(int index)
      Returns the object at the index without resolving it and without range checking the index.
      E remove(int index)
      Removes the object at the index from the list and returns it.
      boolean removeAll(java.util.Collection<?> collection)
      Removes each object of the collection from the list and returns whether any object was actually contained by the list.
      boolean retainAll(java.util.Collection<?> collection)
      Removes from the list each object not contained by the collection and returns whether any object was actually removed.
      void setData(java.lang.Object[] data)
      Updates directly and unsafely the underlying data storage.
      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.
      int size()
      Returns the number of objects in the list.
      java.lang.Object[] toArray()
      Returns an array containing all the objects in sequence.
      <T> T[] toArray(T[] array)
      Returns an array containing all the objects in sequence.
      • Methods inherited from class java.util.AbstractList

        removeRange, subList
      • Methods inherited from class java.util.AbstractCollection

        containsAll
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.List

        containsAll, subList
    • Constructor Detail

      • ArrayDelegatingEList

        public ArrayDelegatingEList()
        Creates an empty instance with no initial capacity. The data storage will be null.
      • ArrayDelegatingEList

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

        protected ArrayDelegatingEList(java.lang.Object[] data)
        Creates an initialized instance that directly uses the given arguments.
        Parameters:
        data - the underlying storage of the list.
    • Method Detail

      • newData

        protected java.lang.Object[] newData(int capacity)
        Returns new allocated data storage. Clients may override this to create typed storage. The cost of type checking via a typed array is negligible.
        Returns:
        new data storage.
      • assign

        protected E assign(java.lang.Object[] data,
               int index,
               E object)
        Assigns the object into the data storage at the given index and returns the object that's been stored. Clients can monitor access to the storage via this method.
        Parameters:
        index - the position of the new content.
        object - the new content.
        Returns:
        the object that's been stored.
      • size

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

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

        public boolean contains(java.lang.Object object)
        Returns whether the list contains the object. This implementation uses either equals or "==" depending on useEquals.
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.List<E>
        Overrides:
        contains in class java.util.AbstractCollection<E>
        Parameters:
        object - the object in question.
        Returns:
        whether the list contains the object.
        See Also:
        AbstractEList.useEquals()
      • indexOf

        public int indexOf(java.lang.Object object)
        Returns the position of the first occurrence of the object in the list. This implementation uses either equals or "==" depending on useEquals.
        Specified by:
        indexOf in interface java.util.List<E>
        Overrides:
        indexOf in class java.util.AbstractList<E>
        Parameters:
        object - the object in question.
        Returns:
        the position of the first occurrence of the object in the list.
      • lastIndexOf

        public int lastIndexOf(java.lang.Object object)
        Returns the position of the last occurrence of the object in the list. This implementation uses either equals or "==" depending on useEquals.
        Specified by:
        lastIndexOf in interface java.util.List<E>
        Overrides:
        lastIndexOf in class java.util.AbstractList<E>
        Parameters:
        object - the object in question.
        Returns:
        the position of the last occurrence of the object in the list.
      • toArray

        public java.lang.Object[] toArray()
        Returns an array containing all the objects in sequence. Clients may override newData to create typed storage in this case.
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.List<E>
        Overrides:
        toArray in class java.util.AbstractCollection<E>
        Returns:
        an array containing all the objects in sequence.
        See Also:
        newData(int)
      • toArray

        public <T> T[] toArray(T[] array)
        Returns an array containing all the objects in sequence.
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.List<E>
        Overrides:
        toArray in class java.util.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.
        See Also:
        newData(int)
      • data

        public abstract java.lang.Object[] data()
        Returns direct unsafe access to the underlying data storage. Clients may not modify this array's elements but may assume that the array remains valid even as the list is modified. The array's length is exactly the same as the list's size; null is used to represent the empty list.
        Returns:
        direct unsafe access to the underlying data storage.
      • setData

        public void setData(java.lang.Object[] data)
        Updates directly and unsafely the underlying data storage. Clients must be aware that this subverts all callbacks and hence possibly the integrity of the list. The list implementation itself calls this method whenever a modification of the list requires a new backing array.
        Parameters:
        data - the new underlying data storage.
      • 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 java.util.List<E>
        Specified by:
        get in class java.util.AbstractList<E>
        Parameters:
        index - the position in question.
        Returns:
        the object at the index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index isn't within the size range.
        See Also:
        AbstractEList.resolve(int, E), basicGet(int)
      • basicGet

        public 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:
        java.lang.IndexOutOfBoundsException - if the index isn't within the size range.
        See Also:
        AbstractEList.resolve(int, E), get(int)
      • 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 assign, 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:
        AbstractEList.set(int, E)
      • addAllUnique

        public boolean addAllUnique(java.util.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 assign, didAdd, and didChange.
        Specified by:
        addAllUnique in class AbstractEList<E>
        Parameters:
        collection - the collection of objects to be added.
        See Also:
        AbstractEList.addAll(Collection)
      • addAllUnique

        public boolean addAllUnique(int index,
                           java.util.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 assign, 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:
        AbstractEList.addAll(int, Collection)
      • addAllUnique

        public boolean addAllUnique(java.lang.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 assign, 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(Object[], int, int)
      • addAllUnique

        public boolean addAllUnique(int index,
                           java.lang.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 assign, 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:
        addAllUnique(Object[], int, int)
      • removeAll

        public boolean removeAll(java.util.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 java.util.Collection<E>
        Specified by:
        removeAll in interface java.util.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 java.util.List<E>
        Specified by:
        remove in class AbstractEList<E>
        Parameters:
        index - the position of the object to remove.
        Returns:
        the removed object.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index isn't within the size range.
      • retainAll

        public boolean retainAll(java.util.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 java.util.Collection<E>
        Specified by:
        retainAll in interface java.util.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. This implementation discards the data storage without modifying it and delegates to didClear and didChange.
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.List<E>
        Overrides:
        clear in class java.util.AbstractList<E>
      • 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 assign, 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:
        java.lang.IndexOutOfBoundsException - if either index isn't within the size range.
      • grow

        protected java.lang.Object[] grow(int size)
        Grows the capacity of the list to exactly the new size.
      • copy

        protected java.lang.Object[] copy()
        Returns a copy of the existing data array.
      • clone

        public java.lang.Object clone()
        Returns a shallow copy of this list.
        Overrides:
        clone in class java.lang.Object
        Returns:
        a shallow copy of this list.
      • listIterator

        public java.util.ListIterator<E> listIterator(int index)
        Returns a list iterator advanced to the given index. This implementation allocates a ArrayDelegatingEList.EListIterator.
        Specified by:
        listIterator in interface java.util.List<E>
        Overrides:
        listIterator in class AbstractEList<E>
        Parameters:
        index - the starting index.
        Returns:
        a list iterator advanced to the index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index isn't within the size range.
        See Also:
        ArrayDelegatingEList.EListIterator
      • basicListIterator

        protected java.util.ListIterator<E> basicListIterator(int index)
        Returns a read-only list iterator advanced to the given index that does not resolve objects. This implementation allocates a ArrayDelegatingEList.NonResolvingEListIterator.
        Overrides:
        basicListIterator in class AbstractEList<E>
        Parameters:
        index - the starting index.
        Returns:
        a read-only list iterator advanced to the index.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index isn't within the size range.
      • basicList

        protected java.util.List<E> basicList()
        Returns an unsafe list that provides a non-resolving view of the underlying data storage.
        Specified by:
        basicList in class AbstractEList<E>
        Returns:
        an unsafe list that provides a non-resolving view of the underlying data storage.