Package com.luciad.utils
Class Observable<T>
java.lang.Object
com.luciad.utils.Observable<T>
- Type Parameters:
T- the type to hold
This class makes it possible to hold and observe a value that can change over time.
-
Constructor Summary
ConstructorsConstructorDescriptionObservable(T initialValue) Constructs the observable with an initial value.Observable(T initialValue, Class<T> clazz) Constructs the observable with an initial value. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCallback(IInvalidationCallback callback) Adds a callback that is notified whensetValueis called.static <T> Observable<T> create(T initialValue) Creates a newObservablewith the given initial value.static <U> Observable<U> Creates a new Observable with the given initial valuegetValue()Returns the observable value.voidremoveCallback(IInvalidationCallback callback) Remove the given callback.voidSets the observable value.
-
Constructor Details
-
Observable
Constructs the observable with an initial value.- Parameters:
initialValue- the initial value.
-
Observable
Constructs the observable with an initial value.- Parameters:
initialValue- the initial value.clazz- the class of initialValue.
-
-
Method Details
-
create
Creates a newObservablewith the given initial value.- Parameters:
initialValue- the initial value.- Returns:
- the created
Observable.
-
create
Creates a new Observable with the given initial value- Type Parameters:
U- the type of the initial value.- Parameters:
initialValue- the initial value.clazz- the class of hte initial value.- Returns:
- the created Observable.
-
getValue
Returns the observable value.- Returns:
- the observable value.
-
setValue
Sets the observable value.This triggers a call to the
configuredcallbacks.- Parameters:
value- the new value- Throws:
IllegalStateException- when callingsetValueon derived instances for example.
-
addCallback
Adds a callback that is notified whensetValueis called.- Parameters:
callback- a callback- Throws:
IllegalArgumentException- when the call back is already added.
-
removeCallback
Remove the given callback.- Parameters:
callback- a callback- Throws:
IllegalArgumentException- when the call back is not known.
-