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
ConstructorDescriptionObservable
(T initialValue) Constructs the observable with an initial value.Observable
(T initialValue, Class<T> clazz) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCallback
(IInvalidationCallback callback) Adds a callback that is notified whensetValue
is called.static <T> Observable
<T> create
(T initialValue) Creates a newObservable
with the given initial value.static <T> Observable
<T> getValue()
Returns the observable value.void
removeCallback
(IInvalidationCallback callback) Remove the given callback.void
Sets the observable value.
-
Constructor Details
-
Observable
Constructs the observable with an initial value.- Parameters:
initialValue
- the initial value.
-
Observable
-
-
Method Details
-
create
Creates a newObservable
with the given initial value.- Parameters:
initialValue
- the initial value.
-
create
-
getValue
Returns the observable value.- Returns:
- the observable value.
-
setValue
Sets the observable value.This triggers a call to the
configured
callbacks.- Parameters:
value
- the new value- Throws:
IllegalStateException
- when callingsetValue
on derived instances for example.
-
addCallback
Adds a callback that is notified whensetValue
is 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.
-