- java.lang.Object
-
- io.github.stasgora.observetree.Observable
-
- io.github.stasgora.observetree.SettableProperty<T>
-
- Type Parameters:
T
- the type of the actual observable data type
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
SettableObservable
public class SettableProperty<T> extends Observable implements Serializable
A wrapper class that encapsulates another object -modelValue
- and notifies it's listeners when it is set.equals()
method is used to determine ifdefaultValue
was changed. It supportsdefaultValue
for themodelValue
that can be set and reset to.- Author:
- Stanisław Góra
- See Also:
SettableObservable
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected T
defaultValue
Default value of the encapsulated objectprotected T
modelValue
Current value of the encapsulated object-
Fields inherited from class io.github.stasgora.observetree.Observable
notificationMethod
-
-
Constructor Summary
Constructors Constructor Description SettableProperty()
SettableProperty(T modelValue)
Constructs a newSettableProperty
with the specifiedmodelValue
-
Method Summary
Modifier and Type Method Description T
get()
Returns the currentmodelValue
of thisSettableProperty
T
getDefaultValue()
Returns thedefaultValue
of thisSettableProperty
void
modify(UnaryOperator<T> operator)
Modifies themodelValue
of thisSettableProperty
inlineboolean
present()
Checks if themodelValue
is notnull
void
resetToDefaultValue()
void
saveAsDefaultValue()
void
set(T modelValue)
Sets themodelValue
of thisSettableProperty
void
setAndNotify(T modelValue)
Sets themodelValue
and callsObservable.notifyListeners()
void
setDefaultValue(T defaultValue)
Sets thedefaultValue
of thisSettableProperty
-
Methods inherited from class io.github.stasgora.observetree.Observable
add, add, add, addChild, addListener, addListener, addListener, addParent, addSubObservable, clearListeners, copyListeners, getChildren, getParents, isValueChanged, notifyListeners, onValueChanged, remove, removeChild, removeListener, removeParent, removeSubObservable, setUnchanged
-
-
-
-
Constructor Detail
-
SettableProperty
public SettableProperty()
-
SettableProperty
public SettableProperty(T modelValue)
Constructs a newSettableProperty
with the specifiedmodelValue
- Parameters:
modelValue
- a value to be set
-
-
Method Detail
-
present
public boolean present()
Checks if themodelValue
is notnull
- Returns:
false
if themodelValue
isnull
,true
otherwise
-
get
public T get()
Returns the currentmodelValue
of thisSettableProperty
- Returns:
- the current
modelValue
-
set
public void set(T modelValue)
Sets themodelValue
of thisSettableProperty
- Parameters:
modelValue
- value to be set
-
setAndNotify
public void setAndNotify(T modelValue)
Sets themodelValue
and callsObservable.notifyListeners()
- Parameters:
modelValue
- value to be set
-
modify
public void modify(UnaryOperator<T> operator)
Modifies themodelValue
of thisSettableProperty
inline- Parameters:
operator
- operation to be performed onmodelValue
-
resetToDefaultValue
public void resetToDefaultValue()
Sets themodelValue
of thisSettableProperty
to thedefaultValue
. If thedefaultValue
isnull
no action will be performed.
-
getDefaultValue
public T getDefaultValue()
Returns thedefaultValue
of thisSettableProperty
- Returns:
- the
defaultValue
of this object
-
setDefaultValue
public void setDefaultValue(T defaultValue)
Sets thedefaultValue
of thisSettableProperty
- Parameters:
defaultValue
- value to be set
-
saveAsDefaultValue
public void saveAsDefaultValue()
-
-