Class State

java.lang.Object
org.nuxeo.ecm.core.storage.State
All Implemented Interfaces:
Serializable, StateAccessor
Direct Known Subclasses:
State.StateDiff

public class State extends Object implements StateAccessor, Serializable
Abstraction for a Map<String, Serializable> that is Serializable.

Internal storage is optimized to avoid a full HashMap when there is a small number of keys.

Since:
5.9.5
See Also:
  • Field Details

  • Constructor Details

    • State

      public State()
      Constructor with default capacity.
    • State

      public State(boolean threadSafe)
      Constructor with default capacity, optionally thread-safe.
      Parameters:
      threadSafe - if true, then a ConcurrentHashMap is used
    • State

      public State(int size)
      Constructor for a given default size.
    • State

      public State(int size, boolean threadSafe)
      Constructor for a given default size, optionally thread-safe.
      Parameters:
      threadSafe - if true, then a ConcurrentHashMap is used
  • Method Details

    • initialCapacity

      protected static int initialCapacity(int size)
    • size

      public int size()
      Gets the number of elements.
    • isEmpty

      public boolean isEmpty()
      Checks if the state is empty.
    • get

      public Serializable get(Object key)
      Gets a value for a key, or null if the key is not present.
    • put

      public void put(String key, Serializable value)
      Sets a key/value.
    • putEvenIfNull

      protected void putEvenIfNull(String key, Serializable value)
    • remove

      public Serializable remove(Object key)
      Removes the mapping for a key.
      Returns:
      the previous value associated with the key, or null if there was no mapping for the key
    • keySet

      public Set<String> keySet()
      Gets the key set. IT MUST NOT BE MODIFIED.
    • keyArray

      public String[] keyArray()
      Gets an array of keys.
    • containsKey

      public boolean containsKey(Object key)
      Checks if there is a mapping for the given key.
    • entrySet

      public Set<Map.Entry<String,Serializable>> entrySet()
      Gets the entry set. IT MUST NOT BE MODIFIED.
    • toString

      public String toString()
      Overridden to display Calendars and arrays better, and truncate long strings and arrays.

      Also displays some keys first (ecm:id, ecm:name, ecm:primaryType)

      Overrides:
      toString in class Object
    • toString

      protected static void toString(StringBuilder sb, Object value)
    • getSingle

      public Object getSingle(String name)
      Description copied from interface: StateAccessor
      Gets a single value.
      Specified by:
      getSingle in interface StateAccessor
      Parameters:
      name - the name
      Returns:
      the value
    • getArray

      public Object[] getArray(String name)
      Description copied from interface: StateAccessor
      Gets an array value.
      Specified by:
      getArray in interface StateAccessor
      Parameters:
      name - the name
      Returns:
      the value
    • setSingle

      public void setSingle(String name, Object value)
      Description copied from interface: StateAccessor
      Sets a single value.
      Specified by:
      setSingle in interface StateAccessor
      Parameters:
      name - the name
      value - the value
    • setArray

      public void setArray(String name, Object[] value)
      Description copied from interface: StateAccessor
      Sets an array value.
      Specified by:
      setArray in interface StateAccessor
      Parameters:
      name - the name
      value - the value
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object