org.eclipse.emf.common.util
Class AbstractEList<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.eclipse.emf.common.util.AbstractEList<E>
All Implemented Interfaces:
java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, EList<E>
Direct Known Subclasses:
ArrayDelegatingEList, BasicEList, DelegatingEList

public abstract class AbstractEList<E>
extends java.util.AbstractList<E>
implements EList<E>

A highly extensible abstract list implementation.


Nested Class Summary
protected static class AbstractEList.BasicIndexOutOfBoundsException
          An IndexOutOfBoundsException that constructs a message from the argument data.
protected  class AbstractEList.EIterator<E1>
          An extensible iterator implementation.
protected  class AbstractEList.EListIterator<E1>
          An extensible list iterator implementation.
protected  class AbstractEList.NonResolvingEIterator<E1>
          An extended read-only iterator that does not resolve objects.
protected  class AbstractEList.NonResolvingEListIterator<E1>
          An extended read-only list iterator that does not resolve objects.
 
Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
AbstractEList()
          Creates an empty instance with no initial capacity.
 
Method Summary
 boolean add(E object)
          Adds the object at the end of the list and returns whether the object was added; if uniqueness is required, duplicates will be ignored and false will be returned.
 void add(int index, E object)
          Adds the object at the given index in the list.
 boolean addAll(java.util.Collection<? extends E> collection)
          Adds each object of the collection to the end of the list.
 boolean addAll(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.
abstract  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.
abstract  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.
abstract  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.
abstract  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.
abstract  void addUnique(E object)
          Adds the object at the end of the list; it does no uniqueness checking.
abstract  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 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 abstract  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.
protected  boolean canContainNull()
          Returns whether null is a valid object for the list.
protected  void didAdd(int index, E newObject)
          Called to indicate that an object has been added to the data storage.
protected  void didChange()
          Called to indicate that the data storage has been changed.
protected  void didClear(int size, java.lang.Object[] oldObjects)
          Called to indicate that the data storage has been cleared.
protected  void didMove(int index, E movedObject, int oldIndex)
          Called to indicate that an object has been moved in the data storage.
protected  void didRemove(int index, E oldObject)
          Called to indicate that an object has been removed from the data storage.
protected  void didSet(int index, E newObject, E oldObject)
          Called to indicate that the data storage has been set.
protected  boolean equalObjects(java.lang.Object firstObject, java.lang.Object secondObject)
          Returns whether two objects are equal using the appropriate comparison mechanism.
 boolean equals(java.lang.Object object)
          Returns whether the object is a list with corresponding equal objects.
protected  java.util.Collection<E> getDuplicates(java.util.Collection<?> collection)
          Returns the collection of objects in the given collection that are also contained by this list.
protected  java.util.Collection<E> getNonDuplicates(java.util.Collection<? extends E> collection)
          Returns the collection of objects in the given collection that are not also contained by this list.
 int hashCode()
          Returns a hash code computed from each object's hash code.
protected  boolean isUnique()
          Returns whether objects are constrained to appear at most once in the list.
 java.util.Iterator<E> iterator()
          Returns an iterator.
 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.
 void move(int index, E object)
          Moves the object to the index of the list.
abstract  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 abstract  E primitiveGet(int index)
          Returns the object at the index without resolving it and without range checking the index.
abstract  E remove(int index)
          Removes the object at the index from the list and returns it.
 boolean remove(java.lang.Object object)
          Removes the object from the list and returns whether the object was actually contained by the list.
 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.
protected  E resolve(int index, E object)
          Resolves the object at the index and returns the result.
 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.
 E set(int index, E object)
          Sets the object at the index and returns the old object at the index.
abstract  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.
 java.lang.String toString()
          Returns a string of the form "[object1, object2]".
protected  boolean useEquals()
          Returns whether equals rather than == should be used to compare members.
protected  E validate(int index, E object)
          Validates a new content object and returns the validated object.
 
Methods inherited from class java.util.AbstractList
clear, get, indexOf, lastIndexOf, removeRange, subList
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, size, toArray, toArray
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
clear, contains, containsAll, get, indexOf, isEmpty, lastIndexOf, size, subList, toArray, toArray
 

Constructor Detail

AbstractEList

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

Method Detail

useEquals

protected boolean useEquals()
Returns whether equals rather than == should be used to compare members. The default is to return true but clients can optimize performance by returning false. The performance difference is highly significant.

Returns:
whether equals rather than == should be used.

equalObjects

protected boolean equalObjects(java.lang.Object firstObject,
                               java.lang.Object secondObject)
Returns whether two objects are equal using the appropriate comparison mechanism.

Returns:
whether two objects are equal.

canContainNull

protected boolean canContainNull()
Returns whether null is a valid object for the list. The default is to return true, but clients can override this to exclude null.

Returns:
whether null is 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 return false, but clients can override this to ensure uniqueness of contents. The performance impact is significant: operations such as add are O(n) as a result requiring uniqueness.

Returns:
whether objects are constrained to appear at most once in the list.

validate

protected E validate(int index,
                     E object)
Validates a new content object and returns the validated object. This implementation checks for null, if necessary and 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:
java.lang.IllegalArgumentException - if a constraint prevents the object from being added.

resolve

protected E resolve(int index,
                    E object)
Resolves the object at the index and returns the result. This implementation simply returns the object; 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

protected void didSet(int index,
                      E newObject,
                      E oldObject)
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

protected void didAdd(int index,
                      E newObject)
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

protected void didRemove(int index,
                         E oldObject)
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

protected void didClear(int size,
                        java.lang.Object[] oldObjects)
Called to indicate that the data storage has been cleared. This implementation calls didRemove for 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:
didRemove(int, E)

didMove

protected void didMove(int index,
                       E movedObject,
                       int oldIndex)
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

protected E basicGet(int index)
Returns the object at the index without resolving it.

Parameters:
index - the position in question.
Returns:
the object at the index.
Throws:
AbstractEList.BasicIndexOutOfBoundsException - if the index isn't within the size range.
See Also:
resolve(int, E), AbstractList.get(int)

primitiveGet

protected abstract E primitiveGet(int index)
Returns the object at the index without resolving it and without range checking the index.

Parameters:
index - the position in question.
Returns:
the object at the index.
See Also:
resolve(int, E), AbstractList.get(int), basicGet(int)

set

public E set(int index,
             E object)
Sets the object at the index and returns the old object at the index. This implementation delegates to setUnique after range checking and after uniqueness checking.

Specified by:
set in interface java.util.List<E>
Overrides:
set in class java.util.AbstractList<E>
Parameters:
index - the position in question.
object - the object to set.
Returns:
the old object at the index.
Throws:
AbstractEList.BasicIndexOutOfBoundsException - if the index isn't within the size range.
java.lang.IllegalArgumentException - if there is a constraint violation, e.g., non-uniqueness.
See Also:
setUnique(int, E)

setUnique

public abstract 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.

Parameters:
index - the position in question.
object - the object to set.
Returns:
the old object at the index.
See Also:
set(int, E)

add

public boolean add(E object)
Adds the object at the end of the list and returns whether the object was added; if uniqueness is required, duplicates will be ignored and false will be returned. This implementation delegates to addUnique(E) after uniqueness checking.

Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.List<E>
Overrides:
add in class java.util.AbstractList<E>
Parameters:
object - the object to be added.
Returns:
whether the object was added.
See Also:
addUnique(Object)

addUnique

public abstract void addUnique(E object)
Adds the object at the end of the list; it does no uniqueness checking. This implementation delegates to assign, didAdd, and didChange. after uniqueness checking.

Parameters:
object - the object to be added.
See Also:
add(Object)

add

public void add(int index,
                E object)
Adds the object at the given index in the list. If uniqueness is required, duplicates will be ignored. This implementation delegates to addUnique(int, E) after uniqueness checking.

Specified by:
add in interface java.util.List<E>
Overrides:
add in class java.util.AbstractList<E>
Parameters:
object - the object to be added.
Throws:
java.lang.IllegalArgumentException - if uniqueness is required, and the object is a duplicate.
See Also:
addUnique(int, Object)

addUnique

public abstract 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 assign, didAdd, and didChange.

Parameters:
object - the object to be added.
See Also:
add(int, Object)

addAll

public boolean addAll(java.util.Collection<? extends E> collection)
Adds each object of the collection to the end of the list. If uniqueness is required, duplicates will be removed from the collection, which could even result in an empty collection. This implementation delegates to addAllUnique(Collection) after uniqueness checking.

Specified by:
addAll in interface java.util.Collection<E>
Specified by:
addAll in interface java.util.List<E>
Overrides:
addAll in class java.util.AbstractCollection<E>
Parameters:
collection - the collection of objects to be added.
See Also:
addAllUnique(Collection)

addAllUnique

public abstract 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.

Parameters:
collection - the collection of objects to be added.
See Also:
addAll(Collection)

addAll

public boolean addAll(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. If uniqueness is required, duplicates will be removed from the collection, which could even result in an empty collection. This implementation delegates to addAllUnique(int, Collection) after uniqueness checking.

Specified by:
addAll in interface java.util.List<E>
Overrides:
addAll in class java.util.AbstractList<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(int, Collection)

addAllUnique

public abstract 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.

Parameters:
index - the index at which to add.
collection - the collection of objects to be added.
Returns:
whether any objects were added.
See Also:
addAll(int, Collection)

addAllUnique

public abstract 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.

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 abstract 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.

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)

remove

public boolean remove(java.lang.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 java.util.Collection<E>
Specified by:
remove in interface java.util.List<E>
Overrides:
remove in class java.util.AbstractCollection<E>
Parameters:
object - the object to be removed.
Returns:
whether the object was actually contained by the list.

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 java.util.AbstractCollection<E>
Parameters:
collection - the collection of objects to be removed.
Returns:
whether any object was actually contained by the list.

remove

public abstract 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>
Overrides:
remove in class java.util.AbstractList<E>
Parameters:
index - the position of the object to remove.
Returns:
the removed object.
Throws:
AbstractEList.BasicIndexOutOfBoundsException - 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 java.util.AbstractCollection<E>
Parameters:
collection - the collection of objects to be retained.
Returns:
whether any object was actually removed.

move

public void move(int index,
                 E object)
Moves the object to the index of the list. This implementation uses AbstractList.indexOf(java.lang.Object) of find the object and delegates to move(int, int).

Specified by:
move in interface EList<E>
Parameters:
index - the new position for the object in the list.
object - the object to be moved.
Throws:
AbstractEList.BasicIndexOutOfBoundsException - if the index isn't within the size range or the object isn't contained by the list.

move

public abstract 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>
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:
AbstractEList.BasicIndexOutOfBoundsException - if either index isn't within the size range.

equals

public boolean equals(java.lang.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 java.util.Collection<E>
Specified by:
equals in interface java.util.List<E>
Overrides:
equals in class java.util.AbstractList<E>
Returns:
whether the object is a list with corresponding equal objects.
See Also:
useEquals()

hashCode

public int hashCode()
Returns a hash code computed from each object's hash code.

Specified by:
hashCode in interface java.util.Collection<E>
Specified by:
hashCode in interface java.util.List<E>
Overrides:
hashCode in class java.util.AbstractList<E>
Returns:
a hash code.

toString

public java.lang.String toString()
Returns a string of the form "[object1, object2]".

Overrides:
toString in class java.util.AbstractCollection<E>
Returns:
a string of the form "[object1, object2]".

iterator

public java.util.Iterator<E> iterator()
Returns an iterator. This implementation allocates a AbstractEList.EIterator.

Specified by:
iterator in interface java.lang.Iterable<E>
Specified by:
iterator in interface java.util.Collection<E>
Specified by:
iterator in interface java.util.List<E>
Overrides:
iterator in class java.util.AbstractList<E>
Returns:
an iterator.
See Also:
AbstractEList.EIterator

basicIterator

protected java.util.Iterator<E> basicIterator()
Returns a read-only iterator that does not resolve objects. This implementation allocates a AbstractEList.NonResolvingEIterator.

Returns:
a read-only iterator that does not resolve objects.

listIterator

public java.util.ListIterator<E> listIterator()
Returns a list iterator. This implementation allocates a AbstractEList.EListIterator.

Specified by:
listIterator in interface java.util.List<E>
Overrides:
listIterator in class java.util.AbstractList<E>
Returns:
a list iterator.
See Also:
AbstractEList.EListIterator

listIterator

public java.util.ListIterator<E> listIterator(int index)
Returns a list iterator advanced to the given index. This implementation allocates a AbstractEList.EListIterator.

Specified by:
listIterator in interface java.util.List<E>
Overrides:
listIterator in class java.util.AbstractList<E>
Parameters:
index - the starting index.
Returns:
a list iterator advanced to the index.
Throws:
AbstractEList.BasicIndexOutOfBoundsException - if the index isn't within the size range.
See Also:
AbstractEList.EListIterator

basicListIterator

protected java.util.ListIterator<E> basicListIterator()
Returns a read-only list iterator that does not resolve objects. This implementation allocates a AbstractEList.NonResolvingEListIterator.

Returns:
a read-only list iterator that does not resolve objects.

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 AbstractEList.NonResolvingEListIterator.

Parameters:
index - the starting index.
Returns:
a read-only list iterator advanced to the index.
Throws:
AbstractEList.BasicIndexOutOfBoundsException - if the index isn't within the size range.

basicList

protected abstract java.util.List<E> basicList()
Returns an unsafe list that provides a non-resolving view of the underlying data storage.

Returns:
an unsafe list that provides a non-resolving view of the underlying data storage.

getDuplicates

protected java.util.Collection<E> getDuplicates(java.util.Collection<?> collection)
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

protected java.util.Collection<E> getNonDuplicates(java.util.Collection<? extends E> collection)
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.

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.