Package org.nuxeo.ecm.core.storage
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
HashMapwhen there is a small number of keys.- Since:
- 5.9.5
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classState.ArraysEntryclassState.ArraysEntryIteratorprotected classState.ArraysEntrySetEntrySet optimized to just return a simple Iterator on the entries.static classState.ListDiffA diff for an array orList.static classState.StateDiffA diff for aState.
-
Field Summary
Fields Modifier and Type Field Description static intARRAY_MAXstatic StateEMPTYprotected List<String>keysprotected static Loglogprotected Map<String,Serializable>mapstatic org.nuxeo.ecm.core.storage.State.NopNOPDenotes no change to an element.protected List<Serializable>values
-
Constructor Summary
Constructors Constructor Description State()Constructor with default capacity.State(boolean threadSafe)Constructor with default capacity, optionally thread-safe.State(int size)Constructor for a given default size.State(int size, boolean threadSafe)Constructor for a given default size, optionally thread-safe.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsKey(Object key)Checks if there is a mapping for the given key.Set<Map.Entry<String,Serializable>>entrySet()Gets the entry set.booleanequals(Object other)Serializableget(Object key)Gets a value for a key, ornullif the key is not present.Object[]getArray(String name)Gets an array value.ObjectgetSingle(String name)Gets a single value.protected static intinitialCapacity(int size)booleanisEmpty()Checks if the state is empty.String[]keyArray()Gets an array of keys.Set<String>keySet()Gets the key set.voidput(String key, Serializable value)Sets a key/value.protected voidputEvenIfNull(String key, Serializable value)Serializableremove(Object key)Removes the mapping for a key.voidsetArray(String name, Object[] value)Sets an array value.voidsetSingle(String name, Object value)Sets a single value.intsize()Gets the number of elements.StringtoString()Overridden to display Calendars and arrays better, and truncate long strings and arrays.protected static voidtoString(StringBuilder sb, Object value)
-
-
-
Field Detail
-
log
protected static final Log log
-
ARRAY_MAX
public static final int ARRAY_MAX
- See Also:
- Constant Field Values
-
EMPTY
public static final State EMPTY
-
NOP
public static final org.nuxeo.ecm.core.storage.State.Nop NOP
Denotes no change to an element.
-
map
protected Map<String,Serializable> map
-
values
protected List<Serializable> values
-
-
Constructor Detail
-
State
public State()
Constructor with default capacity.
-
State
public State(boolean threadSafe)
Constructor with default capacity, optionally thread-safe.- Parameters:
threadSafe- iftrue, then aConcurrentHashMapis 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- iftrue, then aConcurrentHashMapis used
-
-
Method Detail
-
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, ornullif 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
nullif there was no mapping for the key
-
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)
-
toString
protected static void toString(StringBuilder sb, Object value)
-
getSingle
public Object getSingle(String name)
Description copied from interface:StateAccessorGets a single value.- Specified by:
getSinglein interfaceStateAccessor- Parameters:
name- the name- Returns:
- the value
-
getArray
public Object[] getArray(String name)
Description copied from interface:StateAccessorGets an array value.- Specified by:
getArrayin interfaceStateAccessor- Parameters:
name- the name- Returns:
- the value
-
setSingle
public void setSingle(String name, Object value)
Description copied from interface:StateAccessorSets a single value.- Specified by:
setSinglein interfaceStateAccessor- Parameters:
name- the namevalue- the value
-
setArray
public void setArray(String name, Object[] value)
Description copied from interface:StateAccessorSets an array value.- Specified by:
setArrayin interfaceStateAccessor- Parameters:
name- the namevalue- the value
-
-