public abstract class NodeMap extends NodeFeature
Constructor and Description |
---|
NodeMap(StateNode node)
Creates a new map feature for the given node.
|
Modifier and Type | Method and Description |
---|---|
protected void |
clear()
Removes the values for all stored keys.
|
void |
collectChanges(Consumer<NodeChange> collector)
Collects all changes that are recorded for this feature.
|
protected boolean |
contains(String key)
Checks whether a value is stored for the given key.
|
void |
forEachChild(Consumer<StateNode> action)
Passes each child node instance to the given consumer.
|
void |
generateChangesFromEmpty()
Generates all changes that would be needed to take this node from its
initial empty state to its current state.
|
protected Serializable |
get(String key)
Gets the value corresponding to the given key.
|
protected boolean |
getOrDefault(String key,
boolean defaultValue)
Gets the value corresponding to the given key, or the given default value
if no value is stored for the given key or the value is null.
|
protected int |
getOrDefault(String key,
int defaultValue)
Gets the value corresponding to the given key, or the given default value
if no value is stored for the given key or the value is null.
|
protected String |
getOrDefault(String key,
String defaultValue)
Gets the value corresponding to the given key, or the given default value
if no value is stored for the given key or the value is null.
|
protected Set<String> |
keySet()
Gets the defined keys.
|
protected boolean |
mayUpdateFromClient(String key,
Serializable value)
Checks whether the client is allowed to store the given value with the
given key.
|
protected void |
put(String key,
Serializable value)
Stores a value with the given key, replacing any value previously stored
with the same key.
|
protected Serializable |
put(String key,
Serializable value,
boolean emitChange)
Stores a value with the given key, replacing any value previously stored
with the same key.
|
protected Serializable |
remove(String key)
Removes the value stored for the given key.
|
void |
updateFromClient(String key,
Serializable value)
Receives a value update from the client.
|
allowsChanges, attachPotentialChild, detatchPotentialChild, getNode, onAttach, onDetach
public NodeMap(StateNode node)
node
- the node that the feature belongs toprotected void put(String key, Serializable value)
key
- the key to usevalue
- the value to storeprotected Serializable put(String key, Serializable value, boolean emitChange)
key
- the key to usevalue
- the value to storeemitChange
- true to create a change event for the client sidenull
if there was no previous
valueprotected Serializable get(String key)
key
- the key to get a value fornull
if there is
no value stored, or if null
is stored as a valueprotected String getOrDefault(String key, String defaultValue)
key
- the key to get a value fordefaultValue
- the value to return if no value is stored for the given keydefaultValue
if no value is stored for the key or the
stored value is nullprotected int getOrDefault(String key, int defaultValue)
key
- the key to get a value fordefaultValue
- the value to return if no value is stored for the given keydefaultValue
if no value is stored for the key or the
stored value is nullprotected boolean getOrDefault(String key, boolean defaultValue)
key
- the key to get a value fordefaultValue
- the value to return if no value is stored for the given keydefaultValue
if no value is stored for the key or the
stored value is nullprotected Set<String> keySet()
protected boolean contains(String key)
key
- the key to checktrue
if there is a value stored; false
if no value is storedprotected Serializable remove(String key)
key
- the key for which to remove the valuenull
if no value was removedprotected void clear()
public void collectChanges(Consumer<NodeChange> collector)
NodeFeature
collectChanges
in class NodeFeature
collector
- a consumer accepting node changespublic void generateChangesFromEmpty()
NodeFeature
generateChangesFromEmpty
in class NodeFeature
public void forEachChild(Consumer<StateNode> action)
NodeFeature
forEachChild
in class NodeFeature
action
- the consumer that accepts each childpublic void updateFromClient(String key, Serializable value)
mayUpdateFromClient(String, Serializable)
has been overridden to
accept the value.key
- the key to usevalue
- the value to storeprotected boolean mayUpdateFromClient(String key, Serializable value)
false
by default.key
- the key to usevalue
- the value to storetrue
if the value update is accepted,
false
if the value should not be allowed to be
updatedCopyright © 2020. All rights reserved.