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 IllegalStateException
s if you try to serialize or deserialize past
this limit.
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 methods |
boolean
|
equals(Object o)
|
static
Data
|
fromByteArray(byte[] bytes)
Converts a byte array to Data .
|
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.
|
byte
|
getByte(String key, byte defaultValue)
Gets the byte value for the given key.
|
byte[]
|
getByteArray(String key)
Gets the byte 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.
|
<T>
boolean
|
hasKeyWithValueOfType(String key, Class<T> klass)
Returns true if the instance of Data has a non-null value corresponding to
the given String key with the expected type of T .
|
int
|
hashCode()
|
byte[]
|
toByteArray()
Converts this Data to a byte array suitable for sending to other processes in your
application.
|
String
|
toString()
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
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)
Public methods
equals
public boolean equals (Object o)
fromByteArray
public static Data fromByteArray (byte[] bytes)
Converts a byte array to Data
.
Parameters |
bytes |
byte : The byte array representation to convert |
Returns |
Data |
An Data object built from the input |
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
|
getByte
public byte getByte (String key,
byte defaultValue)
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
public byte[] getByteArray (String key)
Gets the byte array value for the given key.
Parameters |
key |
String : The key for the argument |
Returns |
byte[] |
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
|
hasKeyWithValueOfType
public boolean hasKeyWithValueOfType (String key,
Class<T> klass)
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 : 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
public int hashCode ()
toByteArray
public byte[] toByteArray ()
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 |
byte[] |
The byte array representation of the input |
Throws |
IllegalStateException |
if the serialized payload is bigger than
MAX_DATA_BYTES
|
toString
public String toString ()
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples/Code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2020-09-30 UTC.