|
Eclipse Platform Release 3.6 |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.eclipse.core.databinding.observable.AbstractObservable
org.eclipse.core.databinding.observable.set.AbstractObservableSet
org.eclipse.core.databinding.observable.set.ComputedSet
public abstract class ComputedSet
A lazily calculated set 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 set 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 set of all primes greater than 1 and less than the value
of an IObservableValue < Integer >.
final IObservableValue max = WritableValue.withValueType(Integer.TYPE);
max.setValue(new Integer(0));
IObservableSet primes = new ComputedSet() {
protected Set calculate() {
int maxVal = ((Integer) max.getValue()).intValue();
Set result = new HashSet();
outer: for (int i = 2; i < maxVal; i++) {
for (Iterator it = result.iterator(); it.hasNext();) {
Integer knownPrime = (Integer) it.next();
if (i % knownPrime.intValue() == 0)
continue outer;
}
result.add(new Integer(i));
}
return result;
}
};
System.out.println(primes); // => "[]"
max.setValue(new Integer(20));
System.out.println(primes); // => "[2, 3, 5, 7, 11, 13, 17, 19]"
| Constructor Summary | |
|---|---|
ComputedSet()
Creates a computed set in the default realm and with an unknown (null) element type. |
|
ComputedSet(java.lang.Object elementType)
Creates a computed set in the default realm and with the given element type. |
|
ComputedSet(Realm realm)
Creates a computed set in given realm and with an unknown (null) element type. |
|
ComputedSet(Realm realm,
java.lang.Object elementType)
Creates a computed set 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. |
protected void |
addListener(java.lang.Object listenerType,
IObservablesListener listener)
|
void |
addSetChangeListener(ISetChangeListener listener)
|
protected abstract java.util.Set |
calculate()
Subclasses must override this method to calculate the set contents. |
protected java.lang.Object |
clone()
|
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()
|
protected void |
fireEvent(ObservableEvent event)
|
java.lang.Object |
getElementType()
Returns the element type of this observable collection, or null if this observable collection is untyped. |
Realm |
getRealm()
|
protected java.util.Set |
getWrappedSet()
|
protected boolean |
hasListeners()
|
boolean |
isStale()
Returns whether the state of this observable is stale and is expected to change soon. |
protected void |
removeListener(java.lang.Object listenerType,
IObservablesListener listener)
|
| Methods inherited from class org.eclipse.core.databinding.observable.set.AbstractObservableSet |
|---|
add, addAll, clear, contains, containsAll, equals, fireChange, fireSetChange, firstListenerAdded, getterCalled, hashCode, isEmpty, iterator, lastListenerRemoved, remove, removeAll, removeSetChangeListener, retainAll, setStale, size, toArray, toArray, toString |
| Methods inherited from class org.eclipse.core.databinding.observable.AbstractObservable |
|---|
addDisposeListener, addStaleListener, checkRealm, fireStale, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface org.eclipse.core.databinding.observable.IObservable |
|---|
addDisposeListener, addStaleListener, getRealm, isDisposed, removeChangeListener, removeDisposeListener, removeStaleListener |
| Constructor Detail |
|---|
public ComputedSet()
public ComputedSet(java.lang.Object elementType)
elementType - the element type, may be null to indicate unknown
element typepublic ComputedSet(Realm realm)
realm - the realm
public ComputedSet(Realm realm,
java.lang.Object elementType)
realm - the realmelementType - the element type, may be null to indicate unknown
element type| Method Detail |
|---|
protected int doGetSize()
protected java.util.Set getWrappedSet()
getWrappedSet in class AbstractObservableSetprotected abstract java.util.Set calculate()
IObservable, and
implementers must use one of the interface methods tagged TrackedGetter
for ComputedSet to recognize it as a dependency.
public boolean isStale()
IObservable
isStale in interface IObservableisStale in class AbstractObservableSetpublic java.lang.Object getElementType()
IObservableCollectionnull if this observable collection is untyped.
null if this observable collection is untyped.public void addChangeListener(IChangeListener listener)
IObservable
addChangeListener in interface IObservableaddChangeListener in class AbstractObservablepublic void addSetChangeListener(ISetChangeListener listener)
addSetChangeListener in interface IObservableSetaddSetChangeListener in class AbstractObservableSetpublic void dispose()
IObservable
dispose in interface IObservabledispose in class AbstractObservable
protected void addListener(java.lang.Object listenerType,
IObservablesListener listener)
listenerType - listener -
protected void removeListener(java.lang.Object listenerType,
IObservablesListener listener)
listenerType - listener - protected boolean hasListeners()
protected void fireEvent(ObservableEvent event)
public Realm getRealm()
protected java.lang.Object clone()
throws java.lang.CloneNotSupportedException
clone in class java.lang.Objectjava.lang.CloneNotSupportedException
|
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.