@ThreadSafe @Immutable public final class EnhancedAttributeValue extends Object
AttributeValue
.
This is a union type of the types exposed by DynamoDB, exactly as they're exposed by DynamoDB.
An instance of EnhancedAttributeValue
represents exactly one DynamoDB type, like String (s), Number (n) or Bytes (b).
This type can be determined with the type()
method or the is*
methods like isString()
or
isNumber()
. Once the type is known, the value can be extracted with as*
methods like asString()
or asNumber()
.
When converting an EnhancedAttributeValue
into a concrete Java type, it can be tedious to use the type()
or
is*
methods. For this reason, a convert(TypeConvertingVisitor)
method is provided that exposes a polymorphic
way of converting a value into another type.
An instance of EnhancedAttributeValue
is created with the from*
methods, like fromString(String)
or
fromNumber(String)
.
Modifier and Type | Method and Description |
---|---|
Boolean |
asBoolean()
Retrieve this value as a boolean.
|
SdkBytes |
asBytes()
Retrieve this value as bytes.
|
List<AttributeValue> |
asListOfAttributeValues()
Retrieve this value as a list of attribute values.
|
Map<String,AttributeValue> |
asMap()
Retrieve this value as a map.
|
String |
asNumber()
Retrieve this value as a number.
|
List<SdkBytes> |
asSetOfBytes()
Retrieve this value as a set of bytes.
|
List<String> |
asSetOfNumbers()
Retrieve this value as a set of numbers.
|
List<String> |
asSetOfStrings()
Retrieve this value as a set of strings.
|
String |
asString()
Retrieve this value as a string.
|
<T> T |
convert(TypeConvertingVisitor<T> convertingVisitor)
Apply the provided visitor to this item attribute value, converting it into a specific type.
|
boolean |
equals(Object o) |
static EnhancedAttributeValue |
fromAttributeValue(AttributeValue attributeValue)
Create an
EnhancedAttributeValue from a generated AttributeValue . |
static EnhancedAttributeValue |
fromBoolean(Boolean booleanValue)
Create an
EnhancedAttributeValue for a boolean (bool) DynamoDB type. |
static EnhancedAttributeValue |
fromBytes(SdkBytes bytesValue)
Create an
EnhancedAttributeValue for a bytes (b) DynamoDB type. |
static EnhancedAttributeValue |
fromListOfAttributeValues(AttributeValue... listOfAttributeValuesValue)
Create an
EnhancedAttributeValue for a list-of-attributes (l) DynamoDB type. |
static EnhancedAttributeValue |
fromListOfAttributeValues(List<AttributeValue> listOfAttributeValuesValue)
Create an
EnhancedAttributeValue for a list-of-attributes (l) DynamoDB type. |
static EnhancedAttributeValue |
fromMap(Map<String,AttributeValue> mapValue)
Create an
EnhancedAttributeValue for a map (m) DynamoDB type. |
static EnhancedAttributeValue |
fromNumber(String numberValue)
Create an
EnhancedAttributeValue for a number (n) DynamoDB type. |
static EnhancedAttributeValue |
fromSetOfBytes(List<SdkBytes> setOfBytesValue)
Create an
EnhancedAttributeValue for a set-of-bytes (bs) DynamoDB type. |
static EnhancedAttributeValue |
fromSetOfBytes(SdkBytes... setOfBytesValue)
Create an
EnhancedAttributeValue for a set-of-bytes (bs) DynamoDB type. |
static EnhancedAttributeValue |
fromSetOfNumbers(List<String> setOfNumbersValue)
Create an
EnhancedAttributeValue for a set-of-numbers (ns) DynamoDB type. |
static EnhancedAttributeValue |
fromSetOfNumbers(String... setOfNumbersValue)
Create an
EnhancedAttributeValue for a set-of-numbers (ns) DynamoDB type. |
static EnhancedAttributeValue |
fromSetOfStrings(List<String> setOfStringsValue)
Create an
EnhancedAttributeValue for a set-of-strings (ss) DynamoDB type. |
static EnhancedAttributeValue |
fromSetOfStrings(String... setOfStringsValue)
Create an
EnhancedAttributeValue for a set-of-strings (ss) DynamoDB type. |
static EnhancedAttributeValue |
fromString(String stringValue)
Create an
EnhancedAttributeValue for a string (s) DynamoDB type. |
int |
hashCode() |
boolean |
isBoolean()
Returns true if the underlying DynamoDB type of this value is a Boolean (bool).
|
boolean |
isBytes()
Returns true if the underlying DynamoDB type of this value is Bytes (b).
|
boolean |
isListOfAttributeValues()
Returns true if the underlying DynamoDB type of this value is a List of AttributeValues (l).
|
boolean |
isMap()
Returns true if the underlying DynamoDB type of this value is a Map (m).
|
boolean |
isNull()
Returns true if the underlying DynamoDB type of this value is Null (null).
|
boolean |
isNumber()
Returns true if the underlying DynamoDB type of this value is a Number (n).
|
boolean |
isSetOfBytes()
Returns true if the underlying DynamoDB type of this value is a Set of Bytes (bs).
|
boolean |
isSetOfNumbers()
Returns true if the underlying DynamoDB type of this value is a Set of Numbers (ns).
|
boolean |
isSetOfStrings()
Returns true if the underlying DynamoDB type of this value is a Set of Strings (ss).
|
boolean |
isString()
Returns true if the underlying DynamoDB type of this value is a String (s).
|
static EnhancedAttributeValue |
nullValue()
Create an
EnhancedAttributeValue for the null DynamoDB type. |
AttributeValue |
toAttributeValue()
Convert this
EnhancedAttributeValue into a generated AttributeValue . |
Map<String,AttributeValue> |
toAttributeValueMap()
Convert this
EnhancedAttributeValue into a generated Map<String, AttributeValue> . |
String |
toString() |
AttributeValueType |
type()
Retrieve the underlying DynamoDB type of this value, such as String (s) or Number (n).
|
public static EnhancedAttributeValue nullValue()
EnhancedAttributeValue
for the null DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().nul(true).build())
This call should never fail with an Exception
.
public static EnhancedAttributeValue fromMap(Map<String,AttributeValue> mapValue)
EnhancedAttributeValue
for a map (m) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().m(...).build())
This call will fail with a RuntimeException
if the provided map is null or has null keys.
public static EnhancedAttributeValue fromString(String stringValue)
EnhancedAttributeValue
for a string (s) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().s(...).build())
This call will fail with a RuntimeException
if the provided value is null. Use nullValue()
for
null values.
public static EnhancedAttributeValue fromNumber(String numberValue)
EnhancedAttributeValue
for a number (n) DynamoDB type.
This is a String, because it matches the underlying DynamoDB representation.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().n(...).build())
This call will fail with a RuntimeException
if the provided value is null. Use nullValue()
for
null values.
public static EnhancedAttributeValue fromBytes(SdkBytes bytesValue)
EnhancedAttributeValue
for a bytes (b) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().b(...).build())
This call will fail with a RuntimeException
if the provided value is null. Use nullValue()
for
null values.
public static EnhancedAttributeValue fromBoolean(Boolean booleanValue)
EnhancedAttributeValue
for a boolean (bool) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().bool(...).build())
This call will fail with a RuntimeException
if the provided value is null. Use nullValue()
for
null values.
public static EnhancedAttributeValue fromSetOfStrings(String... setOfStringsValue)
EnhancedAttributeValue
for a set-of-strings (ss) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().ss(...).build())
This call will fail with a RuntimeException
if the provided value is null or contains a null value. Use
fromListOfAttributeValues(List)
for null values. This will not validate that there are no
duplicate values.
public static EnhancedAttributeValue fromSetOfStrings(List<String> setOfStringsValue)
EnhancedAttributeValue
for a set-of-strings (ss) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().ss(...).build())
This call will fail with a RuntimeException
if the provided value is null or contains a null value. Use
fromListOfAttributeValues(List)
for null values. This will not validate that there are no
duplicate values.
public static EnhancedAttributeValue fromSetOfNumbers(String... setOfNumbersValue)
EnhancedAttributeValue
for a set-of-numbers (ns) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().ns(...).build())
This call will fail with a RuntimeException
if the provided value is null or contains a null value. Use
fromListOfAttributeValues(List)
for null values. This will not validate that there are no
duplicate values.
public static EnhancedAttributeValue fromSetOfNumbers(List<String> setOfNumbersValue)
EnhancedAttributeValue
for a set-of-numbers (ns) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().ns(...).build())
This call will fail with a RuntimeException
if the provided value is null or contains a null value. Use
fromListOfAttributeValues(List)
for null values. This will not validate that there are no
duplicate values.
public static EnhancedAttributeValue fromSetOfBytes(SdkBytes... setOfBytesValue)
EnhancedAttributeValue
for a set-of-bytes (bs) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().bs(...).build())
This call will fail with a RuntimeException
if the provided value is null or contains a null value. Use
fromListOfAttributeValues(List)
for null values. This will not validate that there are no
duplicate values.
public static EnhancedAttributeValue fromSetOfBytes(List<SdkBytes> setOfBytesValue)
EnhancedAttributeValue
for a set-of-bytes (bs) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().bs(...).build())
This call will fail with a RuntimeException
if the provided value is null or contains a null value. Use
fromListOfAttributeValues(List)
for null values. This will not validate that there are no
duplicate values.
public static EnhancedAttributeValue fromListOfAttributeValues(AttributeValue... listOfAttributeValuesValue)
EnhancedAttributeValue
for a list-of-attributes (l) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().l(...).build())
This call will fail with a RuntimeException
if the provided value is null or contains a null value. Use
nullValue()
for null values.
public static EnhancedAttributeValue fromListOfAttributeValues(List<AttributeValue> listOfAttributeValuesValue)
EnhancedAttributeValue
for a list-of-attributes (l) DynamoDB type.
Equivalent to: EnhancedAttributeValue.fromGeneratedAttributeValue(AttributeValue.builder().l(...).build())
This call will fail with a RuntimeException
if the provided value is null or contains a null value. Use
nullValue()
for null values.
public static EnhancedAttributeValue fromAttributeValue(AttributeValue attributeValue)
EnhancedAttributeValue
from a generated AttributeValue
.
This call will fail with a RuntimeException
if the provided value is null (AttributeValue.nul()
is okay).
public AttributeValueType type()
This call should never fail with an Exception
.
public <T> T convert(TypeConvertingVisitor<T> convertingVisitor)
AttributeConverter
implementations, without having to write a switch statement on the type()
.
Reasons this call may fail with a RuntimeException
:
public boolean isMap()
This call should never fail with an Exception
.
public boolean isString()
This call should never fail with an Exception
.
public boolean isNumber()
This call should never fail with an Exception
.
public boolean isBytes()
This call should never fail with an Exception
.
public boolean isBoolean()
This call should never fail with an Exception
.
public boolean isSetOfStrings()
This call should never fail with an Exception
.
public boolean isSetOfNumbers()
This call should never fail with an Exception
.
public boolean isSetOfBytes()
This call should never fail with an Exception
.
public boolean isListOfAttributeValues()
This call should never fail with an Exception
.
public boolean isNull()
This call should never fail with an Exception
.
public Map<String,AttributeValue> asMap()
This call will fail with a RuntimeException
if isMap()
is false.
public String asString()
This call will fail with a RuntimeException
if isString()
is false.
public String asNumber()
String
(instead of a Number
), because that's the generated type from
DynamoDB: AttributeValue.n()
.
This call will fail with a RuntimeException
if isNumber()
is false.
public SdkBytes asBytes()
This call will fail with a RuntimeException
if isBytes()
is false.
public Boolean asBoolean()
This call will fail with a RuntimeException
if isBoolean()
is false.
public List<String> asSetOfStrings()
Note: This returns a List
(instead of a Set
), because that's the generated type from
DynamoDB: AttributeValue.ss()
.
This call will fail with a RuntimeException
if isSetOfStrings()
is false.
public List<String> asSetOfNumbers()
Note: This returns a List<String>
(instead of a Set<Number>
), because that's the generated type from
DynamoDB: AttributeValue.ns()
.
This call will fail with a RuntimeException
if isSetOfNumbers()
is false.
public List<SdkBytes> asSetOfBytes()
Note: This returns a List
(instead of a Set
), because that's the generated type from
DynamoDB: AttributeValue.bs()
.
This call will fail with a RuntimeException
if isSetOfBytes()
is false.
public List<AttributeValue> asListOfAttributeValues()
This call will fail with a RuntimeException
if isListOfAttributeValues()
is false.
public Map<String,AttributeValue> toAttributeValueMap()
EnhancedAttributeValue
into a generated Map<String, AttributeValue>
.
This call will fail with a RuntimeException
if isMap()
is false.
public AttributeValue toAttributeValue()
EnhancedAttributeValue
into a generated AttributeValue
.
This call should never fail with an Exception
.
Copyright © 2020. All rights reserved.