Class NodeMap

    • Constructor Detail

      • NodeMap

        public NodeMap​(StateNode node)
        Creates a new map feature for the given node.
        Parameters:
        node - the node that the feature belongs to
    • Method Detail

      • put

        protected void put​(String key,
                           Serializable value)
        Stores a value with the given key, replacing any value previously stored with the same key.
        Parameters:
        key - the key to use
        value - the value to store
      • put

        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.
        Parameters:
        key - the key to use
        value - the value to store
        emitChange - true to create a change event for the client side
        Returns:
        the previous value, or null if there was no previous value
      • get

        protected Serializable get​(String key)
        Gets the value corresponding to the given key.
        Parameters:
        key - the key to get a value for
        Returns:
        the value corresponding to the key; null if there is no value stored, or if null is stored as a value
      • getOrDefault

        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.
        Parameters:
        key - the key to get a value for
        defaultValue - the value to return if no value is stored for the given key
        Returns:
        the value corresponding to the key or the given defaultValue if no value is stored for the key or the stored value is null
      • getOrDefault

        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.
        Parameters:
        key - the key to get a value for
        defaultValue - the value to return if no value is stored for the given key
        Returns:
        the value corresponding to the key or the given defaultValue if no value is stored for the key or the stored value is null
      • getOrDefault

        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.
        Parameters:
        key - the key to get a value for
        defaultValue - the value to return if no value is stored for the given key
        Returns:
        the value corresponding to the key or the given defaultValue if no value is stored for the key or the stored value is null
      • keySet

        protected Set<String> keySet()
        Gets the defined keys.
        Returns:
        a set containing all the defined keys
      • contains

        protected boolean contains​(String key)
        Checks whether a value is stored for the given key.
        Parameters:
        key - the key to check
        Returns:
        true if there is a value stored; false if no value is stored
      • remove

        protected Serializable remove​(String key)
        Removes the value stored for the given key.
        Parameters:
        key - the key for which to remove the value
        Returns:
        the removed value, null if no value was removed
      • clear

        protected void clear()
        Removes the values for all stored keys.
      • collectChanges

        public void collectChanges​(Consumer<NodeChange> collector)
        Description copied from class: NodeFeature
        Collects all changes that are recorded for this feature.
        Specified by:
        collectChanges in class NodeFeature
        Parameters:
        collector - a consumer accepting node changes
      • generateChangesFromEmpty

        public void generateChangesFromEmpty()
        Description copied from class: NodeFeature
        Generates all changes that would be needed to take this node from its initial empty state to its current state.
        Specified by:
        generateChangesFromEmpty in class NodeFeature
      • forEachChild

        public void forEachChild​(Consumer<StateNode> action)
        Description copied from class: NodeFeature
        Passes each child node instance to the given consumer.
        Specified by:
        forEachChild in class NodeFeature
        Parameters:
        action - the consumer that accepts each child
      • updateFromClient

        public void updateFromClient​(String key,
                                     Serializable value)
        Receives a value update from the client. The map value is updated without creating a change record since the client already knows the current value. The value is only updated if mayUpdateFromClient(String, Serializable) has been overridden to accept the value.
        Parameters:
        key - the key to use
        value - the value to store
      • mayUpdateFromClient

        protected boolean mayUpdateFromClient​(String key,
                                              Serializable value)
        Checks whether the client is allowed to store the given value with the given key. Always returns false by default.
        Parameters:
        key - the key to use
        value - the value to store
        Returns:
        true if the value update is accepted, false if the value should not be allowed to be updated
      • producePutChange

        protected boolean producePutChange​(String key,
                                           boolean hadValueEarlier,
                                           Serializable newValue)
        Checks whether a MapPutChange should be produced.
        Parameters:
        key - a key to produce a change
        hadValueEarlier - whether the value was already earlier in the map
        newValue - the new value for the key
        Returns: