Class AbstractObservableList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.eclipse.core.databinding.observable.list.AbstractObservableList<E>
- Type Parameters:
E
- the list element type
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,List<E>
,IObservable
,IObservableCollection<E>
,IObservableList<E>
- Direct Known Subclasses:
ComputedList
,MultiList
public abstract class AbstractObservableList<E>
extends AbstractList<E>
implements IObservableList<E>
Subclasses should override at least get(int index) and size().
This class is thread safe. All state accessing methods must be invoked from
the current realm
. Methods for adding and removing
listeners may be invoked from any thread.
- Since:
- 1.0
- Implementation Note:
- If methods are added to the interface which this class implements then implementations of those methods must be added to this class.
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(int index, Collection<? extends E> c) boolean
addAll
(Collection<? extends E> c) void
addChangeListener
(IChangeListener listener) Adds the given change listener to the list of change listeners.void
addDisposeListener
(IDisposeListener listener) Adds the given dispose listener to the list of dispose listeners.void
addListChangeListener
(IListChangeListener<? super E> listener) Adds the given list change listener to the list of list change listeners.void
addStaleListener
(IStaleListener listener) Adds the given stale listener to the list of stale listeners.protected void
Asserts that the realm is the current realm.boolean
boolean
containsAll
(Collection<?> c) void
dispose()
Disposes of this observable object, removing all listeners registered with this object, and all listeners this object might have registered on other objects.protected abstract int
boolean
protected void
Fires change event.protected void
fireListChange
(ListDiff<E> diff) protected void
Fires stale event.protected void
getRealm()
Returns the realm for this observable.int
hashCode()
protected boolean
Returns whether this observable list has any registered listeners.int
boolean
Returns whether the observable has been disposedboolean
isEmpty()
boolean
isStale()
Returns whether the state of this observable is stale and is expected to change soon.iterator()
int
protected void
move
(int oldIndex, int newIndex) Moves the element located atoldIndex
tonewIndex
.boolean
boolean
removeAll
(Collection<?> c) void
removeChangeListener
(IChangeListener listener) Removes the given change listener from the list of change listeners.void
removeDisposeListener
(IDisposeListener listener) Removes the given dispose listener from the list of dispose listeners.void
removeListChangeListener
(IListChangeListener<? super E> listener) Removes the given list change listener from the list of list change listeners.void
removeStaleListener
(IStaleListener listener) Removes the given stale listener from the list of stale listeners.boolean
retainAll
(Collection<?> c) final int
size()
Object[]
toArray()
<T> T[]
toArray
(T[] a) Methods inherited from class java.util.AbstractList
add, clear, get, listIterator, listIterator, remove, removeRange, set, subList
Methods inherited from class java.util.AbstractCollection
toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface org.eclipse.core.databinding.observable.list.IObservableList
get, getElementType, listIterator, listIterator, remove, set, subList
Methods inherited from interface java.util.List
add, clear, replaceAll, sort, spliterator
-
Constructor Details
-
AbstractObservableList
- Parameters:
realm
- the realm; notnull
-
AbstractObservableList
public AbstractObservableList()
-
-
Method Details
-
hasListeners
protected boolean hasListeners()Returns whether this observable list has any registered listeners.- Returns:
- whether this observable list has any registered listeners.
- Since:
- 1.2
-
isStale
public boolean isStale()Description copied from interface:IObservable
Returns whether the state of this observable is stale and is expected to change soon. A non-stale observable that becomes stale will notify its stale listeners. A stale object that becomes non-stale does so by changing its state and notifying its change listeners, it does not notify its stale listeners about becoming non-stale. Clients that do not expect asynchronous changes may ignore staleness of observable objects.- Specified by:
isStale
in interfaceIObservable
- Returns:
- true if this observable's state is stale and will change soon.
-
addListChangeListener
Description copied from interface:IObservableList
Adds the given list change listener to the list of list change listeners.- Specified by:
addListChangeListener
in interfaceIObservableList<E>
- Parameters:
listener
- the change listener to add; notnull
-
removeListChangeListener
Description copied from interface:IObservableList
Removes the given list change listener from the list of list change listeners. Has no effect if the given listener is not registered as a list change listener.- Specified by:
removeListChangeListener
in interfaceIObservableList<E>
- Parameters:
listener
- the change listener to remove; notnull
-
fireListChange
-
addChangeListener
Description copied from interface:IObservable
Adds the given change listener to the list of change listeners. Change listeners are notified about changes of the state of this observable in a generic way, without specifying the change that happened. To get the changed state, a change listener needs to query for the current state of this observable.- Specified by:
addChangeListener
in interfaceIObservable
- Parameters:
listener
- the listener to add; notnull
-
removeChangeListener
Description copied from interface:IObservable
Removes the given change listener from the list of change listeners. Has no effect if the given listener is not registered as a change listener.- Specified by:
removeChangeListener
in interfaceIObservable
- Parameters:
listener
- the listener to remove; notnull
-
addStaleListener
Description copied from interface:IObservable
Adds the given stale listener to the list of stale listeners. Stale listeners are notified when an observable object becomes stale, not when is becomes non-stale.- Specified by:
addStaleListener
in interfaceIObservable
- Parameters:
listener
- the listener to add; notnull
- See Also:
-
removeStaleListener
Description copied from interface:IObservable
Removes the given stale listener from the list of stale listeners. Has no effect if the given listener is not registered as a stale listener.- Specified by:
removeStaleListener
in interfaceIObservable
- Parameters:
listener
- the listener to remove; notnull
-
addDisposeListener
Description copied from interface:IObservable
Adds the given dispose listener to the list of dispose listeners. Dispose listeners are notified when an observable has been disposed.- Specified by:
addDisposeListener
in interfaceIObservable
- Parameters:
listener
- the listener to add- Since:
- 1.2
-
removeDisposeListener
Description copied from interface:IObservable
Removes the given dispose listener from the list of dispose listeners. Has no effect if the given listener is not registered as a dispose listener.- Specified by:
removeDisposeListener
in interfaceIObservable
- Parameters:
listener
- the listener to remove- Since:
- 1.2
-
fireChange
protected void fireChange()Fires change event. Must be invoked from the current realm. -
fireStale
protected void fireStale()Fires stale event. Must be invoked from the current realm. -
firstListenerAdded
protected void firstListenerAdded() -
lastListenerRemoved
protected void lastListenerRemoved() -
isDisposed
public boolean isDisposed()Description copied from interface:IObservable
Returns whether the observable has been disposed- Specified by:
isDisposed
in interfaceIObservable
- Returns:
- whether the observable has been disposed
- Since:
- 1.2
-
dispose
public void dispose()Description copied from interface:IObservable
Disposes of this observable object, removing all listeners registered with this object, and all listeners this object might have registered on other objects.- Specified by:
dispose
in interfaceIObservable
-
size
public final int size()- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceIObservableList<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
-
doGetSize
protected abstract int doGetSize()- Returns:
- the size
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceIObservableList<E>
- Specified by:
isEmpty
in interfaceList<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
contains
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceIObservableList<E>
- Specified by:
contains
in interfaceList<E>
- Overrides:
contains
in classAbstractCollection<E>
-
iterator
- Specified by:
iterator
in interfaceCollection<E>
- Specified by:
iterator
in interfaceIObservableList<E>
- Specified by:
iterator
in interfaceIterable<E>
- Specified by:
iterator
in interfaceList<E>
- Overrides:
iterator
in classAbstractList<E>
-
toArray
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceIObservableList<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a) - Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceIObservableList<E>
- Specified by:
toArray
in interfaceList<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
add
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceIObservableList<E>
- Specified by:
add
in interfaceList<E>
- Overrides:
add
in classAbstractList<E>
-
move
Moves the element located atoldIndex
tonewIndex
. This method is equivalent to callingadd(newIndex, remove(oldIndex))
.Subclasses should override this method to deliver list change notification for the remove and add operations in the same ListChangeEvent, as this allows
ListDiff.accept(ListDiffVisitor)
to recognize the operation as a move.- Specified by:
move
in interfaceIObservableList<E>
- Parameters:
oldIndex
- the element's position before the move. Must be within the range0 <= oldIndex < size()
.newIndex
- the element's position after the move. Must be within the range0 <= newIndex < size()
.- Returns:
- the element that was moved.
- Throws:
IndexOutOfBoundsException
- if either argument is out of range (0 <= index < size()
).- Since:
- 1.1
- See Also:
-
remove
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceIObservableList<E>
- Specified by:
remove
in interfaceList<E>
- Overrides:
remove
in classAbstractCollection<E>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<E>
- Specified by:
containsAll
in interfaceIObservableList<E>
- Specified by:
containsAll
in interfaceList<E>
- Overrides:
containsAll
in classAbstractCollection<E>
-
addAll
- Specified by:
addAll
in interfaceCollection<E>
- Specified by:
addAll
in interfaceIObservableList<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classAbstractCollection<E>
-
addAll
- Specified by:
addAll
in interfaceIObservableList<E>
- Specified by:
addAll
in interfaceList<E>
- Overrides:
addAll
in classAbstractList<E>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<E>
- Specified by:
removeAll
in interfaceIObservableList<E>
- Specified by:
removeAll
in interfaceList<E>
- Overrides:
removeAll
in classAbstractCollection<E>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<E>
- Specified by:
retainAll
in interfaceIObservableList<E>
- Specified by:
retainAll
in interfaceList<E>
- Overrides:
retainAll
in classAbstractCollection<E>
-
equals
- Specified by:
equals
in interfaceCollection<E>
- Specified by:
equals
in interfaceIObservableList<E>
- Specified by:
equals
in interfaceList<E>
- Overrides:
equals
in classAbstractList<E>
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<E>
- Specified by:
hashCode
in interfaceIObservableList<E>
- Specified by:
hashCode
in interfaceList<E>
- Overrides:
hashCode
in classAbstractList<E>
-
indexOf
- Specified by:
indexOf
in interfaceIObservableList<E>
- Specified by:
indexOf
in interfaceList<E>
- Overrides:
indexOf
in classAbstractList<E>
-
lastIndexOf
- Specified by:
lastIndexOf
in interfaceIObservableList<E>
- Specified by:
lastIndexOf
in interfaceList<E>
- Overrides:
lastIndexOf
in classAbstractList<E>
-
getRealm
Description copied from interface:IObservable
Returns the realm for this observable. Unless otherwise specified, getters and setters must be accessed from within this realm. Listeners will be within this realm when they receive events from this observable.Because observables can only be accessed from within one realm, and they always fire events on that realm, their state can be observed in an incremental way. It is always safe to call getters of an observable from within a change listener attached to that observable.
- Specified by:
getRealm
in interfaceIObservable
- Returns:
- the realm
-
checkRealm
protected void checkRealm()Asserts that the realm is the current realm.- Throws:
AssertionFailedException
- if the realm is not the current realm- See Also:
-