Class Item
java.lang.Object
com.amazonaws.services.dynamodbv2.document.Item
An item in DynamoDB. An item is a collection of attributes. Each attribute
has a name and a value. An attribute value can be one of the followings:
- String
- Set<String>
- Number (including any subtypes and primitive types)
- Set<Number>
- byte[]
- Set<byte[]>
- ByteBuffer
- Set<ByteBuffer>
- Boolean or boolean
- null
- Map<String,T>, where T can be any type on this list but must not induce any circular reference
- List<T>, where T can be any type on this list but must not induce any circular reference
Item to be successfully persisted in DynamoDB, at a
minimum the respective attributes for the primary key must be specified.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns all attributes of the current item as a map.Returns all attributes of the current item.base64Decode(String... binaryAttrNames) Utility method to decode the designated binary attributes from base-64 encoding; converting binary lists into binary sets.convertListsToSets(String... listAttrNames) Utility method to converts the designated attributes fromListintoSet, throwingIllegalArgumentExceptionshould there be duplicate elements.booleanstatic ItemConvenient factory method - instantiates anItemfrom the given JSON string.static ItemConvenient factory method - instantiates anItemfrom the given map.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.getBigInteger(String attrName) Returns the value of the specified attribute in the current item as anBigInteger; or null if the attribute doesn't exist.byte[]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.Returns the value of the specified attribute in the current item as a non-null Boolean.booleangetBoolean(String attrName) Returns the value of the specified attribute in the current item as a primitive boolean.getByteBuffer(String attrName) Returns the value of the specified attribute in the current item as aByteBuffer; or null if the attribute either doesn't exist or the attribute value is null.getByteBufferSet(String attrName) Returns the value of the specified attribute in the current item as a set ofByteBuffer; or null if the attribute either doesn't exist or the attribute value is null.doubleReturns the value of the specified attribute in the current item as adouble.floatReturns the value of the specified attribute in the current item as afloat.intReturns the value of the specified attribute in the current item as anint.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.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> Returns the value of the specified attribute in the current item as a set ofT's.; or null if the attribute either doesn't exist or the attribute value is null.longReturns the value of the specified attribute in the current item as anlong.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.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 ofNumber; or null if the attribute doesn't exist.Returns the value of the specified attribute in the current item as aBigDecimal; or null if the attribute either doesn't exist or the attribute value is null.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.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.shortReturns the value of the specified attribute in the current item as ashort.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.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<?> 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.booleanhasAttribute(String attrName) Returns true if this item has the specified attribute; false otherwise.inthashCode()booleanReturns true if the specified attribute exists with a null value; false otherwise.booleanReturns true if this item contains the specified attribute; false otherwise.intReturns the number of attributes of this item.removeAttribute(String attrName) Removes the specified attribute from the current item.toJSON()Returns this item as a JSON string.Returns this item as a pretty JSON string.toString()Sets the value of the specified attribute to the given value.withBigDecimalSet(String attrName, BigDecimal... vals) Sets the value of the specified attribute in the current item to the given value.withBigDecimalSet(String attrName, Set<BigDecimal> val) Sets the value of the specified attribute in the current item to the given value.withBigInteger(String attrName, BigInteger val) Sets the value of the specified attribute in the current item to the given value.withBinary(String attrName, byte[] val) Sets the value of the specified attribute in the current item to the given value.withBinary(String attrName, ByteBuffer val) Sets the value of the specified attribute in the current item to the given value.withBinarySet(String attrName, byte[]... vals) Sets the value of the specified attribute in the current item to the given value.withBinarySet(String attrName, ByteBuffer... vals) Sets the value of the specified attribute in the current item to the given value.withBinarySet(String attrName, Set<byte[]> val) Sets the value of the specified attribute in the current item to the given value.withBoolean(String attrName, boolean val) Sets the value of the specified attribute in the current item to the boolean value.withByteBufferSet(String attrName, Set<ByteBuffer> val) Sets the value of the specified attribute in the current item to the given value.withDouble(String attrName, double val) Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute in the current item to the given JSON document in the form of a string.withKeyComponent(String keyAttrName, Object keyAttrValue) Convenient methods - sets an attribute of this item for the specified key attribute name and value.withKeyComponents(KeyAttribute... components) Convenient methods - sets the attributes of this item from the specified key components.Sets the value of the specified attribute in the current item to the given values as a list.Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute in the current item to the given value.Sets the value of the specified attribute to null.withNumber(String attrName, Number val) Sets the value of the specified attribute in the current item to the given value.withNumber(String attrName, BigDecimal val) Sets the value of the specified attribute in the current item to the given value.withNumberSet(String attrName, Number... vals) Sets the value of the specified attribute in the current item to the given value.withNumberSet(String attrName, Set<Number> vals) Sets the value of the specified attribute in the current item to the given value.withPrimaryKey(PrimaryKey primaryKey) Convenient methods - sets the attributes of this item from the given key attributes.withPrimaryKey(String hashKeyName, Object hashKeyValue) Convenient method to set the attributes of this item from the given hash-only primary key name and value.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.Sets the value of the specified attribute in the current item to the given value.withString(String attrName, String val) Sets the value of the specified attribute in the current item to the given string value.withStringSet(String attrName, String... val) Sets the value of the specified attribute in the current item to the given value.withStringSet(String attrName, Set<String> val) Sets the value of the specified attribute in the current item to the given value.
-
Constructor Details
-
Item
public Item()
-
-
Method Details
-
isNull
Returns true if the specified attribute exists with a null value; false otherwise. -
isPresent
Returns true if this item contains the specified attribute; false otherwise. -
getString
-
withString
-
getNumber
Returns the value of the specified attribute in the current item as aBigDecimal; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
NumberFormatException- if the attribute value is not a valid representation of aBigDecimal.- See Also:
-
getBigInteger
Returns the value of the specified attribute in the current item as anBigInteger; or null if the attribute doesn't exist.- Throws:
NumberFormatException- if the attribute value is null or not a valid representation of aBigDecimal.- See Also:
-
getShort
Returns the value of the specified attribute in the current item as ashort.- Throws:
NumberFormatException- if the attribute value is null or not a valid representation of aBigDecimal.- See Also:
-
getInt
Returns the value of the specified attribute in the current item as anint.- Throws:
NumberFormatException- if the attribute value is null or not a valid representation of aBigDecimal.- See Also:
-
getLong
Returns the value of the specified attribute in the current item as anlong.- Throws:
NumberFormatException- if the attribute value is null or not a valid representation of aBigDecimal.- See Also:
-
getFloat
Returns the value of the specified attribute in the current item as afloat.- Throws:
NumberFormatException- if the attribute value is null or not a valid representation of aBigDecimal.- See Also:
-
getDouble
Returns the value of the specified attribute in the current item as adouble.- Throws:
NumberFormatException- if the attribute value is null or not a valid representation of aBigDecimal.- See Also:
-
withNumber
Sets the value of the specified attribute in the current item to the given value. -
withNumber
-
withInt
-
withBigInteger
Sets the value of the specified attribute in the current item to the given value. -
withShort
-
withFloat
-
withDouble
-
withLong
-
getBinary
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.- Throws:
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- See Also:
-
getByteBuffer
Returns the value of the specified attribute in the current item as aByteBuffer; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
IncompatibleTypeException- if the attribute value cannot be converted into a byte array- See Also:
-
withBinary
-
withBinary
Sets the value of the specified attribute in the current item to the given value. -
getStringSet
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.- Throws:
IncompatibleTypeException- if the attribute value cannot be converted into a set of strings because of duplicate elements- See Also:
-
withStringSet
-
withStringSet
-
getNumberSet
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.- Throws:
NumberFormatException- if the attribute involves a value that is not a valid representation of aBigDecimal.IncompatibleTypeException- if the attribute value cannot be converted into a set ofBigDecimal's because of duplicate elements- See Also:
-
withBigDecimalSet
Sets the value of the specified attribute in the current item to the given value. -
withBigDecimalSet
Sets the value of the specified attribute in the current item to the given value. -
withNumberSet
-
withNumberSet
-
getBinarySet
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.- Throws:
IncompatibleTypeException- if the attribute value cannot be converted into a set of byte arrays- See Also:
-
getByteBufferSet
Returns the value of the specified attribute in the current item as a set ofByteBuffer; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
IncompatibleTypeException- if the attribute value cannot be converted into a set ofByteBuffer- See Also:
-
withBinarySet
-
withByteBufferSet
Sets the value of the specified attribute in the current item to the given value. -
withBinarySet
-
withBinarySet
Sets the value of the specified attribute in the current item to the given value. -
getList
Returns the value of the specified attribute in the current item as a set ofT's.; or null if the attribute either doesn't exist or the attribute value is null.- Throws:
ClassCastException- if the attribute involves a value that cannot be casted toT- See Also:
-
withList
-
withList
-
getMap
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. Note that any numeric type of a map is always canonicalized intoBigDecimal, and therefore ifTreferred to aNumbertype, it would need to beBigDecimalto avoid a class cast exception.- Throws:
ClassCastException- if the attribute is not a map of string toT- See Also:
-
getMapOfNumbers
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 ofNumber; or null if the attribute doesn't exist.- Parameters:
attrName- the attribute namevalueType- the specific number type of the value to be returned. Currently, onlyShortIntegerLongFloatDoubleNumberBigDecimalBigInteger
- Throws:
UnsupportedOperationException- if the value type is not supportedClassCastException- if the attribute is not a map of string to numbers
-
getRawMap
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. Note that any numeric type of the map will be returned asBigDecimal.- Throws:
ClassCastException- if the attribute is not a map- See Also:
-
withMap
-
withJSON
-
getJSON
-
getJSONPretty
-
getBOOL
Returns the value of the specified attribute in the current item as a non-null Boolean.- Throws:
IncompatibleTypeException- if either the attribute doesn't exist or if the attribute value cannot be converted into a non-null Boolean value- See Also:
-
getBoolean
Returns the value of the specified attribute in the current item as a primitive boolean.- Throws:
IncompatibleTypeException- if either the attribute doesn't exist or if the attribute value cannot be converted into a boolean value
-
withBoolean
-
withNull
-
with
Sets the value of the specified attribute to the given value. An attribute value can be a- Number
- String
- binary (ie byte array or byte buffer)
- boolean
- null
- list (of any of the types on this list)
- map (with string key to value of any of the types on this list)
- set (of any of the types on this list)
-
withPrimaryKey
Convenient methods - sets the attributes of this item from the given key attributes. -
withPrimaryKey
-
withPrimaryKey
-
withKeyComponents
Convenient methods - sets the attributes of this item from the specified key components. -
withKeyComponent
-
get
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.An attribute value can be a
- Number
- String
- binary (ie byte array or byte buffer)
- boolean
- null
- list (of any of the types on this list)
- map (with string key to value of any of the types on this list)
- set (of any of the types on this list)
- See Also:
-
getTypeOf
-
removeAttribute
-
attributes
-
hasAttribute
Returns true if this item has the specified attribute; false otherwise. -
asMap
-
numberOfAttributes
public int numberOfAttributes()Returns the number of attributes of this item. -
fromMap
-
fromJSON
-
toJSON
Returns this item as a JSON string. Note all binary data will become base-64 encoded in the resultant string. -
base64Decode
Utility method to decode the designated binary attributes from base-64 encoding; converting binary lists into binary sets.- Parameters:
binaryAttrNames- names of binary attributes or binary set attributes currently base-64 encoded (typically when converted from a JSON string.)- See Also:
-
convertListsToSets
-
toJSONPretty
Returns this item as a pretty JSON string. Note all binary data will become base-64 encoded in the resultant string. -
toString
-
hashCode
-
equals
-