Package org.eclipse.emf.common.util
Class ArrayDelegatingEList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.eclipse.emf.common.util.AbstractEList<E>
org.eclipse.emf.common.util.ArrayDelegatingEList<E>
- All Implemented Interfaces:
Serializable,Cloneable,Iterable<E>,Collection<E>,List<E>,RandomAccess,SequencedCollection<E>,EList<E>
public abstract class ArrayDelegatingEList<E>
extends AbstractEList<E>
implements RandomAccess, Cloneable, Serializable
A highly extensible abstract list implementation
logically backed by an array that is never modified.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classAn extensible iterator implementation.protected classAn extensible list iterator implementation.protected classAn extended read-only iterator that does notresolveobjects.protected classAn extended read-only list iterator that does notresolveobjects.Nested classes/interfaces inherited from class org.eclipse.emf.common.util.AbstractEList
AbstractEList.BasicIndexOutOfBoundsException -
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
ConstructorsModifierConstructorDescriptionCreates an empty instance with no initial capacity.protectedArrayDelegatingEList(Object[] data) Creates an initialized instance that directly uses the given arguments.ArrayDelegatingEList(Collection<? extends E> collection) Creates an instance that is a copy of the collection. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddAllUnique(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.booleanaddAllUnique(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.booleanaddAllUnique(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.booleanaddAllUnique(Collection<? extends E> collection) Adds each object of the collection to the end of the list; it does no uniqueness checking.voidAdds the object at the given index in the list; it does no ranging checking or uniqueness checking.voidAdds the object at the end of the list; it does no uniqueness checking.protected EAssigns the object into the data storage at the given index and returns the object that's been stored.basicGet(int index) Returns the object at the index withoutresolvingit.Returns a read-only iterator that does notresolveobjects.Returns an unsafe list that provides anon-resolvingview of the underlying data storage.protected ListIterator<E> Returns a read-only list iterator that does notresolveobjects.protected ListIterator<E> basicListIterator(int index) Returns a read-only list iterator advanced to the given index that does notresolveobjects.voidclear()Clears the list of all objects.clone()Returns a shallow copy of this list.booleanReturns whether the list contains the object.protected Object[]copy()Returns a copy of the existing data array.abstract Object[]data()Returns direct unsafe access to the underlying data storage.get(int index) Returns the object at the index.protected Object[]grow(int size) Grows the capacity of the list to exactly the new size.intReturns the position of the first occurrence of the object in the list.booleanisEmpty()Returns whether the list has zero size.iterator()Returns an iterator.intlastIndexOf(Object object) Returns the position of the last occurrence of the object in the list.Returns a list iterator.listIterator(int index) Returns a list iterator advanced to the given index.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 Object[]newData(int capacity) Returns new allocated data storage.protected EprimitiveGet(int index) Returns the object at the index withoutresolvingit and without range checking the index.remove(int index) Removes the object at the index from the list and returns it.booleanremoveAll(Collection<?> collection) Removes each object of the collection from the list and returns whether any object was actually contained by the list.booleanretainAll(Collection<?> collection) Removes from the list each object not contained by the collection and returns whether any object was actually removed.voidUpdates directly and unsafely the underlying data storage.Sets the object at the index and returns the old object at the index; it does no ranging checking or uniqueness checking.final intsize()Returns the number of objects in the list.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 org.eclipse.emf.common.util.AbstractEList
add, add, addAll, addAll, canContainNull, didAdd, didChange, didClear, didMove, didRemove, didSet, equalObjects, equals, getDuplicates, getNonDuplicates, hashCode, isUnique, move, remove, resolve, set, toString, useEquals, validateMethods inherited from class java.util.AbstractList
removeRange, subListMethods inherited from class java.util.AbstractCollection
containsAllMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, containsAll, getFirst, getLast, removeFirst, removeLast, replaceAll, reversed, sort, spliterator, subList
-
Constructor Details
-
ArrayDelegatingEList
public ArrayDelegatingEList()Creates an empty instance with no initial capacity. The data storage will be null. -
ArrayDelegatingEList
Creates an instance that is a copy of the collection.- Parameters:
collection- the initial contents of the list.
-
ArrayDelegatingEList
Creates an initialized instance that directly uses the given arguments.- Parameters:
data- the underlying storage of the list.
-
-
Method Details
-
newData
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
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:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>- Returns:
- the number of objects in the list.
-
isEmpty
public boolean isEmpty()Returns whether the list has zero size.- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Overrides:
isEmptyin classAbstractCollection<E>- Returns:
- whether the list has zero size.
-
contains
Returns whether the list contains the object. This implementation uses eitherequalsor"=="depending onuseEquals.- Specified by:
containsin interfaceCollection<E>- Specified by:
containsin interfaceList<E>- Overrides:
containsin classAbstractCollection<E>- Parameters:
object- the object in question.- Returns:
- whether the list contains the object.
- See Also:
-
indexOf
Returns the position of the first occurrence of the object in the list. This implementation uses eitherequalsor"=="depending onuseEquals. -
lastIndexOf
Returns the position of the last occurrence of the object in the list. This implementation uses eitherequalsor"=="depending onuseEquals.- Specified by:
lastIndexOfin interfaceList<E>- Overrides:
lastIndexOfin classAbstractList<E>- Parameters:
object- the object in question.- Returns:
- the position of the last occurrence of the object in the list.
-
toArray
Returns an array containing all the objects in sequence. Clients may overridenewDatato create typed storage in this case.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<E>- Returns:
- an array containing all the objects in sequence.
- See Also:
-
toArray
public <T> T[] toArray(T[] array) Returns an array containing all the objects in sequence.- Specified by:
toArrayin interfaceCollection<E>- Specified by:
toArrayin interfaceList<E>- Overrides:
toArrayin classAbstractCollection<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:
-
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'ssize;nullis used to represent the empty list.- Returns:
- direct unsafe access to the underlying data storage.
-
setData
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
Returns the object at the index. This implementation delegates toresolveso that clients may transform the fetched object.- Specified by:
getin interfaceList<E>- Specified by:
getin classAbstractList<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:
-
basicGet
Returns the object at the index withoutresolvingit.- Overrides:
basicGetin classAbstractEList<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
Description copied from class:AbstractEListReturns the object at the index withoutresolvingit and without range checking the index.- Specified by:
primitiveGetin classAbstractEList<E>- Parameters:
index- the position in question.- Returns:
- the object at the index.
- See Also:
-
setUnique
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 toassign,didSet, anddidChange.- Specified by:
setUniquein classAbstractEList<E>- Parameters:
index- the position in question.object- the object to set.- Returns:
- the old object at the index.
- See Also:
-
addUnique
Adds the object at the end of the list; it does no uniqueness checking. This implementation delegates toassign,didAdd, anddidChange. after uniqueness checking.- Specified by:
addUniquein classAbstractEList<E>- Parameters:
object- the object to be added.- See Also:
-
addUnique
Adds the object at the given index in the list; it does no ranging checking or uniqueness checking. This implementation delegates toassign,didAdd, anddidChange.- Specified by:
addUniquein classAbstractEList<E>- Parameters:
object- the object to be added.- See Also:
-
addAllUnique
Adds each object of the collection to the end of the list; it does no uniqueness checking. This implementation delegates toassign,didAdd, anddidChange.- Specified by:
addAllUniquein classAbstractEList<E>- Parameters:
collection- the collection of objects to be added.- See Also:
-
addAllUnique
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 toassign,didAdd, anddidChange.- Specified by:
addAllUniquein classAbstractEList<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
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 toassign,didAdd, anddidChange.- Specified by:
addAllUniquein classAbstractEList<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
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 toassign,didAdd, anddidChange.- Specified by:
addAllUniquein classAbstractEList<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:
-
removeAll
Removes each object of the collection from the list and returns whether any object was actually contained by the list.- Specified by:
removeAllin interfaceCollection<E>- Specified by:
removeAllin interfaceList<E>- Overrides:
removeAllin classAbstractEList<E>- Parameters:
collection- the collection of objects to be removed.- Returns:
- whether any object was actually contained by the list.
-
remove
Removes the object at the index from the list and returns it. This implementation delegates todidRemoveanddidChange.- Specified by:
removein interfaceList<E>- Specified by:
removein classAbstractEList<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.
-
retainAll
Removes from the list each object not contained by the collection and returns whether any object was actually removed. This delegates toremove(int)in the case that it finds an object that isn't retained.- Specified by:
retainAllin interfaceCollection<E>- Specified by:
retainAllin interfaceList<E>- Overrides:
retainAllin classAbstractEList<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 todidClearanddidChange.- Specified by:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Overrides:
clearin classAbstractList<E>
-
move
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 toassign,didMove, anddidChange.- Specified by:
movein interfaceEList<E>- Specified by:
movein classAbstractEList<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.
-
grow
Grows the capacity of the list to exactly the new size. -
copy
Returns a copy of the existing data array. -
clone
Returns a shallow copy of this list. -
iterator
Returns an iterator. This implementation allocates aArrayDelegatingEList.EIterator. -
basicIterator
Returns a read-only iterator that does notresolveobjects. This implementation allocates aArrayDelegatingEList.NonResolvingEIterator.- Overrides:
basicIteratorin classAbstractEList<E>- Returns:
- a read-only iterator that does not resolve objects.
-
listIterator
Returns a list iterator. This implementation allocates aArrayDelegatingEList.EListIterator.- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractEList<E>- Returns:
- a list iterator.
- See Also:
-
listIterator
Returns a list iterator advanced to the given index. This implementation allocates aArrayDelegatingEList.EListIterator.- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractEList<E>- Parameters:
index- the starting index.- Returns:
- a list iterator advanced to the index.
- Throws:
IndexOutOfBoundsException- if the index isn't within the size range.- See Also:
-
basicListIterator
Returns a read-only list iterator that does notresolveobjects. This implementation allocates aArrayDelegatingEList.NonResolvingEListIterator.- Overrides:
basicListIteratorin classAbstractEList<E>- Returns:
- a read-only list iterator that does not resolve objects.
-
basicListIterator
Returns a read-only list iterator advanced to the given index that does notresolveobjects. This implementation allocates aArrayDelegatingEList.NonResolvingEListIterator.- Overrides:
basicListIteratorin classAbstractEList<E>- Parameters:
index- the starting index.- Returns:
- a read-only list iterator advanced to the index.
- Throws:
IndexOutOfBoundsException- if the index isn't within the size range.
-
basicList
Returns an unsafe list that provides anon-resolvingview of the underlying data storage.- Specified by:
basicListin classAbstractEList<E>- Returns:
- an unsafe list that provides a non-resolving view of the underlying data storage.
-