public final class DoubleProperty extends java.lang.Object implements ConfigurationObserver
DoubleProperty
is a ConfigurationObserver
implementation that observes changes to a configuration value with a given ID and is of type double
.
You can think of this class as a variable of type double
. This means you can get or set its value. Setting its value will set it in its current Configuration
, if present.
This class is thread-safe and therefore also suitable for concurrent use without external synchronization.
Constructor and Description |
---|
DoubleProperty(java.lang.String id)
Constructs a new
DoubleProperty given an ID. |
DoubleProperty(java.lang.String id,
double defaultValue)
Constructs a new
DoubleProperty given an ID and a default configuration value. |
DoubleProperty(java.lang.String id,
double defaultValue,
java.util.function.DoubleConsumer doubleConsumer)
Constructs a new
DoubleProperty given an ID, a default configuration value and an DoubleConsumer to consume the configuration value. |
Modifier and Type | Method and Description |
---|---|
void |
added(Configuration configuration)
Called by the
Configuration that this ConfigurationObserver instance was just added to. |
double |
get()
Returns the current configuration value.
|
void |
objectSet(Configuration configuration,
java.lang.String id,
java.util.Optional<?> oldObject,
java.util.Optional<?> newObject)
Called by a
Configuration when a new Object has been set for a given ID. |
void |
removed(Configuration configuration)
Called by the
Configuration that this ConfigurationObserver instance was just removed from. |
void |
set(double value)
Sets a new configuration value.
|
public DoubleProperty(java.lang.String id)
DoubleProperty
given an ID.
Calling this constructor is equivalent to calling new DoubleProperty(id, 0.0D)
.
If id
is null
, a NullPointerException
will be thrown.
id
- the ID of the configuration value to observe changes tojava.lang.NullPointerException
- thrown if, and only if, id
is null
public DoubleProperty(java.lang.String id, double defaultValue)
DoubleProperty
given an ID and a default configuration value.
Calling this constructor is equivalent to calling new DoubleProperty(id, defaultValue, value -> {})
.
If id
is null
, a NullPointerException
will be thrown.
id
- the ID of the configuration value to observe changes todefaultValue
- the default configuration value to return in case no configuration value with the given ID existsjava.lang.NullPointerException
- thrown if, and only if, id
is null
public DoubleProperty(java.lang.String id, double defaultValue, java.util.function.DoubleConsumer doubleConsumer)
DoubleProperty
given an ID, a default configuration value and an DoubleConsumer
to consume the configuration value.
If either id
or doubleConsumer
are null
, a NullPointerException
will be thrown.
id
- the ID of the configuration value to observe changes todefaultValue
- the default configuration value to return in case no configuration value with the given ID existsdoubleConsumer
- the DoubleConsumer
that will consume the configuration value on changesjava.lang.NullPointerException
- thrown if, and only if, either id
or doubleConsumer
are null
public double get()
If no configuration value was ever stored in the Configuration
, the default configuration value will be returned.
public void added(Configuration configuration)
Configuration
that this ConfigurationObserver
instance was just added to.
If configuration
is null
, a NullPointerException
will be thrown.
added
in interface ConfigurationObserver
configuration
- the Configuration
that called this methodjava.lang.NullPointerException
- thrown if, and only if, configuration
is null
public void objectSet(Configuration configuration, java.lang.String id, java.util.Optional<?> oldObject, java.util.Optional<?> newObject)
Configuration
when a new Object
has been set for a given ID.
If either configuration
, id
, oldObject
or newObject
are null
, a NullPointerException
will be thrown.
objectSet
in interface ConfigurationObserver
configuration
- the Configuration
that called this methodid
- the ID of the Object
oldObject
- an Optional
that contains the old configuration value, if it was setnewObject
- an Optional
that contains the new configuration value, if it is setjava.lang.NullPointerException
- thrown if, and only if, either configuration
, id
, oldObject
or newObject
are null
public void removed(Configuration configuration)
Configuration
that this ConfigurationObserver
instance was just removed from.
If configuration
is null
, a NullPointerException
will be thrown.
removed
in interface ConfigurationObserver
configuration
- the Configuration
that called this methodjava.lang.NullPointerException
- thrown if, and only if, configuration
is null
public void set(double value)
This method will set the new configuration value in the Configuration
, if present. The Configuration
will only be present if you have added this DoubleProperty
to a Configuration
.
value
- the new configuration value