|
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(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,
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(Object listenerType,
IObservablesListener listener)
|
void |
addSetChangeListener(ISetChangeListener listener)
|
protected abstract Set |
calculate()
Subclasses must override this method to calculate the set contents. |
protected 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)
|
Object |
getElementType()
Returns the element type of this observable collection, or null if this observable collection is untyped. |
Realm |
getRealm()
|
protected 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(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(Object elementType)
elementType
- the element type, may be null
to indicate unknown
element typepublic ComputedSet(Realm realm)
realm
- the realmpublic ComputedSet(Realm realm, Object elementType)
realm
- the realmelementType
- the element type, may be null
to indicate unknown
element typeMethod Detail |
---|
protected int doGetSize()
protected Set getWrappedSet()
getWrappedSet
in class AbstractObservableSet
protected abstract 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 IObservable
isStale
in class AbstractObservableSet
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 AbstractObservable
public void addSetChangeListener(ISetChangeListener listener)
addSetChangeListener
in interface IObservableSet
addSetChangeListener
in class AbstractObservableSet
public void dispose()
IObservable
dispose
in interface IObservable
dispose
in class AbstractObservable
protected void addListener(Object listenerType, IObservablesListener listener)
listenerType
- listener
- protected void removeListener(Object listenerType, IObservablesListener listener)
listenerType
- listener
- protected boolean hasListeners()
protected void fireEvent(ObservableEvent event)
public Realm getRealm()
protected Object clone() throws CloneNotSupportedException
clone
in class Object
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.