Package org.eclipse.emf.common.util
Class AbstractEList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.eclipse.emf.common.util.AbstractEList<E>
- All Implemented Interfaces:
Iterable<E>,Collection<E>,List<E>,EList<E>
- Direct Known Subclasses:
ArrayDelegatingEList,BasicEList,DelegatingEList
A highly extensible abstract list implementation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classAn IndexOutOfBoundsException that constructs a message from the argument data.protected 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. -
Field Summary
Fields inherited from class java.util.AbstractList
modCount -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the object at the given index in the list.booleanAdds the object at the end of the list and returns whether the object was added; ifuniquenessis required, duplicates will be ignored andfalsewill be returned.booleanaddAll(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.booleanaddAll(Collection<? extends E> collection) Adds each object of the collection to the end of the list.abstract booleanaddAllUnique(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.abstract 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.abstract 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.abstract booleanaddAllUnique(Collection<? extends E> collection) Adds each object of the collection to the end of the list; it does no uniqueness checking.abstract voidAdds the object at the given index in the list; it does no ranging checking or uniqueness checking.abstract voidAdds the object at the end of the list; it does no uniqueness checking.protected EbasicGet(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.protected booleanReturns whethernullis a valid object for the list.protected voidCalled to indicate that an object has been added to the data storage.protected voidCalled to indicate that the data storage has been changed.protected voidCalled to indicate that the data storage has been cleared.protected voidCalled to indicate that an object has been moved in the data storage.protected voidCalled to indicate that an object has been removed from the data storage.protected voidCalled to indicate that the data storage has been set.protected booleanequalObjects(Object firstObject, Object secondObject) Returns whether two objects are equal using theappropriatecomparison mechanism.booleanReturns whether the object is a list with corresponding equal objects.protected Collection<E>getDuplicates(Collection<?> collection) Returns the collection of objects in the given collection that are also contained by this list.protected Collection<E>getNonDuplicates(Collection<? extends E> collection) Returns the collection of objects in the given collection that are not also contained by this list.inthashCode()Returns a hash code computed from each object's hash code.protected booleanisUnique()Returns whether objects are constrained to appear at most once in the list.iterator()Returns an iterator.Returns a list iterator.listIterator(int index) Returns a list iterator advanced to the given index.abstract Emove(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.voidMoves the object to the index of the list.protected abstract EprimitiveGet(int index) Returns the object at the index withoutresolvingit and without range checking the index.abstract Eremove(int index) Removes the object at the index from the list and returns it.booleanRemoves the object from the list and returns whether the object was actually contained by the list.booleanremoveAll(Collection<?> collection) Removes each object of the collection from the list and returns whether any object was actually contained by the list.protected EResolves the object at the index and returns the result.booleanretainAll(Collection<?> collection) Removes from the list each object not contained by the collection and returns whether any object was actually removed.Sets the object at the index and returns the old object at the index.abstract ESets the object at the index and returns the old object at the index; it does no ranging checking or uniqueness checking.toString()Returns a string of the form"[object1, object2]".protected booleanReturns whetherequalsrather than==should be used to compare members.protected EValidates a new content object and returns the validated object.Methods inherited from class java.util.AbstractList
clear, get, indexOf, lastIndexOf, removeRange, subListMethods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, size, toArray, toArrayMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
clear, contains, containsAll, get, indexOf, isEmpty, lastIndexOf, replaceAll, size, sort, spliterator, subList, toArray, toArray
-
Constructor Details
-
AbstractEList
public AbstractEList()Creates an empty instance with no initial capacity. The data storage will be null.
-
-
Method Details
-
useEquals
protected boolean useEquals()Returns whetherequalsrather than==should be used to compare members. The default is to returntruebut clients can optimize performance by returningfalse. The performance difference is highly significant.- Returns:
- whether
equalsrather than==should be used.
-
equalObjects
Returns whether two objects are equal using theappropriatecomparison mechanism.- Returns:
- whether two objects are equal.
-
canContainNull
protected boolean canContainNull()Returns whethernullis a valid object for the list. The default is to returntrue, but clients can override this to excludenull.- Returns:
- whether
nullis a valid object for the list.
-
isUnique
protected boolean isUnique()Returns whether objects are constrained to appear at most once in the list. The default is to returnfalse, but clients can override this to ensure uniqueness of contents. The performance impact is significant: operations such asaddare O(n) as a result requiring uniqueness.- Returns:
- whether objects are constrained to appear at most once in the list.
-
validate
Validates a new content object and returns the validated object. This implementation checks for null, ifnecessaryand returns the argument object. Clients may throw additional types of runtime exceptions in order to handle constraint violations.- Parameters:
index- the position of the new content.object- the new content.- Returns:
- the validated content.
- Throws:
IllegalArgumentException- if a constraint prevents the object from being added.
-
resolve
Resolves the object at the index and returns the result. This implementation simply returns theobject; clients can use this to transform objects as they are fetched.- Parameters:
index- the position of the content.object- the content.- Returns:
- the resolved object.
-
didSet
Called to indicate that the data storage has been set. This implementation does nothing; clients can use this to monitor settings to the data storage.- Parameters:
index- the position that was set.newObject- the new object at the position.oldObject- the old object at the position.
-
didAdd
Called to indicate that an object has been added to the data storage. This implementation does nothing; clients can use this to monitor additions to the data storage.- Parameters:
index- the position object the new object.newObject- the new object at the position.
-
didRemove
Called to indicate that an object has been removed from the data storage. This implementation does nothing; clients can use this to monitor removals from the data storage.- Parameters:
index- the position of the old object.oldObject- the old object at the position.
-
didClear
Called to indicate that the data storage has been cleared. This implementation callsdidRemovefor each object; clients can use this to monitor clearing of the data storage.- Parameters:
size- the original size of the list.oldObjects- the old data storage being discarded.- See Also:
-
didMove
Called to indicate that an object has been moved in the data storage. This implementation does nothing; clients can use this to monitor movement in the data storage.- Parameters:
index- the position of the moved object.movedObject- the moved object at the position.oldIndex- the position the object was at before the move.
-
didChange
protected void didChange()Called to indicate that the data storage has been changed. This implementation does nothing; clients can use this to monitor change in the data storage. -
basicGet
Returns the object at the index withoutresolvingit.- 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
Returns the object at the index withoutresolvingit and without range checking the index.- Parameters:
index- the position in question.- Returns:
- the object at the index.
- See Also:
-
set
Sets the object at the index and returns the old object at the index. This implementation delegates tosetUniqueafter range checking and afteruniquenesschecking.- Specified by:
setin interfaceList<E>- Overrides:
setin classAbstractList<E>- Parameters:
index- the position in question.object- the object to set.- Returns:
- the old object at the index.
- Throws:
IndexOutOfBoundsException- if the index isn't within the size range.IllegalArgumentException- if there is a constraint violation, e.g., non-uniqueness.- 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.- Parameters:
index- the position in question.object- the object to set.- Returns:
- the old object at the index.
- See Also:
-
add
Adds the object at the end of the list and returns whether the object was added; ifuniquenessis required, duplicates will be ignored andfalsewill be returned. This implementation delegates toaddUnique(E)after uniqueness checking.- Specified by:
addin interfaceCollection<E>- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>- Parameters:
object- the object to be added.- Returns:
- whether the object was added.
- See Also:
-
addUnique
Adds the object at the end of the list; it does no uniqueness checking.- Parameters:
object- the object to be added.- See Also:
-
add
Adds the object at the given index in the list. Ifuniquenessis required, duplicates will be ignored. This implementation delegates toaddUnique(int, E)after uniqueness checking.- Specified by:
addin interfaceList<E>- Overrides:
addin classAbstractList<E>- Parameters:
object- the object to be added.- Throws:
IllegalArgumentException- ifuniquenessis required, and the object is a duplicate.- See Also:
-
addUnique
Adds the object at the given index in the list; it does no ranging checking or uniqueness checking.- Parameters:
object- the object to be added.- See Also:
-
addAll
Adds each object of the collection to the end of the list. Ifuniquenessis required, duplicates will beremovedfrom the collection, which could even result in an empty collection. This implementation delegates toaddAllUnique(Collection)after uniqueness checking.- Specified by:
addAllin interfaceCollection<E>- Specified by:
addAllin interfaceList<E>- Overrides:
addAllin classAbstractCollection<E>- Parameters:
collection- the collection of objects to be added.- See Also:
-
addAllUnique
Adds each object of the collection to the end of the list; it does no uniqueness checking.- Parameters:
collection- the collection of objects to be added.- See Also:
-
addAll
Adds each object of the collection at each successive index in the list and returns whether any objects were added. Ifuniquenessis required, duplicates will beremovedfrom the collection, which could even result in an empty collection. This implementation delegates toaddAllUnique(int, Collection)after uniqueness checking. -
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.- 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.- 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.- 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
Removes the object from the list and returns whether the object was actually contained by the list. This implementation usesindexOfto find the object and delegates toremove(int)in the case that it finds the object.- Specified by:
removein interfaceCollection<E>- Specified by:
removein interfaceList<E>- Overrides:
removein classAbstractCollection<E>- Parameters:
object- the object to be removed.- Returns:
- whether the object was actually contained by the list.
-
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 classAbstractCollection<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>- Overrides:
removein classAbstractList<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 classAbstractCollection<E>- Parameters:
collection- the collection of objects to be retained.- Returns:
- whether any object was actually removed.
-
move
Moves the object to the index of the list. This implementation usesAbstractList.indexOf(java.lang.Object)of find the object and delegates tomove(int, int).- Specified by:
movein interfaceEList<E>- Parameters:
index- the new position for the object in the list.object- the object to be moved.- Throws:
IndexOutOfBoundsException- if the index isn't within the size range or the object isn't contained by the list.
-
move
Moves the object at the source index of the list to the target index of the list and returns the moved object.- Specified by:
movein interfaceEList<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.
-
equals
Returns whether the object is a list with corresponding equal objects. This implementation uses eitherequalsor"=="depending onuseEquals.- Specified by:
equalsin interfaceCollection<E>- Specified by:
equalsin interfaceList<E>- Overrides:
equalsin classAbstractList<E>- Returns:
- whether the object is a list with corresponding equal objects.
- See Also:
-
hashCode
public int hashCode()Returns a hash code computed from each object's hash code.- Specified by:
hashCodein interfaceCollection<E>- Specified by:
hashCodein interfaceList<E>- Overrides:
hashCodein classAbstractList<E>- Returns:
- a hash code.
-
toString
Returns a string of the form"[object1, object2]".- Overrides:
toStringin classAbstractCollection<E>- Returns:
- a string of the form
"[object1, object2]".
-
iterator
Returns an iterator. This implementation allocates aAbstractEList.EIterator. -
basicIterator
Returns a read-only iterator that does notresolveobjects. This implementation allocates aAbstractEList.NonResolvingEIterator.- Returns:
- a read-only iterator that does not resolve objects.
-
listIterator
Returns a list iterator. This implementation allocates aAbstractEList.EListIterator.- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<E>- Returns:
- a list iterator.
- See Also:
-
listIterator
Returns a list iterator advanced to the given index. This implementation allocates aAbstractEList.EListIterator.- Specified by:
listIteratorin interfaceList<E>- Overrides:
listIteratorin classAbstractList<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 aAbstractEList.NonResolvingEListIterator.- 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 aAbstractEList.NonResolvingEListIterator.- 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.- Returns:
- an unsafe list that provides a non-resolving view of the underlying data storage.
-
getDuplicates
Returns the collection of objects in the given collection that are also contained by this list.- Parameters:
collection- the other collection.- Returns:
- the collection of objects in the given collection that are also contained by this list.
-
getNonDuplicates
Returns the collection of objects in the given collection that are not also contained by this list.- Parameters:
collection- the other collection.- Returns:
- the collection of objects in the given collection that are not also contained by this list.
-