Class DataSet
- All Implemented Interfaces:
Parcelable
,Map<String,
Object>
String
and UUID
values). The specified data types
can safely be persisted to and restored from local storage and network in binary
form. Unsupported I/O data types can also be put into the data set for in-memory
operations, and they will be silently ignored during I/O.
A DataSet object can be put into other data sets (exclude itself) to construct a
tree structure. Additionally, an array structure (exposed in List
)
is also supported, where elements are backed by ArrayList
.
The implementation of this class is a linked hash map, which is fast and small-footprint.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface icyllis.modernui.util.Parcelable
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>, Parcelable.WriteFlags
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all of the mappings from this map.boolean
containsKey
(Object key) Returnstrue
if this map contains a mapping for the specified key.boolean
containsValue
(Object value) Returnstrue
if this map contains one or more keys to the specified value.entrySet()
boolean
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.boolean
getBoolean
(String key) Returns the value associated with the given key, or false if no mapping of the desired type exists for the given key.boolean
getBoolean
(String key, boolean defaultValue) Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.byte
Returns the value associated with the given key, or (byte) 0 if no mapping of the desired type exists for the given key.byte
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.byte[]
getByteArray
(String key) Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.char
Returns the value associated with the given key, or '0' if no mapping of the desired type exists for the given key.char
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.getDataSet
(String key) Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.double
Returns the value associated with the given key, or 0.0 if no mapping of the desired type exists for the given key.double
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.double[]
getDoubleArray
(String key) Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.float
Returns the value associated with the given key, or 0.0f if no mapping of the desired type exists for the given key.float
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.float[]
getFloatArray
(String key) Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.int
Returns the value associated with the given key, or 0 if no mapping of the desired type exists for the given key.int
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.int[]
getIntArray
(String key) Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.<T> List
<T> Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.long
Returns the value associated with the given key, or 0L if no mapping of the desired type exists for the given key.long
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.long[]
getLongArray
(String key) Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.getOrDefault
(Object key, Object defaultValue) short
Returns the value associated with the given key, or (short) 0 if no mapping of the desired type exists for the given key.short
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.short[]
getShortArray
(String key) Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.<T> T
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.<T> T
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.int
hashCode()
boolean
isEmpty()
Returnstrue
if this map contains no key-value mappings.keySet()
Associates the specified value with the specified key in this map.void
void
putBoolean
(String key, boolean value) Inserts a boolean value into the mapping, replacing any existing value for the given key.void
Inserts a byte value into the mapping, replacing any existing value for the given key.void
putByteArray
(String key, byte[] value) Inserts a byte[] value into the mapping, replacing any existing value for the given key.void
putDataSet
(String key, DataSet value) Inserts a DataSet value into the mapping, replacing any existing value for the given key.void
Inserts a double value into the mapping, replacing any existing value for the given key.void
putDoubleArray
(String key, double[] value) Inserts a double[] value into the mapping, replacing any existing value for the given key.void
Inserts a float value into the mapping, replacing any existing value for the given key.void
putFloatArray
(String key, float[] value) Inserts a float[] value into the mapping, replacing any existing value for the given key.putIfAbsent
(String key, Object value) void
Inserts an int value into the mapping, replacing any existing value for the given key.void
putIntArray
(String key, int[] value) Inserts an int[] value into the mapping, replacing any existing value for the given key.void
Inserts a List value into the mapping, replacing any existing value for the given key.void
Inserts a long value into the mapping, replacing any existing value for the given key.void
putLongArray
(String key, long[] value) Inserts a long[] value into the mapping, replacing any existing value for the given key.void
Inserts a short value into the mapping, replacing any existing value for the given key.void
putShortArray
(String key, short[] value) Inserts a short[] value into the mapping, replacing any existing value for the given key.void
Inserts a String value into the mapping, replacing any existing value for the given key.void
Inserts a UUID value into the mapping, replacing any existing value for the given key.Removes the mapping for a key from this map if it is present.Removes the mapping associated with the first key in iteration order.Removes the mapping associated with the last key in iteration order.int
size()
Returns the number of key-value mappings in this map.toString()
values()
void
writeToParcel
(Parcel dest, int flags) The subclass implements the method to flatten its contents by calling the methods ofParcel
for its primitive values.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, merge, remove, replace, replace, replaceAll
-
Field Details
-
CREATOR
-
-
Constructor Details
-
DataSet
public DataSet()Creates a new, empty DataSet.
-
-
Method Details
-
size
public int size()Returns the number of key-value mappings in this map. -
isEmpty
public boolean isEmpty()Returnstrue
if this map contains no key-value mappings. -
containsKey
Returnstrue
if this map contains a mapping for the specified key. More formally, returnstrue
if and only if this map contains a mapping for a keyk
such thatObjects.equals(key, k)
. (There can be at most one such mapping.)- Specified by:
containsKey
in interfaceMap<String,
Object> - Parameters:
key
- the key whose presence in this data set is to be tested- Returns:
true
if this data set contains a mapping for the specified key- Throws:
NullPointerException
- if the specified key is null
-
containsValue
Returnstrue
if this map contains one or more keys to the specified value. More formally, returnstrue
if and only if this map contains at least one mapping to a valuev
such thatObjects.equals(value, v)
. This operation requires time linear in the map size.- Specified by:
containsValue
in interfaceMap<String,
Object> - Parameters:
value
- value whose presence in this map is to be tested- Returns:
true
if this map contains one or more keys to the specified value
-
get
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.More formally, if this map contains a mapping from a key
k
to a valuev
such thatObjects.equals(key, k)
, then this method returnsv
; otherwise it returnsnull
. (There can be at most one such mapping.)- Specified by:
get
in interfaceMap<String,
Object> - Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
null
if this map contains no mapping for the key - Throws:
NullPointerException
- if the specified key is null
-
getOrDefault
- Specified by:
getOrDefault
in interfaceMap<String,
Object>
-
putIfAbsent
- Specified by:
putIfAbsent
in interfaceMap<String,
Object>
-
getValue
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
null
if this map contains no mapping for the key
-
getValue
Returns the value to which the specified key is mapped, ornull
if this map contains no mapping for the key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the value to which the specified key is mapped, or
null
if this map contains no mapping for the key
-
getBoolean
Returns the value associated with the given key, or false if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the boolean value to which the specified key is mapped
-
getBoolean
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the value to return if key does not exist- Returns:
- the boolean value to which the specified key is mapped
-
getByte
Returns the value associated with the given key, or (byte) 0 if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the byte value to which the specified key is mapped
-
getByte
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the value to return if key does not exist- Returns:
- the byte value to which the specified key is mapped
-
getChar
Returns the value associated with the given key, or '0' if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the char value to which the specified key is mapped
-
getChar
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the value to return if key does not exist- Returns:
- the char value to which the specified key is mapped
-
getShort
Returns the value associated with the given key, or (short) 0 if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the short value to which the specified key is mapped
-
getShort
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the value to return if key does not exist- Returns:
- the short value to which the specified key is mapped
-
getInt
Returns the value associated with the given key, or 0 if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the int value to which the specified key is mapped
-
getInt
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the value to return if key does not exist- Returns:
- the int value to which the specified key is mapped
-
getLong
Returns the value associated with the given key, or 0L if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the long value to which the specified key is mapped
-
getLong
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the value to return if key does not exist- Returns:
- the long value to which the specified key is mapped
-
getFloat
Returns the value associated with the given key, or 0.0f if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the float value to which the specified key is mapped
-
getFloat
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the value to return if key does not exist- Returns:
- the float value to which the specified key is mapped
-
getDouble
Returns the value associated with the given key, or 0.0 if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the double value to which the specified key is mapped
-
getDouble
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key. Significantly, any numbers found with the key can be returned.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the value to return if key does not exist- Returns:
- the double value to which the specified key is mapped
-
getByteArray
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the byte[] value to which the specified key is mapped, or null
-
getShortArray
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the short[] value to which the specified key is mapped, or null
-
getIntArray
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the int[] value to which the specified key is mapped, or null
-
getLongArray
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the long[] value to which the specified key is mapped, or null
-
getFloatArray
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the float[] value to which the specified key is mapped, or null
-
getDoubleArray
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the double[] value to which the specified key is mapped, or null
-
getString
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the String value to which the specified key is mapped, or null
-
getString
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the value to return if key does not exist or if a null value is associated with the given key.- Returns:
- the String value associated with the given key, or defaultValue if no valid String object is currently mapped to that key.
-
getUUID
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the UUID value to which the specified key is mapped, or null
-
getUUID
Returns the value associated with the given key, or defaultValue if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returneddefaultValue
- the value to return if key does not exist or if a null value is associated with the given key.- Returns:
- the UUID value associated with the given key, or defaultValue if no valid UUID object is currently mapped to that key.
-
getList
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.Note that if the list elements are primitive types, you should use the methods which are specified by primitive types.
- Type Parameters:
T
- the element type- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the List value to which the specified key is mapped, or null
-
getDataSet
Returns the value associated with the given key, or null if no mapping of the desired type exists for the given key.- Parameters:
key
- the key whose associated value is to be returned- Returns:
- the DataSet value to which the specified key is mapped, or null
-
put
Associates the specified value with the specified key in this map.
If the map previously contained a mapping for the key, the old value is replaced by the specified value. -
putByte
Inserts a byte value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the byte value to be associated with the specified key
-
putShort
Inserts a short value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the short value to be associated with the specified key
-
putInt
Inserts an int value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the int value to be associated with the specified key
-
putLong
Inserts a long value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the long value to be associated with the specified key
-
putFloat
Inserts a float value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the float value to be associated with the specified key
-
putDouble
Inserts a double value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the double value to be associated with the specified key
-
putBoolean
Inserts a boolean value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the boolean value to be associated with the specified key
-
putString
Inserts a String value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the String value to be associated with the specified key
-
putUUID
Inserts a UUID value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the UUID value to be associated with the specified key
-
putList
Inserts a List value into the mapping, replacing any existing value for the given key.The list value type must be the same and supported by DataSets. Significantly, the list can be nested list or a list of nodes.
Note that if the list elements are primitive types, you should use the methods which are specified by primitive types.
- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the List value to be associated with the specified key
-
putDataSet
Inserts a DataSet value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the DataSet value to be associated with the specified key
-
putByteArray
Inserts a byte[] value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the byte[] value to be associated with the specified key
-
putShortArray
Inserts a short[] value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the short[] value to be associated with the specified key
-
putIntArray
Inserts an int[] value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the int[] value to be associated with the specified key
-
putLongArray
Inserts a long[] value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the long[] value to be associated with the specified key
-
putFloatArray
Inserts a float[] value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the float[] value to be associated with the specified key
-
putDoubleArray
Inserts a double[] value into the mapping, replacing any existing value for the given key.- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the double[] value to be associated with the specified key
-
remove
Removes the mapping for a key from this map if it is present.Returns the value to which this map previously associated the key, or
null
if the map contained no mapping for the key.The map will not contain a mapping for the specified key once the call returns.
-
removeFirst
Removes the mapping associated with the first key in iteration order.- Returns:
- the value previously associated with the first key in iteration order.
- Throws:
NoSuchElementException
- is this map is empty.
-
removeLast
Removes the mapping associated with the last key in iteration order.- Returns:
- the value previously associated with the last key in iteration order.
- Throws:
NoSuchElementException
- is this map is empty.
-
putAll
-
clear
public void clear()Removes all of the mappings from this map. The map will be empty after this call returns. -
keySet
-
values
-
entrySet
-
writeToParcel
Description copied from interface:Parcelable
The subclass implements the method to flatten its contents by calling the methods ofParcel
for its primitive values.- Specified by:
writeToParcel
in interfaceParcelable
- Parameters:
dest
- the parcel to write the object's data toflags
- the flags about how the object should be written
-
hashCode
public int hashCode() -
equals
-
toString
-