DataItem

Immutable data class for restricting the supported types that can be passed into the system.

The toString() method will provide a JSON friendly representation of the data enclosed. That is,

  • String data will be quoted; i.e. "my string"

  • Numeric data will not be quoted; i.e. 10 or 3.141..

  • Boolean data will not be quoted; i.e. true/false

  • DataList data will be formatted as a JSON Array; i.e. ["value", 10, true]

  • DataObject data will be formatted as a JSON Object; i.e. { "key":"value", "number":10 }

This class is currently broadly similar to the JSONObject and makes use of several methods provided by the org.json package on Android.

The any value should be restricted to only JSON supportable types - see convert.

The string parameter should only be used in the case where this value is being lazily instantiated from an already stringified representation of the value. If provided, then the string parameter will be used as the pre-computed return value from toString as well

Parameters

any

The value to be wrapped; at least this or the string value need to be provided

string

The string value representing the value of any; at least this or the string value need to be provided

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val value: Any?

Contains the underlying data value for this instance.

Functions

Link copied to clipboard
open override fun asDataItem(): DataItem

Should return an instance of a DataItem that represents all required properties of the implementing class, such that it could be:

Link copied to clipboard
Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard

Returns the contained value as an Boolean if the contained value is a Boolean.

Link copied to clipboard

Returns the contained value as an DataList if the contained value is a DataList.

Link copied to clipboard

Returns the contained value as an DataObject if the contained value is a DataObject.

Link copied to clipboard

Returns the contained value as an Double if the contained value is a Double, or a Number that can be coerced to an Double.

Link copied to clipboard
fun getInt(): Int?

Returns the contained value as an Int if the contained value is an Int, or a Number that can be coerced to an Int.

Link copied to clipboard
fun getLong(): Long?

Returns the contained value as an Long if the contained value is a Long, or a Number that can be coerced to an Long.

Link copied to clipboard

Returns the contained value as a String if the contained value is a String.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard

Indicates whether the contained value is a Boolean

Link copied to clipboard

Indicates whether the contained value is a DataList

Link copied to clipboard

Indicates whether the contained value is a DataObject

Link copied to clipboard

Indicates whether the contained value is a Double

Link copied to clipboard
fun isInt(): Boolean

Indicates whether the contained value is an Int

Link copied to clipboard

Indicates whether the contained value is a Long

Link copied to clipboard

Indicates whether the contained value is null

Link copied to clipboard

Indicates whether the contained value is a Number

Link copied to clipboard

Indicates whether the contained value is a String

Link copied to clipboard
open override fun toString(): String

Returns the String representation of the value in a JSON compliant format.