T - type of wrapped valuepublic class MutableValue<T> extends java.lang.Object implements ChangingValue<T>
MutableValue is a wrapper of value that you can replace and whose changes will be propagated
to derived values.
A good usage example would be a config from which other values could be derived and should be changed once config changes.
| Modifier and Type | Method and Description |
|---|---|
long |
changeVersion()
Indicator of how often has the wrapped value changed.
|
static <T> MutableValue<T> |
failedMutableValue(java.lang.RuntimeException exception)
Factory method for
MutableValue |
static <T> MutableValue<T> |
mutableValue(T initialValue)
Factory method for
MutableValue |
java.util.Optional<java.lang.String> |
name() |
void |
updateAsFailure(java.lang.RuntimeException exception)
Updates wrapped value as an exception and increments the
changeVersion |
void |
updateValue(T newValue)
Updates wrapped value and increments the
changeVersion |
boolean |
updateValueIfDifferent(T potentialNewValue)
If
potentialNewValue is different than the already wrapped, it then value will replace the old one
and the changeVersion will be incremented. |
T |
value() |
MutableValue<T> |
withDisposeFunction(java.util.function.Consumer<T> disposeFunction)
Creates a copy of current
MutableValue with defined dispose function |
MutableValue<T> |
withDisposeFunction(java.util.Optional<java.util.function.Consumer<T>> optionalDisposeFunction)
Creates a copy of current
MutableValue with new dispose function if Optional dispose function is defined
and without a dispose function if the Optional dispose function is undefined |
MutableValue<T> |
withNoDisposeFunction()
Creates a copy of current
MutableValue with dispose function being removed |
MutableValue<T> |
withNoOnValueSetFunction()
Creates a copy of current
MutableValue with on value set function being removed |
MutableValue<T> |
withNoValueName()
Creates a copy of current
MutableValue with value name being removed |
MutableValue<T> |
withOnValueSetFunction(java.util.function.Consumer<T> onValueSetFunction,
boolean applyToCurrentValue)
Creates a copy of current
MutableValue with defined function applied to each new wrapped value |
MutableValue<T> |
withOnValueSetFunction(java.util.Optional<java.util.function.Consumer<T>> optionalOnValueSetFunction,
boolean applyToCurrentValue)
Creates a copy of current
MutableValue with new on value set function if Optional on value set function is defined
and without an on value set function if the Optional on value set function is undefined |
MutableValue<T> |
withValueName(java.util.Optional<java.lang.String> optionalValueName)
Creates a copy of current
MutableValue with new value name if Optional name is defined
and without a value name if the Optional name is undefined |
MutableValue<T> |
withValueName(java.lang.String valueName)
Creates a copy of current
MutableValue with defined value name |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforCurrentValue, join, join, join, map, mapToValuepublic static <T> MutableValue<T> mutableValue(T initialValue)
MutableValueT - type of wrapped valueinitialValue - initial valueMutableValue valuepublic static <T> MutableValue<T> failedMutableValue(java.lang.RuntimeException exception)
MutableValueT - type of wrapped valueexception - RuntimeException caught when trying to get initial valueMutableValue valuepublic MutableValue<T> withValueName(java.lang.String valueName)
MutableValue with defined value namevalueName - new value name to useMutableValue with a new value namepublic MutableValue<T> withNoValueName()
MutableValue with value name being removedMutableValue without a value namepublic MutableValue<T> withValueName(java.util.Optional<java.lang.String> optionalValueName)
MutableValue with new value name if Optional name is defined
and without a value name if the Optional name is undefinedoptionalValueName - if empty new MutableValue will have no value name otherwise the define value name will be usedMutableValue with defined value namepublic MutableValue<T> withOnValueSetFunction(java.util.function.Consumer<T> onValueSetFunction, boolean applyToCurrentValue)
MutableValue with defined function applied to each new wrapped valueonValueSetFunction - function that is called using new value when it is being passed inapplyToCurrentValue - indicator if the onValueSetFunction should be applied to the currently wrapped valueMutableValue with a new on value set functionpublic MutableValue<T> withNoOnValueSetFunction()
MutableValue with on value set function being removedMutableValue without an on value set functionpublic MutableValue<T> withOnValueSetFunction(java.util.Optional<java.util.function.Consumer<T>> optionalOnValueSetFunction, boolean applyToCurrentValue)
MutableValue with new on value set function if Optional on value set function is defined
and without an on value set function if the Optional on value set function is undefinedoptionalOnValueSetFunction - if empty new MutableValue will have no on value set function otherwise the define on value set function will be usedapplyToCurrentValue - indicator if the defined optionalOnValueSetFunction should be applied to the currently wrapped valueMutableValue with defined on value set functionpublic MutableValue<T> withDisposeFunction(java.util.function.Consumer<T> disposeFunction)
MutableValue with defined dispose functiondisposeFunction - function that is called using old value when a new value is being passed inMutableValue with a new dispose functionpublic MutableValue<T> withNoDisposeFunction()
MutableValue with dispose function being removedMutableValue without a dispose functionpublic MutableValue<T> withDisposeFunction(java.util.Optional<java.util.function.Consumer<T>> optionalDisposeFunction)
MutableValue with new dispose function if Optional dispose function is defined
and without a dispose function if the Optional dispose function is undefinedoptionalDisposeFunction - if empty new MutableValue will have no dispose function otherwise the define dispose function will be usedMutableValue with defined dispose functionpublic java.util.Optional<java.lang.String> name()
name in interface ChangingValue<T>ChangingValuepublic void updateValue(T newValue)
changeVersionnewValue - new value that will be wrappedpublic boolean updateValueIfDifferent(T potentialNewValue)
potentialNewValue is different than the already wrapped, it then value will replace the old one
and the changeVersion will be incremented. If they will be the same then no change will happenpotentialNewValue - value that might be wrapped if it is different than the already wrappedpublic void updateAsFailure(java.lang.RuntimeException exception)
changeVersionexception - new value that will be wrappedpublic long changeVersion()
ChangingValuechangeVersion should
increase by one.changeVersion in interface ChangingValue<T>