T
- The type of the value.public final class DefaultDynamicValue<T> extends Object implements DynamicValue<T>, Serializable
UpdatePolicy
the new value is immedeately active or it requires an active commit
by client code. Similarly an instance also can ignore all later changes to the value.
DynamicValue.UpdatePolicy
Modifier and Type | Method and Description |
---|---|
void |
addListener(PropertyChangeListener l)
Add a listener to be called as weak reference, when this value has been changed.
|
void |
commit()
Commits a new value that has not been committed yet, make it the new value of the instance.
|
T |
commitAndGet()
Performs a commit, if necessary, and returns the current value.
|
void |
discard()
Discards a new value that was published.
|
T |
evaluateValue()
Evaluates the current value dynamically from the underlying configuration.
|
T |
get()
If a value is present in this
DynamicValue , returns the value,
otherwise throws ConfigException . |
T |
getNewValue()
Access a new value that has not yet been committed.
|
DynamicValue.UpdatePolicy |
getUpdatePolicy()
Access the
UpdatePolicy used for updating this value. |
boolean |
isPresent()
Return
true if there is a value present, otherwise false . |
static DynamicValue |
of(Field annotatedField,
Configuration configuration) |
static DynamicValue |
of(Method method,
Configuration configuration) |
T |
orElse(T other)
Return the value if present, otherwise return
other . |
T |
orElseGet(ConfiguredItemSupplier<? extends T> other)
Return the value if present, otherwise invoke
other and return
the result of that invocation. |
<X extends Throwable> |
orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier)
Return the contained value, if present, otherwise throw an exception
to be created by the provided supplier.
|
void |
removeListener(PropertyChangeListener l)
Removes a listener to be called, when this value has been changed.
|
void |
setUpdatePolicy(DynamicValue.UpdatePolicy updatePolicy)
Sets a new
UpdatePolicy . |
boolean |
updateValue()
Method to check for and apply a new value.
|
public static DynamicValue of(Field annotatedField, Configuration configuration)
public static DynamicValue of(Method method, Configuration configuration)
public T commitAndGet()
commitAndGet
in interface DynamicValue<T>
DynamicValue
ConfigException
- if there is no value presentisPresent()
public void commit()
commit
in interface DynamicValue<T>
public void discard()
discard
in interface DynamicValue<T>
public DynamicValue.UpdatePolicy getUpdatePolicy()
UpdatePolicy
used for updating this value.getUpdatePolicy
in interface DynamicValue<T>
public void setUpdatePolicy(DynamicValue.UpdatePolicy updatePolicy)
UpdatePolicy
.setUpdatePolicy
in interface DynamicValue<T>
updatePolicy
- the new policy, not null.public void addListener(PropertyChangeListener l)
addListener
in interface DynamicValue<T>
l
- the listener, not nullpublic void removeListener(PropertyChangeListener l)
removeListener
in interface DynamicValue<T>
l
- the listner to be removed, not nullpublic T get()
DynamicValue
, returns the value,
otherwise throws ConfigException
.get
in interface DynamicValue<T>
Optional
ConfigException
- if there is no value presentisPresent()
public boolean updateValue()
UpdatePolicy
the value is immediately or deferred visible (or it may even be ignored completely).updateValue
in interface DynamicValue<T>
DefaultDynamicValue.UpdatePolicy
in place.public T evaluateValue()
evaluateValue
in interface DynamicValue<T>
public T getNewValue()
getNewValue
in interface DynamicValue<T>
public boolean isPresent()
true
if there is a value present, otherwise false
.isPresent
in interface DynamicValue<T>
true
if there is a value present, otherwise false
public T orElse(T other)
other
.orElse
in interface DynamicValue<T>
other
- the value to be returned if there is no value present, may
be nullother
public T orElseGet(ConfiguredItemSupplier<? extends T> other)
other
and return
the result of that invocation.orElseGet
in interface DynamicValue<T>
other
- a ConfiguredItemSupplier
whose result is returned if no value
is presentother.get()
NullPointerException
- if value is not present and other
is
nullpublic <X extends Throwable> T orElseThrow(ConfiguredItemSupplier<? extends X> exceptionSupplier) throws X extends Throwable
NOTE A method reference to the exception constructor with an empty
argument list can be used as the supplier. For example,
IllegalStateException::new
orElseThrow
in interface DynamicValue<T>
X
- Type of the exception to be thrownexceptionSupplier
- The supplier which will return the exception to
be thrownX
- if there is no value presentNullPointerException
- if no value is present and
exceptionSupplier
is nullX extends Throwable
Copyright © 2014–2015 Apache Software Foundation. All rights reserved.