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
HashMap
when 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 class
State.ArraysEntry
class
State.ArraysEntryIterator
protected class
State.ArraysEntrySet
EntrySet optimized to just return a simple Iterator on the entries.static class
State.ListDiff
A diff for an array orList
.static class
State.StateDiff
A diff for aState
.
-
Field Summary
Fields Modifier and Type Field Description static int
ARRAY_MAX
static State
EMPTY
protected List<String>
keys
protected static Log
log
protected Map<String,Serializable>
map
static org.nuxeo.ecm.core.storage.State.Nop
NOP
Denotes 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 boolean
containsKey(Object key)
Checks if there is a mapping for the given key.Set<Map.Entry<String,Serializable>>
entrySet()
Gets the entry set.boolean
equals(Object other)
Serializable
get(Object key)
Gets a value for a key, ornull
if the key is not present.Object[]
getArray(String name)
Gets an array value.Object
getSingle(String name)
Gets a single value.protected static int
initialCapacity(int size)
boolean
isEmpty()
Checks if the state is empty.String[]
keyArray()
Gets an array of keys.Set<String>
keySet()
Gets the key set.void
put(String key, Serializable value)
Sets a key/value.protected void
putEvenIfNull(String key, Serializable value)
Serializable
remove(Object key)
Removes the mapping for a key.void
setArray(String name, Object[] value)
Sets an array value.void
setSingle(String name, Object value)
Sets a single value.int
size()
Gets the number of elements.String
toString()
Overridden to display Calendars and arrays better, and truncate long strings and arrays.protected static void
toString(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 aConcurrentHashMap
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
- iftrue
, then aConcurrentHashMap
is 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, ornull
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
-
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:StateAccessor
Gets a single value.- Specified by:
getSingle
in interfaceStateAccessor
- 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 interfaceStateAccessor
- 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 interfaceStateAccessor
- Parameters:
name
- the namevalue
- the value
-
setArray
public void setArray(String name, Object[] value)
Description copied from interface:StateAccessor
Sets an array value.- Specified by:
setArray
in interfaceStateAccessor
- Parameters:
name
- the namevalue
- the value
-
-