ch.elca.el4j.util.observer.impl
Class LiveValue<T>

java.lang.Object
  extended by ch.elca.el4j.util.observer.impl.AbstractObservableValue<T>
      extended by ch.elca.el4j.util.observer.impl.LiveValue<T>
Type Parameters:
T - see supertype
All Implemented Interfaces:
InquisitiveValueObserver<Object>, ObservableValue<T>, ValueObserver<Object>

public class LiveValue<T>
extends AbstractObservableValue<T>
implements InquisitiveValueObserver<Object>

A LiveValue is a derived value that stays up to date by itself.

A LiveValue is defined by a method computing it. The method is usually implemented in a Computable and given to LiveValue's public constructor. Alternatively, the method may also be provided by overriding is(). In that case, you may not assume that the subclass' constructor is invoked before is() is.

A LiveValue is an ObservableValue. Therefore, it is possible to build directed acyclic graphs (and thus trees) of LiveValues. For obvious reasons, cyclic dependencies are not permitted; detection of one results in a CyclicDependencyException to be thrown.

This class is thread safe.

If the live value only depends on values of type ObservableValue (which it obtains by invoking ObservableValue.get()), the live value will keep itself up to date by itself. Otherwise, updates must be requested manually using revise().

Author:
Adrian Moos (AMS)
See Also:
LiveValueFactory
File-location:
LiveValue
Last check-in date:
2009-08-04 15:17:52 +0200 (Di, 04. Aug 2009) by swismer for revision 3880

Nested Class Summary
protected static class LiveValue.Currency
          a cached value's degree of currency.
 
Constructor Summary
protected LiveValue()
          creates this live value.
  LiveValue(Computable<T> computation)
          creates the live value defined by the supplied Computable.
 
Method Summary
 void changed(Object newvalue)
          not intended for public use.
 T get()
          .
protected  T is()
          The computation represented by this live value.
 void notified()
          not intended for public use.
 void revise()
          revise the result cached by this live value, i.e. ensure it is still correct.Invoke this method if non-observable input values may have changed.
 String toString()
          returns a textual description of this live value.
 
Methods inherited from class ch.elca.el4j.util.observer.impl.AbstractObservableValue
equal, set, subscribe, subscribeSilently, unsubscribe
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LiveValue

protected LiveValue()
creates this live value. Subclasses must override is() and be prepared to receive calls to it before their constructor is invoked. (This restriction can be circumvented by initializing the live value in a separate Computable before passing it to this class' other constructor)


LiveValue

public LiveValue(Computable<T> computation)
creates the live value defined by the supplied Computable.

Method Detail

is

protected T is()
The computation represented by this live value. Uses other observables and

Returns:
the live value's current value

revise

public void revise()
revise the result cached by this live value, i.e. ensure it is still correct.Invoke this method if non-observable input values may have changed.


get

public T get()
.

Specified by:
get in interface ObservableValue<T>
Overrides:
get in class AbstractObservableValue<T>
Returns:
this observable's current value

changed

public void changed(Object newvalue)
not intended for public use.

Specified by:
changed in interface ValueObserver<Object>
Parameters:
newvalue - the new reference

toString

public String toString()
returns a textual description of this live value.

Overrides:
toString in class Object

notified

public void notified()
not intended for public use.

Specified by:
notified in interface InquisitiveValueObserver<Object>


Copyright © 2005-2011 ELCA. All Rights Reserved.