Data

public final class Data
extends Object

java.lang.Object
   ↳ androidx.work.Data


A persistable set of key/value pairs which are used as inputs and outputs for ListenableWorkers. Keys are Strings, and values can be Strings, primitive types, or their array variants.

This is a lightweight container, and should not be considered your data store. As such, there is an enforced MAX_DATA_BYTES limit on the serialized (byte array) size of the payloads. This class will throw IllegalStateExceptions if you try to serialize or deserialize past this limit.

Summary

Nested classes

class Data.Builder

A builder for Data objects. 

Constants

int MAX_DATA_BYTES

The maximum number of bytes for Data when it is serialized (converted to a byte array).

Fields

public static final Data EMPTY

An empty Data object with no elements.

Public constructors

Data(Data other)

Public methods

boolean equals(Object o)
boolean getBoolean(String key, boolean defaultValue)

Gets the boolean value for the given key.

boolean[] getBooleanArray(String key)

Gets the boolean array value for the given key.

double getDouble(String key, double defaultValue)

Gets the double value for the given key.

double[] getDoubleArray(String key)

Gets the double array value for the given key.

float getFloat(String key, float defaultValue)

Gets the float value for the given key.

float[] getFloatArray(String key)

Gets the float array value for the given key.

int getInt(String key, int defaultValue)

Gets the integer value for the given key.

int[] getIntArray(String key)

Gets the integer array value for the given key.

Map<String, Object> getKeyValueMap()

Gets all the values in this Data object.

long getLong(String key, long defaultValue)

Gets the long value for the given key.

long[] getLongArray(String key)

Gets the long array value for the given key.

String getString(String key)

Gets the String value for the given key.

String[] getStringArray(String key)

Gets the String array value for the given key.

int hashCode()

Inherited methods

Constants

MAX_DATA_BYTES

public static final int MAX_DATA_BYTES

The maximum number of bytes for Data when it is serialized (converted to a byte array). Please see the class-level Javadoc for more information.

Constant Value: 10240 (0x00002800)

Fields

EMPTY

public static final Data EMPTY

An empty Data object with no elements.

Public constructors

Data

public Data (Data other)

Parameters
other Data

Public methods

equals

public boolean equals (Object o)

Parameters
o Object

Returns
boolean

getBoolean

public boolean getBoolean (String key, 
                boolean defaultValue)

Gets the boolean value for the given key.

Parameters
key String: The key for the argument

defaultValue boolean: The default value to return if the key is not found

Returns
boolean The value specified by the key if it exists; the default value otherwise

getBooleanArray

public boolean[] getBooleanArray (String key)

Gets the boolean array value for the given key.

Parameters
key String: The key for the argument

Returns
boolean[] The value specified by the key if it exists; null otherwise

getDouble

public double getDouble (String key, 
                double defaultValue)

Gets the double value for the given key.

Parameters
key String: The key for the argument

defaultValue double: The default value to return if the key is not found

Returns
double The value specified by the key if it exists; the default value otherwise

getDoubleArray

public double[] getDoubleArray (String key)

Gets the double array value for the given key.

Parameters
key String: The key for the argument

Returns
double[] The value specified by the key if it exists; null otherwise

getFloat

public float getFloat (String key, 
                float defaultValue)

Gets the float value for the given key.

Parameters
key String: The key for the argument

defaultValue float: The default value to return if the key is not found

Returns
float The value specified by the key if it exists; the default value otherwise

getFloatArray

public float[] getFloatArray (String key)

Gets the float array value for the given key.

Parameters
key String: The key for the argument

Returns
float[] The value specified by the key if it exists; null otherwise

getInt

public int getInt (String key, 
                int defaultValue)

Gets the integer value for the given key.

Parameters
key String: The key for the argument

defaultValue int: The default value to return if the key is not found

Returns
int The value specified by the key if it exists; the default value otherwise

getIntArray

public int[] getIntArray (String key)

Gets the integer array value for the given key.

Parameters
key String: The key for the argument

Returns
int[] The value specified by the key if it exists; null otherwise

getKeyValueMap

public Map<String, Object> getKeyValueMap ()

Gets all the values in this Data object.

Returns
Map<String, Object> A Map of key-value pairs for this object; this Map is unmodifiable and should be used for reads only.

getLong

public long getLong (String key, 
                long defaultValue)

Gets the long value for the given key.

Parameters
key String: The key for the argument

defaultValue long: The default value to return if the key is not found

Returns
long The value specified by the key if it exists; the default value otherwise

getLongArray

public long[] getLongArray (String key)

Gets the long array value for the given key.

Parameters
key String: The key for the argument

Returns
long[] The value specified by the key if it exists; null otherwise

getString

public String getString (String key)

Gets the String value for the given key.

Parameters
key String: The key for the argument

Returns
String The value specified by the key if it exists; the default value otherwise

getStringArray

public String[] getStringArray (String key)

Gets the String array value for the given key.

Parameters
key String: The key for the argument

Returns
String[] The value specified by the key if it exists; null otherwise

hashCode

public int hashCode ()

Returns
int