public final class DataMap extends CheckedMap<java.lang.String,java.lang.Object> implements DataComplex
DataMap
maps strings to Data objects.
The key of this map is always a string. When a key is being added or replaced,
the map will verify that key is a string. If the key is not a string,
the map will throw an IllegalArgumentException
.
When an value is being added or replaced on the map, the map
will verify that the value is a Data object. If the value
is not a Data object, then the map will throw an IllegalArgumentException
.
Cloning via the clone()
method will shallow copy the DataMap
and will not deep copy contained complex objects. Copying via the copy()
method will deep copy the DataMap
, which includes deep copying the
contained complex objects. Keys are not deep copied because the keys are
immutable strings.
Instrumentation if enabled is only enabled for the DataMap
and not
for the underlying CheckedMap
. Furthermore, if a DataMap
is cloned,
the clone will not have instrumentation enabled and the clone's instrumented
data will be cleared.
Since DataMap
extends CheckedMap
, copying of the DataMap
is lazy and may be
delayed until the DataMap
is about to be modified.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ERROR_KEY |
static java.lang.String |
RESERVED_CONSTANT_PREFIX |
static java.lang.String |
RESERVED_CONSTANT_SUFFIX |
TIMES_ACCESSED, VALUE
Constructor and Description |
---|
DataMap()
Constructs an empty
DataMap . |
DataMap(int initialCapacity)
Constructs a
DataMap with the specified initial capacity and
default load factor. |
DataMap(int initialCapacity,
float loadFactor)
Constructs a
DataMap with the specified initial capacity and
load factor. |
DataMap(java.util.Map<? extends java.lang.String,? extends java.lang.Object> map)
Constructs a
DataMap with the entries provided by the input map. |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
addError(java.lang.String msg)
Adds an error message to the
DataMap . |
void |
clearInstrumentedData()
Clear tracked data.
|
DataMap |
clone()
Shallow clone.
|
void |
collectInstrumentedData(java.lang.StringBuilder keyPrefix,
java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>> instrumentedData,
boolean collectAllData)
Collect either all the data in this and contained
Instrumentable or only the keys
or indices that have been marked as accessed depending on the collectAllData flag. |
boolean |
containsKey(java.lang.Object key) |
DataMap |
copy()
Deep copy.
|
void |
copyReferencedObjects(com.linkedin.data.DataComplexTable alreadyCopied)
Deep copy this object and the complex Data objects referenced by this object.
|
int |
dataComplexHashCode()
Returns the data complex hash code of this data complex object.
|
java.lang.Object |
get(java.lang.Object key) |
java.lang.Boolean |
getBoolean(java.lang.String key)
Returns the value to which the specified key is mapped and cast to
Boolean ,
or null if this map contains no mapping for the key. |
ByteString |
getByteString(java.lang.String key)
Returns the value to which the specified key is mapped and cast to
ByteString ,
or null if this map contains no mapping for the key. |
DataList |
getDataList(java.lang.String key)
Returns the value to which the specified key is mapped and cast to
DataList ,
or null if this map contains no mapping for the key. |
DataMap |
getDataMap(java.lang.String key)
Returns the value to which the specified key is mapped and cast to
DataMap ,
or null if this map contains no mapping for the key. |
java.lang.Double |
getDouble(java.lang.String key)
Returns the value to which the specified key is mapped and cast to
Double ,
or null if this map contains no mapping for the key. |
java.lang.String |
getError()
Returns the value to which
ERROR_KEY is mapped and cast to String ,
or null if this map contains no mapping for the key. |
java.lang.Float |
getFloat(java.lang.String key)
Returns the value to which the specified key is mapped and cast to
Float ,
or null if this map contains no mapping for the key. |
java.lang.Integer |
getInteger(java.lang.String key)
Returns the value to which the specified key is mapped and cast to
Integer ,
or null if this map contains no mapping for the key. |
java.lang.Long |
getLong(java.lang.String key)
Returns the value to which the specified key is mapped and cast to
Long ,
or null if this map contains no mapping for the key. |
java.lang.String |
getString(java.lang.String key)
Returns the value to which the specified key is mapped and cast to
String ,
or null if this map contains no mapping for the key. |
boolean |
isMadeReadOnly()
Whether this object and recursively contained complex objects are read-only.
|
void |
makeReadOnly()
Make read-only this object and recursively contained complex objects.
|
static java.lang.String |
reservedConstant(java.lang.String name) |
void |
startInstrumentingAccess()
Sets the state of this
Instrumentable to start instrumenting data access. |
void |
stopInstrumentingAccess()
Sets the state of this
Instrumentable to stop instrumenting data access. |
clear, containsValue, entrySet, equals, getObject, hashCode, invalidate, isEmpty, isReadOnly, keySet, put, putAll, putAllWithoutChecking, putWithoutChecking, remove, setReadOnly, size, toString, values
finalize, getClass, notify, notifyAll, wait, wait, wait
values
invalidate, isReadOnly, setReadOnly
public static final java.lang.String RESERVED_CONSTANT_PREFIX
public static final java.lang.String RESERVED_CONSTANT_SUFFIX
public static final java.lang.String ERROR_KEY
public DataMap()
DataMap
.public DataMap(java.util.Map<? extends java.lang.String,? extends java.lang.Object> map)
DataMap
with the entries provided by the input map.map
- provides the entries of the new DataMap
.public DataMap(int initialCapacity)
DataMap
with the specified initial capacity and
default load factor.initialCapacity
- provides the initial capacity of the DataMap
.HashMap
public static java.lang.String reservedConstant(java.lang.String name)
public DataMap clone() throws java.lang.CloneNotSupportedException
Common
clone
in interface Common
clone
in interface CommonMap<java.lang.String,java.lang.Object>
clone
in interface DataComplex
clone
in class CheckedMap<java.lang.String,java.lang.Object>
java.lang.CloneNotSupportedException
- if the object cannot be shallow copied.public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map<java.lang.String,java.lang.Object>
get
in class CheckedMap<java.lang.String,java.lang.Object>
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<java.lang.String,java.lang.Object>
containsKey
in class CheckedMap<java.lang.String,java.lang.Object>
public DataMap copy() throws java.lang.CloneNotSupportedException
DataComplex
copy
in interface DataComplex
java.lang.CloneNotSupportedException
- if the object cannot be deep copied.public void copyReferencedObjects(com.linkedin.data.DataComplexTable alreadyCopied) throws java.lang.CloneNotSupportedException
alreadyCopied
- provides the objects already copied, and their copies.java.lang.CloneNotSupportedException
- if the referenced object cannot be copied.public void makeReadOnly()
DataComplex
makeReadOnly
in interface DataComplex
public boolean isMadeReadOnly()
DataComplex
isMadeReadOnly
in interface DataComplex
public java.lang.Boolean getBoolean(java.lang.String key)
Boolean
,
or null
if this map contains no mapping for the key.key
- provides the key whose associated value is to be returned.Boolean
,
or null
if this map contains no mapping for the key.public java.lang.Integer getInteger(java.lang.String key)
Integer
,
or null
if this map contains no mapping for the key.key
- provides the key whose associated value is to be returned.Integer
,
or null
if this map contains no mapping for the key.public java.lang.Long getLong(java.lang.String key)
Long
,
or null
if this map contains no mapping for the key.key
- provides the key whose associated value is to be returned.Long
,
or null
if this map contains no mapping for the key.public java.lang.Float getFloat(java.lang.String key)
Float
,
or null
if this map contains no mapping for the key.key
- provides the key whose associated value is to be returned.Float
,
or null
if this map contains no mapping for the key.public java.lang.Double getDouble(java.lang.String key)
Double
,
or null
if this map contains no mapping for the key.key
- provides the key whose associated value is to be returned.Double
,
or null
if this map contains no mapping for the key.public java.lang.String getString(java.lang.String key)
String
,
or null
if this map contains no mapping for the key.key
- provides the key whose associated value is to be returned.String
,
or null
if this map contains no mapping for the key.public ByteString getByteString(java.lang.String key)
ByteString
,
or null
if this map contains no mapping for the key.key
- provides the key whose associated value is to be returned.ByteString
,
or null
if this map contains no mapping for the key.public DataMap getDataMap(java.lang.String key)
DataMap
,
or null
if this map contains no mapping for the key.key
- provides the key whose associated value is to be returned.DataMap
,
or null
if this map contains no mapping for the key.public DataList getDataList(java.lang.String key)
DataList
,
or null
if this map contains no mapping for the key.key
- provides the key whose associated value is to be returned.DataList
,
or null
if this map contains no mapping for the key.public java.lang.String getError()
ERROR_KEY
is mapped and cast to String
,
or null
if this map contains no mapping for the key.String
,
or null
if this map contains no mapping for the key.public java.lang.String addError(java.lang.String msg)
DataMap
.
If a value is not mapped to ERROR_KEY
, bind the specified error message
to ERROR_KEY
. Otherwise, replace the value of ERROR_KEY
with
a new String
constructed by appending the specified error message to
the previous value of ERROR_KEY
.msg
- provides the error message to add.ERROR_KEY
.public void startInstrumentingAccess()
Instrumentable
Instrumentable
to start instrumenting data access.
The types of accesses that are instrumented depends on the actual concrete classes
that implement this interface. The minimum expectation is that read access via
Collection#get
, Map#get
, and Map.containsKey(Object)
are instrumented as an access.startInstrumentingAccess
in interface Instrumentable
public void stopInstrumentingAccess()
Instrumentable
Instrumentable
to stop instrumenting data access.stopInstrumentingAccess
in interface Instrumentable
public void clearInstrumentedData()
Instrumentable
clearInstrumentedData
in interface Instrumentable
public void collectInstrumentedData(java.lang.StringBuilder keyPrefix, java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.Object>> instrumentedData, boolean collectAllData)
Instrumentable
Instrumentable
or only the keys
or indices that have been marked as accessed depending on the collectAllData
flag.
The data is collected into the instrumentedData
supplied. Each entry's key in
the instrumentedData
map is the fully qualified name of the accessed key or index.
The fully qualified name is constructed by pre-pending the provided keyPrefix
and the keys and indices of antecedent objects traversed to reach this particular
key or index. Each entry's value in the instrumentedData
map is another map.
The minimum expectation is that the latter map has at least two entries,
the "value" entry holds the String representation object identified by the fully
qualified name, and the "timesAcessed" entry has the number of times the fully
qualified name has been accessed. The number of times accessed may be null
in
case it is unknown how many times the key or index was accessed due to instrumentation limitations.collectInstrumentedData
in interface Instrumentable
keyPrefix
- is the prefix to prepend to the fully qualified name of accessed keys and indices.instrumentedData
- provides the map to hold the output of the collected instrumented data, each
map entry's key is the fully qualified name of the key or index accessed, and the
map entry's value is another map that holds collected data.collectAllData
- indicates whether to collect all data in this and contained Instrumentable
or
only the keys or indices accessed.public int dataComplexHashCode()
DataComplex
dataComplexHashCode
in interface DataComplex