public class Item extends Object
Item
to be successfully persisted in DynamoDB, at a
minimum the respective attributes for the primary key must be specified.Constructor and Description |
---|
Item() |
Modifier and Type | Method and Description |
---|---|
Map<String,Object> |
asMap()
Returns all attributes of the current item as a map.
|
Iterable<Map.Entry<String,Object>> |
attributes()
Returns all attributes of the current item.
|
Item |
base64Decode(String... binaryAttrNames)
Utility method to decode the designated binary attributes from base-64
encoding; converting binary lists into binary sets.
|
Item |
convertListsToSets(String... listAttrNames)
Utility method to converts the designated attributes from
List into Set , throwing
IllegalArgumentException should there be duplicate elements. |
boolean |
equals(Object in) |
static Item |
fromJSON(String json)
Convenient factory method - instantiates an
Item from the
given JSON string. |
static Item |
fromMap(Map<String,Object> attributes)
Convenient factory method - instantiates an
Item from the
given map. |
Object |
get(String attrName)
Returns the value of the specified attribute in the current item as an
object; or null if the attribute either doesn't exist or the attribute
value is null.
|
BigInteger |
getBigInteger(String attrName)
Returns the value of the specified attribute in the current item as an
BigInteger ; or null if the attribute doesn't exist. |
byte[] |
getBinary(String attrName)
Returns the value of the specified attribute in the current item as a
byte array; or null if the attribute either doesn't exist or the
attribute value is null.
|
Set<byte[]> |
getBinarySet(String attrName)
Returns the value of the specified attribute in the current item as a set
of byte arrays; or null if the attribute either doesn't exist or the
attribute value is null.
|
Boolean |
getBOOL(String attrName)
Returns the value of the specified attribute in the current item as a
non-null Boolean.
|
boolean |
getBoolean(String attrName)
Returns the value of the specified attribute in the current item as a
primitive boolean.
|
ByteBuffer |
getByteBuffer(String attrName)
Returns the value of the specified attribute in the current item as a
ByteBuffer ; or null if the attribute either doesn't exist or
the attribute value is null. |
Set<ByteBuffer> |
getByteBufferSet(String attrName)
Returns the value of the specified attribute in the current item as a set
of
ByteBuffer ; or null if the attribute either doesn't exist
or the attribute value is null. |
double |
getDouble(String attrName)
Returns the value of the specified attribute in the current item as a
double . |
float |
getFloat(String attrName)
Returns the value of the specified attribute in the current item as a
float . |
int |
getInt(String attrName)
Returns the value of the specified attribute in the current item as an
int . |
String |
getJSON(String attrName)
Returns the value of the specified attribute in the current item as a
JSON string; or null if the attribute either doesn't
exist or the attribute value is null.
|
String |
getJSONPretty(String attrName)
Returns the value of the specified attribute in the current item as a
JSON string with pretty indentation; or null if the attribute either
doesn't exist or the attribute value is null.
|
<T> List<T> |
getList(String attrName)
Returns the value of the specified attribute in the current item as a set
of
T 's.; or null if the attribute either doesn't exist or
the attribute value is null. |
long |
getLong(String attrName)
Returns the value of the specified attribute in the current item as an
long . |
<T> Map<String,T> |
getMap(String attrName)
Returns the value of the specified attribute in the current item as a map
of string-to-
T 's; or null if the attribute either doesn't
exist or the attribute value is null. |
<T extends Number> |
getMapOfNumbers(String attrName,
Class<T> valueType)
Convenient method to return the specified attribute in the current item
as a (copy of) map of string-to-
T 's where T must be a
subclass of Number ; or null if the attribute doesn't
exist. |
BigDecimal |
getNumber(String attrName)
Returns the value of the specified attribute in the current item as a
BigDecimal ; or null if the attribute either doesn't exist or
the attribute value is null. |
Set<BigDecimal> |
getNumberSet(String attrName)
Returns the value of the specified attribute in the current item as a set
of BigDecimal's; or null if the attribute either doesn't exist or the
attribute value is null.
|
Map<String,Object> |
getRawMap(String attrName)
Convenient method to return the value of the specified attribute in the
current item as a map of string-to-
Object 's; or null if the
attribute either doesn't exist or the attribute value is null. |
short |
getShort(String attrName)
Returns the value of the specified attribute in the current item as a
short . |
String |
getString(String attrName)
Returns the value of the specified attribute in the current item as a
string; or null if the attribute either doesn't exist or the attribute
value is null.
|
Set<String> |
getStringSet(String attrName)
Returns the value of the specified attribute in the current item as a set
of strings; or null if the attribute either doesn't exist or the
attribute value is null.
|
Class<?> |
getTypeOf(String attrName)
Returns the type of the specified attribute in the current item; or null
if the attribute either doesn't exist or the attribute value is null.
|
boolean |
hasAttribute(String attrName)
Returns true if this item has the specified attribute; false otherwise.
|
int |
hashCode() |
boolean |
isNull(String attrName)
Returns true if the specified attribute exists with a null value; false
otherwise.
|
boolean |
isPresent(String attrName)
Returns true if this item contains the specified attribute; false
otherwise.
|
int |
numberOfAttributes()
Returns the number of attributes of this item.
|
Item |
removeAttribute(String attrName)
Removes the specified attribute from the current item.
|
String |
toJSON()
Returns this item as a JSON string.
|
String |
toJSONPretty()
Returns this item as a pretty JSON string.
|
String |
toString() |
Item |
with(String attrName,
Object val)
Sets the value of the specified attribute to the given value.
|
Item |
withBigDecimalSet(String attrName,
BigDecimal... vals)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withBigDecimalSet(String attrName,
Set<BigDecimal> val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withBigInteger(String attrName,
BigInteger val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withBinary(String attrName,
byte[] val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withBinary(String attrName,
ByteBuffer val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withBinarySet(String attrName,
byte[]... vals)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withBinarySet(String attrName,
ByteBuffer... vals)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withBinarySet(String attrName,
Set<byte[]> val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withBoolean(String attrName,
boolean val)
Sets the value of the specified attribute in the current item to the
boolean value.
|
Item |
withByteBufferSet(String attrName,
Set<ByteBuffer> val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withDouble(String attrName,
double val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withFloat(String attrName,
float val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withInt(String attrName,
int val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withJSON(String attrName,
String json)
Sets the value of the specified attribute in the current item to the
given JSON document in the form of a string.
|
Item |
withKeyComponent(String keyAttrName,
Object keyAttrValue)
Convenient methods - sets an attribute of this item for the specified
key attribute name and value.
|
Item |
withKeyComponents(KeyAttribute... components)
Convenient methods - sets the attributes of this item from the specified
key components.
|
Item |
withList(String attrName,
List<?> val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withList(String attrName,
Object... vals)
Sets the value of the specified attribute in the current item to the
given values as a list.
|
Item |
withLong(String attrName,
long val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withMap(String attrName,
Map<String,?> val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withNull(String attrName)
Sets the value of the specified attribute to null.
|
Item |
withNumber(String attrName,
BigDecimal val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withNumber(String attrName,
Number val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withNumberSet(String attrName,
Number... vals)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withNumberSet(String attrName,
Set<Number> vals)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withPrimaryKey(PrimaryKey primaryKey)
Convenient methods - sets the attributes of this item from the given
key attributes.
|
Item |
withPrimaryKey(String hashKeyName,
Object hashKeyValue)
Convenient method to set the attributes of this item from the given
hash-only primary key name and value.
|
Item |
withPrimaryKey(String hashKeyName,
Object hashKeyValue,
String rangeKeyName,
Object rangeKeyValue)
Convenient method to set the attributes of this item from the given
hash and range primary key.
|
Item |
withShort(String attrName,
short val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withString(String attrName,
String val)
Sets the value of the specified attribute in the current item to the
given string value.
|
Item |
withStringSet(String attrName,
Set<String> val)
Sets the value of the specified attribute in the current item to the
given value.
|
Item |
withStringSet(String attrName,
String... val)
Sets the value of the specified attribute in the current item to the
given value.
|
public boolean isNull(String attrName)
public boolean isPresent(String attrName)
public String getString(String attrName)
public Item withString(String attrName, String val)
public BigDecimal getNumber(String attrName)
BigDecimal
; or null if the attribute either doesn't exist or
the attribute value is null.NumberFormatException
- if the attribute value is not a valid
representation of a BigDecimal
.#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public BigInteger getBigInteger(String attrName)
BigInteger
; or null if the attribute doesn't exist.NumberFormatException
- if the attribute value is null or not a valid representation
of a BigDecimal
.#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public short getShort(String attrName)
short
.NumberFormatException
- if the attribute value is null or not a valid representation
of a BigDecimal
.#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public int getInt(String attrName)
int
.NumberFormatException
- if the attribute value is null or not a valid representation
of a BigDecimal
.#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public long getLong(String attrName)
long
.NumberFormatException
- if the attribute value is null or not a valid representation
of a BigDecimal
.#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public float getFloat(String attrName)
float
.NumberFormatException
- if the attribute value is null or not a valid representation
of a BigDecimal
.#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public double getDouble(String attrName)
double
.NumberFormatException
- if the attribute value is null or not a valid representation
of a BigDecimal
.#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public Item withNumber(String attrName, BigDecimal val)
public Item withNumber(String attrName, Number val)
public Item withInt(String attrName, int val)
public Item withBigInteger(String attrName, BigInteger val)
public Item withShort(String attrName, short val)
public Item withFloat(String attrName, float val)
public Item withDouble(String attrName, double val)
public Item withLong(String attrName, long val)
public byte[] getBinary(String attrName)
UnsupportedOperationException
- If the attribute value involves a byte buffer which is not
backed by an accessible arrayIncompatibleTypeException
- if the attribute value cannot be converted into a byte array#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public ByteBuffer getByteBuffer(String attrName)
ByteBuffer
; or null if the attribute either doesn't exist or
the attribute value is null.IncompatibleTypeException
- if the attribute value cannot be converted into a byte array#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public Item withBinary(String attrName, byte[] val)
public Item withBinary(String attrName, ByteBuffer val)
public Set<String> getStringSet(String attrName)
IncompatibleTypeException
- if the attribute value cannot be converted into a set of
strings because of duplicate elements#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public Item withStringSet(String attrName, Set<String> val)
public Item withStringSet(String attrName, String... val)
public Set<BigDecimal> getNumberSet(String attrName)
NumberFormatException
- if the attribute involves a value that is not a valid
representation of a BigDecimal
.IncompatibleTypeException
- if the attribute value cannot be converted into a set of
BigDecimal
's because of duplicate elements#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public Item withBigDecimalSet(String attrName, Set<BigDecimal> val)
public Item withBigDecimalSet(String attrName, BigDecimal... vals)
public Item withNumberSet(String attrName, Number... vals)
public Item withNumberSet(String attrName, Set<Number> vals)
public Set<byte[]> getBinarySet(String attrName)
IncompatibleTypeException
- if the attribute value cannot be converted into a set of byte
arrays#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public Set<ByteBuffer> getByteBufferSet(String attrName)
ByteBuffer
; or null if the attribute either doesn't exist
or the attribute value is null.IncompatibleTypeException
- if the attribute value cannot be converted into a set of
ByteBuffer
#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public Item withBinarySet(String attrName, Set<byte[]> val)
public Item withByteBufferSet(String attrName, Set<ByteBuffer> val)
public Item withBinarySet(String attrName, byte[]... vals)
public Item withBinarySet(String attrName, ByteBuffer... vals)
public <T> List<T> getList(String attrName)
T
's.; or null if the attribute either doesn't exist or
the attribute value is null.ClassCastException
- if the attribute involves a value that cannot be casted to
T
#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public Item withList(String attrName, List<?> val)
public Item withList(String attrName, Object... vals)
public <T> Map<String,T> getMap(String attrName)
T
's; or null if the attribute either doesn't
exist or the attribute value is null. Note that any numeric type of a
map is always canonicalized into BigDecimal
, and therefore
if T
referred to a Number
type, it would need
to be BigDecimal
to avoid a class cast exception.ClassCastException
- if the attribute is not a map of string to T
#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public <T extends Number> Map<String,T> getMapOfNumbers(String attrName, Class<T> valueType)
T
's where T must be a
subclass of Number
; or null if the attribute doesn't
exist.attrName
- the attribute namevalueType
- the specific number type of the value to be returned.
Currently, onlyShort
Integer
Long
Float
Double
Number
BigDecimal
BigInteger
UnsupportedOperationException
- if the value type is not supportedClassCastException
- if the attribute is not a map of string to numberspublic Map<String,Object> getRawMap(String attrName)
Object
's; or null if the
attribute either doesn't exist or the attribute value is null. Note that
any numeric type of the map will be returned as BigDecimal
.ClassCastException
- if the attribute is not a map#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public Item withMap(String attrName, Map<String,?> val)
public Item withJSON(String attrName, String json)
public String getJSON(String attrName)
public String getJSONPretty(String attrName)
public Boolean getBOOL(String attrName)
IncompatibleTypeException
- if either the attribute doesn't exist or if the attribute
value cannot be converted into a non-null Boolean value#isNull(String) to check if the attribute value is
null.
,
#isPresent(String) to check if the attribute
value is present.
public boolean getBoolean(String attrName)
IncompatibleTypeException
- if either the attribute doesn't exist or if the attribute
value cannot be converted into a boolean valuepublic Item withBoolean(String attrName, boolean val)
public Item with(String attrName, Object val)
public Item withPrimaryKey(PrimaryKey primaryKey)
public Item withPrimaryKey(String hashKeyName, Object hashKeyValue)
public Item withPrimaryKey(String hashKeyName, Object hashKeyValue, String rangeKeyName, Object rangeKeyValue)
public Item withKeyComponents(KeyAttribute... components)
public Item withKeyComponent(String keyAttrName, Object keyAttrValue)
public Object get(String attrName)
An attribute value can be a
public Class<?> getTypeOf(String attrName)
public Item removeAttribute(String attrName)
public Iterable<Map.Entry<String,Object>> attributes()
public boolean hasAttribute(String attrName)
public int numberOfAttributes()
public static Item fromMap(Map<String,Object> attributes)
Item
from the
given map.attributes
- simple Java types; not the DyanmoDB typespublic static Item fromJSON(String json)
Item
from the
given JSON string.Item
initialized from the given JSON document;
or null if the input is null.public String toJSON()
public Item base64Decode(String... binaryAttrNames)
binaryAttrNames
- names of binary attributes or binary set attributes currently
base-64 encoded (typically when converted from a JSON string.)fromJSON(String)
public Item convertListsToSets(String... listAttrNames)
List
into Set
, throwing
IllegalArgumentException
should there be duplicate elements.listAttrNames
- names of attributes to be converted.fromJSON(String)
public String toJSONPretty()
Copyright © 2020. All rights reserved.