public final class IntProperty extends java.lang.Object implements ConfigurationObserver
IntProperty
is a ConfigurationObserver
implementation that observes changes to a configuration value with a given ID and is of type int
.
You can think of this class as a variable of type int
. 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 |
---|
IntProperty(java.lang.String id)
Constructs a new
IntProperty given an ID. |
IntProperty(java.lang.String id,
int defaultValue)
Constructs a new
IntProperty given an ID and a default configuration value. |
IntProperty(java.lang.String id,
int defaultValue,
java.util.function.IntConsumer intConsumer)
Constructs a new
IntProperty given an ID, a default configuration value and an IntConsumer 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. |
int |
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(int value)
Sets a new configuration value.
|
public IntProperty(java.lang.String id)
IntProperty
given an ID.
Calling this constructor is equivalent to calling new IntProperty(id, 0)
.
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 IntProperty(java.lang.String id, int defaultValue)
IntProperty
given an ID and a default configuration value.
Calling this constructor is equivalent to calling new IntProperty(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 IntProperty(java.lang.String id, int defaultValue, java.util.function.IntConsumer intConsumer)
IntProperty
given an ID, a default configuration value and an IntConsumer
to consume the configuration value.
If either id
or intConsumer
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 existsintConsumer
- the IntConsumer
that will consume the configuration value on changesjava.lang.NullPointerException
- thrown if, and only if, either id
or intConsumer
are null
public int 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(int 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 IntProperty
to a Configuration
.
value
- the new configuration value