|
Eclipse Platform Release 3.6 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractList
org.eclipse.core.databinding.observable.list.AbstractObservableList
org.eclipse.core.databinding.observable.list.ComputedList
public abstract class ComputedList
A lazily calculated list that automatically computes and registers listeners
on its dependencies as long as all of its dependencies are
IObservable
objects. Any change to one of the observable dependencies
causes the list to be recomputed.
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.
Example: compute the fibonacci sequence, up to as many elements as the value
of an IObservableValue
< Integer
>.
final IObservableValue count = WritableValue.withValueType(Integer.TYPE); count.setValue(new Integer(0)); IObservableList fibonacci = new ComputedList() { protected List calculate() { int size = ((Integer) count.getValue()).intValue(); List result = new ArrayList(); for (int i = 0; i < size; i++) { if (i == 0) result.add(new Integer(0)); else if (i == 1) result.add(new Integer(1)); else { Integer left = (Integer) result.get(i - 2); Integer right = (Integer) result.get(i - 1); result.add(new Integer(left.intValue() + right.intValue())); } } return result; } }; System.out.println(fibonacci); // => "[]" count.setValue(new Integer(5)); System.out.println(fibonacci); // => "[0, 1, 1, 2, 3]"
Field Summary |
---|
Fields inherited from class java.util.AbstractList |
---|
modCount |
Constructor Summary | |
---|---|
ComputedList()
Creates a computed list in the default realm and with an unknown (null) element type. |
|
ComputedList(Object elementType)
Creates a computed list in the default realm and with the given element type. |
|
ComputedList(Realm realm)
Creates a computed list in given realm and with an unknown (null) element type. |
|
ComputedList(Realm realm,
Object elementType)
Creates a computed list in the given realm and with the given element type. |
Method Summary | |
---|---|
void |
addChangeListener(IChangeListener listener)
Adds the given change listener to the list of change listeners. |
void |
addListChangeListener(IListChangeListener listener)
Adds the given list change listener to the list of list change listeners. |
protected abstract List |
calculate()
Subclasses must override this method to calculate the list contents. |
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 int |
doGetSize()
|
Object |
get(int index)
|
Object |
getElementType()
Returns the element type of this observable collection, or null if this observable collection is untyped. |
boolean |
isStale()
Returns whether the state of this observable is stale and is expected to change soon. |
Methods inherited from class org.eclipse.core.databinding.observable.list.AbstractObservableList |
---|
add, addAll, addAll, addDisposeListener, addStaleListener, checkRealm, contains, containsAll, equals, fireChange, fireListChange, fireStale, firstListenerAdded, getRealm, hashCode, hasListeners, indexOf, isDisposed, isEmpty, iterator, lastIndexOf, lastListenerRemoved, move, remove, removeAll, removeChangeListener, removeDisposeListener, removeListChangeListener, removeStaleListener, retainAll, size, toArray, toArray |
Methods inherited from class java.util.AbstractList |
---|
add, clear, 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 org.eclipse.core.databinding.observable.list.IObservableList |
---|
listIterator, listIterator, remove, set, subList |
Methods inherited from interface java.util.List |
---|
add, clear |
Constructor Detail |
---|
public ComputedList()
public ComputedList(Object elementType)
elementType
- the element type, may be null
to indicate unknown
element typepublic ComputedList(Realm realm)
realm
- the realmpublic ComputedList(Realm realm, Object elementType)
realm
- the realmelementType
- the element type, may be null
to indicate unknown
element typeMethod Detail |
---|
protected int doGetSize()
doGetSize
in class AbstractObservableList
public Object get(int index)
get
in interface List
get
in interface IObservableList
get
in class AbstractList
protected abstract List calculate()
IObservable
, and
implementers must use one of the interface methods tagged TrackedGetter
for ComputedList to recognize it as a dependency.
public boolean isStale()
IObservable
isStale
in interface IObservable
isStale
in class AbstractObservableList
public Object getElementType()
IObservableCollection
null
if this observable collection is untyped.
null
if this observable collection is untyped.public void addChangeListener(IChangeListener listener)
IObservable
addChangeListener
in interface IObservable
addChangeListener
in class AbstractObservableList
public void addListChangeListener(IListChangeListener listener)
IObservableList
addListChangeListener
in interface IObservableList
addListChangeListener
in class AbstractObservableList
public void dispose()
IObservable
dispose
in interface IObservable
dispose
in class AbstractObservableList
|
Eclipse Platform Release 3.6 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Guidelines for using Eclipse APIs.
Copyright (c) Eclipse contributors and others 2000, 2010. All rights reserved.