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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all of the mappings from this map.booleancontainsKey(Object key) Returnstrueif this map contains a mapping for the specified key.booleancontainsValue(Object value) Returnstrueif this map contains one or more keys to the specified value.entrySet()booleanReturns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.booleangetBoolean(String key) Returns the value associated with the given key, or false if no mapping of the desired type exists for the given key.booleangetBoolean(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.byteReturns the value associated with the given key, or (byte) 0 if no mapping of the desired type exists for the given key.byteReturns 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.charReturns the value associated with the given key, or '0' if no mapping of the desired type exists for the given key.charReturns 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.doubleReturns the value associated with the given key, or 0.0 if no mapping of the desired type exists for the given key.doubleReturns 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.floatReturns the value associated with the given key, or 0.0f if no mapping of the desired type exists for the given key.floatReturns 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.intReturns the value associated with the given key, or 0 if no mapping of the desired type exists for the given key.intReturns 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.longReturns the value associated with the given key, or 0L if no mapping of the desired type exists for the given key.longReturns 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) shortReturns the value associated with the given key, or (short) 0 if no mapping of the desired type exists for the given key.shortReturns 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> TReturns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.<T> TReturns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.inthashCode()booleanisEmpty()Returnstrueif this map contains no key-value mappings.keySet()Associates the specified value with the specified key in this map.voidvoidputBoolean(String key, boolean value) Inserts a boolean value into the mapping, replacing any existing value for the given key.voidInserts a byte value into the mapping, replacing any existing value for the given key.voidputByteArray(String key, byte[] value) Inserts a byte[] value into the mapping, replacing any existing value for the given key.voidputDataSet(String key, DataSet value) Inserts a DataSet value into the mapping, replacing any existing value for the given key.voidInserts a double value into the mapping, replacing any existing value for the given key.voidputDoubleArray(String key, double[] value) Inserts a double[] value into the mapping, replacing any existing value for the given key.voidInserts a float value into the mapping, replacing any existing value for the given key.voidputFloatArray(String key, float[] value) Inserts a float[] value into the mapping, replacing any existing value for the given key.putIfAbsent(String key, Object value) voidInserts an int value into the mapping, replacing any existing value for the given key.voidputIntArray(String key, int[] value) Inserts an int[] value into the mapping, replacing any existing value for the given key.voidInserts a List value into the mapping, replacing any existing value for the given key.voidInserts a long value into the mapping, replacing any existing value for the given key.voidputLongArray(String key, long[] value) Inserts a long[] value into the mapping, replacing any existing value for the given key.voidInserts a short value into the mapping, replacing any existing value for the given key.voidputShortArray(String key, short[] value) Inserts a short[] value into the mapping, replacing any existing value for the given key.voidInserts a String value into the mapping, replacing any existing value for the given key.voidInserts 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.intsize()Returns the number of key-value mappings in this map.toString()values()voidwriteToParcel(Parcel dest, int flags) The subclass implements the method to flatten its contents by calling the methods ofParcelfor its primitive values.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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()Returnstrueif this map contains no key-value mappings. -
containsKey
Returnstrueif this map contains a mapping for the specified key. More formally, returnstrueif and only if this map contains a mapping for a keyksuch thatObjects.equals(key, k). (There can be at most one such mapping.)- Specified by:
containsKeyin interfaceMap<String,Object> - Parameters:
key- the key whose presence in this data set is to be tested- Returns:
trueif this data set contains a mapping for the specified key- Throws:
NullPointerException- if the specified key is null
-
containsValue
Returnstrueif this map contains one or more keys to the specified value. More formally, returnstrueif and only if this map contains at least one mapping to a valuevsuch thatObjects.equals(value, v). This operation requires time linear in the map size.- Specified by:
containsValuein interfaceMap<String,Object> - Parameters:
value- value whose presence in this map is to be tested- Returns:
trueif this map contains one or more keys to the specified value
-
get
Returns the value to which the specified key is mapped, ornullif this map contains no mapping for the key.More formally, if this map contains a mapping from a key
kto a valuevsuch thatObjects.equals(key, k), then this method returnsv; otherwise it returnsnull. (There can be at most one such mapping.)- Specified by:
getin 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
nullif this map contains no mapping for the key - Throws:
NullPointerException- if the specified key is null
-
getOrDefault
- Specified by:
getOrDefaultin interfaceMap<String,Object>
-
putIfAbsent
- Specified by:
putIfAbsentin interfaceMap<String,Object>
-
getValue
Returns the value to which the specified key is mapped, ornullif 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
nullif this map contains no mapping for the key
-
getValue
Returns the value to which the specified key is mapped, ornullif 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
nullif 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
nullif 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:ParcelableThe subclass implements the method to flatten its contents by calling the methods ofParcelfor its primitive values.- Specified by:
writeToParcelin 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
-