Data

class 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 types

A builder for Data objects.

Constants

const Int

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

Public companion functions

Data

Converts a byte array to Data.

Public companion properties

Data

An empty Data object with no elements.

Public constructors

Data(other: Data)

Copy constructor

Public functions

open operator Boolean
equals(other: Any?)
Boolean
getBoolean(key: String, defaultValue: Boolean)

Gets the boolean value for the given key.

BooleanArray?

Gets the boolean array value for the given key.

Byte
getByte(key: String, defaultValue: Byte)

Gets the byte value for the given key.

ByteArray?

Gets the byte array value for the given key.

Double
getDouble(key: String, defaultValue: Double)

Gets the double value for the given key.

DoubleArray?

Gets the double array value for the given key.

Float
getFloat(key: String, defaultValue: Float)

Gets the float value for the given key.

FloatArray?

Gets the float array value for the given key.

Int
getInt(key: String, defaultValue: Int)

Gets the integer value for the given key.

IntArray?

Gets the integer array value for the given key.

Long
getLong(key: String, defaultValue: Long)

Gets the long value for the given key.

LongArray?

Gets the long array value for the given key.

String?

Gets the String value for the given key.

Array<String>?

Gets the String array value for the given key.

Boolean
<T : Any?> hasKeyWithValueOfType(key: String, klass: Class<T>)

Returns true if the instance of Data has a non-null value corresponding to the given String key with the expected type of T.

open Int
ByteArray

Converts this Data to a byte array suitable for sending to other processes in your application.

open String

Public properties

Map<StringAny?>

Extension functions

inline Boolean

Returns true if the instance of Data has a value corresponding to the given key with an expected type T.

Constants

MAX_DATA_BYTES

const val MAX_DATA_BYTESInt

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.

Public companion functions

fromByteArray

@TypeConverter
fun fromByteArray(bytes: ByteArray): Data

Converts a byte array to Data.

Parameters
bytes: ByteArray

The byte array representation to convert

Returns
Data

An Data object built from the input

Throws
kotlin.IllegalStateException

if bytes is bigger than .MAX_DATA_BYTES

Public companion properties

EMPTY

val EMPTYData

An empty Data object with no elements.

Public constructors

Data

Added in 1.0.0
Data(other: Data)

Copy constructor

Public functions

equals

open operator fun equals(other: Any?): Boolean

getBoolean

Added in 1.0.0
fun getBoolean(key: String, defaultValue: Boolean): Boolean

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

Added in 1.0.0
fun getBooleanArray(key: String): BooleanArray?

Gets the boolean array value for the given key.

Parameters
key: String

The key for the argument

Returns
BooleanArray?

The value specified by the key if it exists; null otherwise

getByte

Added in 2.1.0
fun getByte(key: String, defaultValue: Byte): Byte

Gets the byte value for the given key.

Parameters
key: String

The key for the argument

defaultValue: Byte

The default value to return if the key is not found

Returns
Byte

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

getByteArray

Added in 2.1.0
fun getByteArray(key: String): ByteArray?

Gets the byte array value for the given key.

Parameters
key: String

The key for the argument

Returns
ByteArray?

The value specified by the key if it exists; null otherwise

getDouble

Added in 1.0.0
fun getDouble(key: String, defaultValue: Double): Double

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

Added in 1.0.0
fun getDoubleArray(key: String): DoubleArray?

Gets the double array value for the given key.

Parameters
key: String

The key for the argument

Returns
DoubleArray?

The value specified by the key if it exists; null otherwise

getFloat

Added in 1.0.0
fun getFloat(key: String, defaultValue: Float): Float

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

Added in 1.0.0
fun getFloatArray(key: String): FloatArray?

Gets the float array value for the given key.

Parameters
key: String

The key for the argument

Returns
FloatArray?

The value specified by the key if it exists; null otherwise

getInt

Added in 1.0.0
fun getInt(key: String, defaultValue: Int): Int

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

Added in 1.0.0
fun getIntArray(key: String): IntArray?

Gets the integer array value for the given key.

Parameters
key: String

The key for the argument

Returns
IntArray?

The value specified by the key if it exists; null otherwise

getLong

Added in 1.0.0
fun getLong(key: String, defaultValue: Long): Long

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

Added in 1.0.0
fun getLongArray(key: String): LongArray?

Gets the long array value for the given key.

Parameters
key: String

The key for the argument

Returns
LongArray?

The value specified by the key if it exists; null otherwise

getString

Added in 1.0.0
fun getString(key: String): String?

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; null otherwise

getStringArray

Added in 1.0.0
fun getStringArray(key: String): Array<String>?

Gets the String array value for the given key.

Parameters
key: String

The key for the argument

Returns
Array<String>?

The value specified by the key if it exists; null otherwise

hasKeyWithValueOfType

Added in 2.3.0
fun <T : Any?> hasKeyWithValueOfType(key: String, klass: Class<T>): Boolean

Returns true if the instance of Data has a non-null value corresponding to the given String key with the expected type of T.

Parameters
key: String

The String key

klass: Class<T>

The Class container for the expected type

Returns
Boolean

true If the instance of Data has a value for the given String key with the expected type.

hashCode

open fun hashCode(): Int

toByteArray

Added in 2.3.0
fun toByteArray(): ByteArray

Converts this Data to a byte array suitable for sending to other processes in your application. There are no versioning guarantees with this byte array, so you should not use this for IPCs between applications or persistence.

Returns
ByteArray

The byte array representation of the input

Throws
kotlin.IllegalStateException

if the serialized payload is bigger than .MAX_DATA_BYTES

toString

open fun toString(): String

Public properties

keyValueMap

Added in 1.0.0
val keyValueMapMap<StringAny?>

Extension functions

hasKeyWithValueOfType

inline fun <T : Any> Data.hasKeyWithValueOfType(key: String): Boolean

Returns true if the instance of Data has a value corresponding to the given key with an expected type T.