org.eclipse.emf.common.notify.impl
Class NotifyingListImpl<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by org.eclipse.emf.common.util.BasicEList<E>
              extended by org.eclipse.emf.common.notify.impl.NotifyingListImpl<E>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess, NotifyingList<E>, EList<E>
Direct Known Subclasses:
ItemProvider.ItemProviderNotifyingArrayList, NotifyingInternalEListImpl

public class NotifyingListImpl<E>
extends BasicEList<E>
implements NotifyingList<E>

An extensible implementation of a notifying list.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class org.eclipse.emf.common.util.BasicEList
BasicEList.BasicIndexOutOfBoundsException, BasicEList.EIterator<E1>, BasicEList.EListIterator<E1>, BasicEList.FastCompare<E>, BasicEList.NonResolvingEIterator<E1>, BasicEList.NonResolvingEListIterator<E1>, BasicEList.UnmodifiableEList<E>
 
Field Summary
 
Fields inherited from class org.eclipse.emf.common.util.BasicEList
data, size
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
NotifyingListImpl()
          Creates an empty instance.
NotifyingListImpl(java.util.Collection<? extends E> collection)
          Creates an instance that is a copy of the collection.
NotifyingListImpl(int initialCapacity)
          Creates an empty instance with the given capacity.
 
Method Summary
 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 to the end of the list and returns whether any objects were added; it does no 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.
 NotificationChain basicAdd(E object, NotificationChain notifications)
          Adds the object at the end of the list and returns the potentially updated notification chain; it does no inverse updating.
 NotificationChain basicRemove(java.lang.Object object, NotificationChain notifications)
          Removes the object from the list and returns the potentially updated notification chain; it does no inverse updating.
 NotificationChain basicSet(int index, E object, NotificationChain notifications)
          Sets the object at the index and returns the potentially updated notification chain; it does no inverse updating.
protected  boolean canContainNull()
          Returns !
 void clear()
          Clears the list of all objects.
protected  NotificationImpl createNotification(int eventType, java.lang.Object oldObject, java.lang.Object newObject, int index)
           
protected  NotificationImpl createNotification(int eventType, java.lang.Object oldObject, java.lang.Object newObject, int index, boolean wasSet)
          Creates a notification.
protected  NotificationChain createNotificationChain(int capacity)
          Creates a notification chain, if the expected capacity exceeds the threshold at which a list is better than chaining individual notification instances.
protected  void dispatchNotification(Notification notification)
          Dispatches a notification to the notifier of the list.
protected  boolean doAddAllUnique(java.util.Collection<? extends E> collection)
          Adds each object of the collection to the end of the list; it does no uniqueness checking, inverse updating, or notification.
protected  boolean doAddAllUnique(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 range checking, uniqueness checking, inverse updating, or notification.
protected  boolean doAddAllUnique(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, uniqueness checking, inverse updating, or notification.
protected  boolean doAddAllUnique(java.lang.Object[] objects, int start, int end)
          Adds each object from start to end of the array to the end of the list and returns whether any objects were added; it does no ranging checking, uniqueness checking, inverse updating, or notification.
protected  void doAddUnique(E object)
          Adds the object at the end of the list; it does no uniqueness checking, inverse updating, or notification.
protected  void doAddUnique(int index, E object)
          Adds the object at the given index in the list; it does no range checking, uniqueness checking, inverse updating, or notification.
protected  void doClear()
          Clears the list of all objects; it does no inverse updating.
protected  E doMove(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; it does no notification.
protected  E doRemove(int index)
          Removes the object at the index from the list and returns it; it does no inverse updating, or notification.
protected  boolean doRemoveAll(java.util.Collection<?> collection)
          Removes each object of the collection from the list and returns whether any object was actually contained by the list; it does no inverse updating, or notification.
protected  E doSetUnique(int index, E object)
          Sets the object at the index and returns the old object at the index; it does no ranging checking, uniqueness checking, inverse updating or notification.
 java.lang.Object getFeature()
          Returns null.
 int getFeatureID()
          Returns Notification.NO_FEATURE_ID.
protected  int getFeatureID(java.lang.Class<?> expectedClass)
          Returns the result of calling getFeatureID().
 java.lang.Object getNotifier()
          Returns null.
protected  boolean hasInverse()
          Returns false.
protected  boolean hasShadow()
          Returns false.
protected  NotificationChain inverseAdd(E object, NotificationChain notifications)
          Does nothing and returns the notifications.
protected  NotificationChain inverseRemove(E object, NotificationChain notifications)
          Does nothing and returns the notifications.
protected  boolean isNotificationRequired()
          Returns false.
protected  boolean isSet()
          Returns whether the list is considered set, i.e., whether it's not empty.
 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.
 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.
protected  E resolve(E object)
          Returns the resolved object from this list for the purpose of testing whether removeAll(Collection) applies to it.
 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.
protected  NotificationChain shadowAdd(E object, NotificationChain notifications)
          Does nothing and returns the notifications.
protected  NotificationChain shadowRemove(E object, NotificationChain notifications)
          Does nothing and returns the notifications.
protected  NotificationChain shadowSet(E oldObject, E newObject, NotificationChain notifications)
          Does nothing and returns the notifications.
 
Methods inherited from class org.eclipse.emf.common.util.BasicEList
add, add, addAll, addAll, assign, basicGet, basicIterator, basicList, basicListIterator, basicListIterator, clone, contains, containsAll, data, didAdd, didChange, didClear, didMove, didRemove, didSet, equalObjects, equals, get, getDuplicates, getNonDuplicates, grow, hashCode, indexOf, isEmpty, isUnique, iterator, lastIndexOf, listIterator, listIterator, move, newData, remove, resolve, retainAll, set, setData, shrink, size, toArray, toArray, toString, useEquals, validate
 
Methods inherited from class java.util.AbstractList
removeRange, subList
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.eclipse.emf.common.util.EList
move
 
Methods inherited from interface java.util.List
add, add, addAll, addAll, contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, retainAll, set, size, subList, toArray, toArray
 

Constructor Detail

NotifyingListImpl

public NotifyingListImpl()
Creates an empty instance.


NotifyingListImpl

public NotifyingListImpl(int initialCapacity)
Creates an empty instance with the given capacity.

Parameters:
initialCapacity - the initial capacity of the list before it must grow.

NotifyingListImpl

public NotifyingListImpl(java.util.Collection<? extends E> collection)
Creates an instance that is a copy of the collection.

Parameters:
collection - the initial contents of the list.
Method Detail

getNotifier

public java.lang.Object getNotifier()
Returns null.

Specified by:
getNotifier in interface NotifyingList<E>
Returns:
null.

getFeature

public java.lang.Object getFeature()
Returns null.

Specified by:
getFeature in interface NotifyingList<E>
Returns:
null.
See Also:
Notification.getFeature()

getFeatureID

public int getFeatureID()
Returns Notification.NO_FEATURE_ID.

Specified by:
getFeatureID in interface NotifyingList<E>
Returns:
Notification.NO_FEATURE_ID.
See Also:
Notification.getFeatureID(java.lang.Class)

getFeatureID

protected int getFeatureID(java.lang.Class<?> expectedClass)
Returns the result of calling getFeatureID().

Parameters:
expectedClass - the class to which the ID is relative.
Returns:
getFeatureID().

isSet

protected boolean isSet()
Returns whether the list is considered set, i.e., whether it's not empty. A derived implementation may model this state directly.

Returns:
whether the list is considered set.

hasInverse

protected boolean hasInverse()
Returns false.

Returns:
false.

canContainNull

protected boolean canContainNull()
Returns !hasInverse().

Overrides:
canContainNull in class BasicEList<E>
Returns:
!hasInverse.

isNotificationRequired

protected boolean isNotificationRequired()
Returns false.

Returns:
false.

hasShadow

protected boolean hasShadow()
Returns false.

Returns:
false.

shadowAdd

protected NotificationChain shadowAdd(E object,
                                      NotificationChain notifications)
Does nothing and returns the notifications. Clients can override this to update the inverse of a bidirectional relation.

Parameters:
object - the object that's been added to the list.
notifications - the chain of accumulating notifications.
Returns:
the notifications.

shadowRemove

protected NotificationChain shadowRemove(E object,
                                         NotificationChain notifications)
Does nothing and returns the notifications. Clients can override this to update the inverse of a bidirectional relation.

Parameters:
object - the object that's been remove from the list.
notifications - the chain of accumulating notifications.
Returns:
the notifications.

shadowSet

protected NotificationChain shadowSet(E oldObject,
                                      E newObject,
                                      NotificationChain notifications)
Does nothing and returns the notifications. Clients can override this to update the inverse of a bidirectional relation.

Parameters:
oldObject - the object that's been removed from the list.
newObject - the object that's been added to the list.
notifications - the chain of accumulating notifications.
Returns:
the notifications.

inverseAdd

protected NotificationChain inverseAdd(E object,
                                       NotificationChain notifications)
Does nothing and returns the notifications. Clients can override this to update the inverse of a bidirectional relation.

Parameters:
object - the object that's been added to the list.
notifications - the chain of accumulating notifications.
Returns:
the notifications.

inverseRemove

protected NotificationChain inverseRemove(E object,
                                          NotificationChain notifications)
Does nothing and returns the notifications. Clients can override this to update the inverse of a bidirectional relation.

Parameters:
object - the object that's been remove from the list.
notifications - the chain of accumulating notifications.
Returns:
the notifications.

createNotification

protected NotificationImpl createNotification(int eventType,
                                              java.lang.Object oldObject,
                                              java.lang.Object newObject,
                                              int index)

createNotification

protected NotificationImpl createNotification(int eventType,
                                              java.lang.Object oldObject,
                                              java.lang.Object newObject,
                                              int index,
                                              boolean wasSet)
Creates a notification.

Parameters:
eventType - the type of change that has occurred.
oldObject - the value of the notifier's feature before the change occurred.
newObject - the value of the notifier's feature after the change occurred.
index - the position at which the change occurred.
Returns:
a new notification.

createNotificationChain

protected NotificationChain createNotificationChain(int capacity)
Creates a notification chain, if the expected capacity exceeds the threshold at which a list is better than chaining individual notification instances.


dispatchNotification

protected void dispatchNotification(Notification notification)
Dispatches a notification to the notifier of the list.

Parameters:
notification - the notification to dispatch.

addUnique

public void addUnique(E object)
Adds the object at the end of the list; it does no uniqueness checking. In addition to the normal effects, this override implementation generates notifications as required and delegates to inverseAdd as required.

Overrides:
addUnique in class BasicEList<E>
Parameters:
object - the object to be added.
See Also:
isNotificationRequired(), hasInverse(), inverseAdd(E, org.eclipse.emf.common.notify.NotificationChain)

doAddUnique

protected void doAddUnique(E object)
Adds the object at the end of the list; it does no uniqueness checking, inverse updating, or notification.

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. In addition to the normal effects, this override implementation generates notifications as required and delegates to inverseAdd as required.

Overrides:
addUnique in class BasicEList<E>
Parameters:
object - the object to be added.
See Also:
isNotificationRequired(), hasInverse(), inverseAdd(E, org.eclipse.emf.common.notify.NotificationChain)

doAddUnique

protected void doAddUnique(int index,
                           E object)
Adds the object at the given index in the list; it does no range checking, uniqueness checking, inverse updating, or notification.

Parameters:
object - the object to be added.

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 addAllUnique(int, Collection).

Overrides:
addAllUnique in class BasicEList<E>
Parameters:
collection - the collection of objects to be added.
See Also:
inverseAdd(E, org.eclipse.emf.common.notify.NotificationChain)

doAddAllUnique

protected boolean doAddAllUnique(java.util.Collection<? extends E> collection)
Adds each object of the collection to the end of the list; it does no uniqueness checking, inverse updating, or notification.

Parameters:
collection - the collection of objects to be added.

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. In addition to the normal effects, this override implementation generates notifications as required and delegates to inverseAdd as required.

Overrides:
addAllUnique in class BasicEList<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:
isNotificationRequired(), hasInverse(), inverseAdd(E, org.eclipse.emf.common.notify.NotificationChain)

doAddAllUnique

protected boolean doAddAllUnique(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 range checking, uniqueness checking, inverse updating, or notification.

Parameters:
index - the index at which to add.
collection - the collection of objects to be added.
Returns:
whether any objects were added.

addAllUnique

public boolean addAllUnique(java.lang.Object[] objects,
                            int start,
                            int end)
Adds each object from start to end of the array to the end of the list and returns whether any objects were added; it does no uniqueness checking. This implementation delegates to addAllUnique(int, Object[], int, int).

Overrides:
addAllUnique in class BasicEList<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:
inverseAdd(E, org.eclipse.emf.common.notify.NotificationChain)

doAddAllUnique

protected boolean doAddAllUnique(java.lang.Object[] objects,
                                 int start,
                                 int end)
Adds each object from start to end of the array to the end of the list and returns whether any objects were added; it does no ranging checking, uniqueness checking, inverse updating, or notification.

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.

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. In addition to the normal effects, this override implementation generates notifications as required and delegates to inverseAdd as required.

Overrides:
addAllUnique in class BasicEList<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(int, Collection), isNotificationRequired(), hasInverse(), inverseAdd(E, org.eclipse.emf.common.notify.NotificationChain), BasicEList.assign(int, Object)

doAddAllUnique

protected boolean doAddAllUnique(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, uniqueness checking, inverse updating, or notification.

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.

basicAdd

public NotificationChain basicAdd(E object,
                                  NotificationChain notifications)
Adds the object at the end of the list and returns the potentially updated notification chain; it does no inverse updating. This implementation generates notifications as required.

Parameters:
object - the object to be added.
Returns:
the notification chain.
See Also:
isNotificationRequired(), hasInverse(), inverseAdd(E, org.eclipse.emf.common.notify.NotificationChain)

remove

public E remove(int index)
Removes the object at the index from the list and returns it. In addition to the normal effects, this override implementation generates notifications as required and delegates to inverseRemove as required.

Specified by:
remove in interface java.util.List<E>
Overrides:
remove in class BasicEList<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.
See Also:
isNotificationRequired(), hasInverse(), inverseRemove(E, org.eclipse.emf.common.notify.NotificationChain)

doRemove

protected E doRemove(int index)
Removes the object at the index from the list and returns it; it does no inverse updating, or notification.

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.

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. In addition to the normal effects, this override implementation generates notifications as required and delegates to inverseRemove as required.

Specified by:
removeAll in interface java.util.Collection<E>
Specified by:
removeAll in interface java.util.List<E>
Overrides:
removeAll in class BasicEList<E>
Parameters:
collection - the collection of objects to be removed.
Returns:
whether any object was actually contained by the list.
See Also:
isNotificationRequired(), hasInverse(), inverseRemove(E, org.eclipse.emf.common.notify.NotificationChain)

resolve

protected E resolve(E object)
Returns the resolved object from this list for the purpose of testing whether removeAll(Collection) applies to it.

Parameters:
object - the object to be resolved.
Returns:
the resolved object from this list for the purpose of testing whether removeAll applies to it.

doRemoveAll

protected boolean doRemoveAll(java.util.Collection<?> collection)
Removes each object of the collection from the list and returns whether any object was actually contained by the list; it does no inverse updating, or notification.

Parameters:
collection - the collection of objects to be removed.
Returns:
whether any object was actually contained by the list.

basicRemove

public NotificationChain basicRemove(java.lang.Object object,
                                     NotificationChain notifications)
Removes the object from the list and returns the potentially updated notification chain; it does no inverse updating. This implementation generates notifications as required.

Parameters:
object - the object to be removed.
Returns:
the notification chain.
See Also:
isNotificationRequired(), hasInverse(), inverseRemove(E, org.eclipse.emf.common.notify.NotificationChain)

clear

public void clear()
Clears the list of all objects. In addition to the normal effects, this override implementation generates notifications as required and delegates to inverseRemove as required.

Specified by:
clear in interface java.util.Collection<E>
Specified by:
clear in interface java.util.List<E>
Overrides:
clear in class BasicEList<E>
See Also:
isNotificationRequired(), hasInverse(), inverseRemove(E, org.eclipse.emf.common.notify.NotificationChain)

doClear

protected void doClear()
Clears the list of all objects; it does no inverse updating.


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. In addition to the normal effects, this override implementation generates notifications as required and delegates to inverseAdd and inverseRemove as required.

Overrides:
setUnique in class BasicEList<E>
Parameters:
index - the position in question.
object - the object to set.
Returns:
the old object at the index.
See Also:
isNotificationRequired(), hasInverse(), inverseAdd(E, org.eclipse.emf.common.notify.NotificationChain), inverseRemove(E, org.eclipse.emf.common.notify.NotificationChain)

doSetUnique

protected E doSetUnique(int index,
                        E object)
Sets the object at the index and returns the old object at the index; it does no ranging checking, uniqueness checking, inverse updating or notification.

Parameters:
index - the position in question.
object - the object to set.
Returns:
the old object at the index.

basicSet

public NotificationChain basicSet(int index,
                                  E object,
                                  NotificationChain notifications)
Sets the object at the index and returns the potentially updated notification chain; it does no inverse updating. This implementation generates notifications as required.

Parameters:
index - the position in question.
object - the object to set.
Returns:
the notification chain.
See Also:
isNotificationRequired(), hasInverse(), inverseAdd(E, org.eclipse.emf.common.notify.NotificationChain), inverseRemove(E, org.eclipse.emf.common.notify.NotificationChain)

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. In addition to the normal effects, this override implementation generates notifications as required.

Specified by:
move in interface EList<E>
Overrides:
move in class BasicEList<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.
See Also:
isNotificationRequired()

doMove

protected E doMove(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; it does no notification.

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.

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