All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.dynamodb.model.AttributeValue Maven / Gradle / Ivy

Go to download

A single bundled dependency that includes all service and dependent JARs with third-party libraries relocated to different namespaces.

There is a newer version: 2.5.20
Show newest version
/*
 * Copyright 2013-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.dynamodb.model;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.core.adapter.StandardMemberCopier;
import software.amazon.awssdk.core.protocol.ProtocolMarshaller;
import software.amazon.awssdk.core.protocol.StructuredPojo;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap;
import software.amazon.awssdk.services.dynamodb.transform.AttributeValueMarshaller;
import software.amazon.awssdk.utils.CollectionUtils;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
 * 

* Represents the data for an attribute. *

*

* Each attribute value is described as a name-value pair. The name is the data type, and the value is the data itself. *

*

* For more information, see Data Types in the Amazon DynamoDB Developer Guide. *

*/ @Generated("software.amazon.awssdk:codegen") public final class AttributeValue implements StructuredPojo, ToCopyableBuilder { private final String s; private final String n; private final SdkBytes b; private final List ss; private final List ns; private final List bs; private final Map m; private final List l; private final Boolean bool; private final Boolean nul; private AttributeValue(BuilderImpl builder) { this.s = builder.s; this.n = builder.n; this.b = builder.b; this.ss = builder.ss; this.ns = builder.ns; this.bs = builder.bs; this.m = builder.m; this.l = builder.l; this.bool = builder.bool; this.nul = builder.nul; } /** *

* An attribute of type String. For example: *

*

* "S": "Hello" *

* * @return An attribute of type String. For example:

*

* "S": "Hello" */ public String s() { return s; } /** *

* An attribute of type Number. For example: *

*

* "N": "123.45" *

*

* Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. *

* * @return An attribute of type Number. For example:

*

* "N": "123.45" *

*

* Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages * and libraries. However, DynamoDB treats them as number type attributes for mathematical operations. */ public String n() { return n; } /** *

* An attribute of type Binary. For example: *

*

* "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" *

* * @return An attribute of type Binary. For example:

*

* "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" */ public SdkBytes b() { return b; } /** *

* An attribute of type String Set. For example: *

*

* "SS": ["Giraffe", "Hippo" ,"Zebra"] *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

* * @return An attribute of type String Set. For example:

*

* "SS": ["Giraffe", "Hippo" ,"Zebra"] */ public List ss() { return ss; } /** *

* An attribute of type Number Set. For example: *

*

* "NS": ["42.2", "-19", "7.5", "3.14"] *

*

* Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

* * @return An attribute of type Number Set. For example:

*

* "NS": ["42.2", "-19", "7.5", "3.14"] *

*

* Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages * and libraries. However, DynamoDB treats them as number type attributes for mathematical operations. */ public List ns() { return ns; } /** *

* An attribute of type Binary Set. For example: *

*

* "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

* * @return An attribute of type Binary Set. For example:

*

* "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] */ public List bs() { return bs; } /** *

* An attribute of type Map. For example: *

*

* "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

* * @return An attribute of type Map. For example:

*

* "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} */ public Map m() { return m; } /** *

* An attribute of type List. For example: *

*

* "L": ["Cookies", "Coffee", 3.14159] *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

* * @return An attribute of type List. For example:

*

* "L": ["Cookies", "Coffee", 3.14159] */ public List l() { return l; } /** *

* An attribute of type Boolean. For example: *

*

* "BOOL": true *

* * @return An attribute of type Boolean. For example:

*

* "BOOL": true */ public Boolean bool() { return bool; } /** *

* An attribute of type Null. For example: *

*

* "NULL": true *

* * @return An attribute of type Null. For example:

*

* "NULL": true */ public Boolean nul() { return nul; } @Override public Builder toBuilder() { return new BuilderImpl(this); } public static Builder builder() { return new BuilderImpl(); } public static Class serializableBuilderClass() { return BuilderImpl.class; } @Override public int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(s()); hashCode = 31 * hashCode + Objects.hashCode(n()); hashCode = 31 * hashCode + Objects.hashCode(b()); hashCode = 31 * hashCode + Objects.hashCode(ss()); hashCode = 31 * hashCode + Objects.hashCode(ns()); hashCode = 31 * hashCode + Objects.hashCode(bs()); hashCode = 31 * hashCode + Objects.hashCode(m()); hashCode = 31 * hashCode + Objects.hashCode(l()); hashCode = 31 * hashCode + Objects.hashCode(bool()); hashCode = 31 * hashCode + Objects.hashCode(nul()); return hashCode; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof AttributeValue)) { return false; } AttributeValue other = (AttributeValue) obj; return Objects.equals(s(), other.s()) && Objects.equals(n(), other.n()) && Objects.equals(b(), other.b()) && Objects.equals(ss(), other.ss()) && Objects.equals(ns(), other.ns()) && Objects.equals(bs(), other.bs()) && Objects.equals(m(), other.m()) && Objects.equals(l(), other.l()) && Objects.equals(bool(), other.bool()) && Objects.equals(nul(), other.nul()); } @Override public String toString() { return ToString.builder("AttributeValue").add("S", s()).add("N", n()).add("B", b()).add("SS", ss()).add("NS", ns()) .add("BS", bs()).add("M", m()).add("L", l()).add("BOOL", bool()).add("NUL", nul()).build(); } public Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "S": return Optional.ofNullable(clazz.cast(s())); case "N": return Optional.ofNullable(clazz.cast(n())); case "B": return Optional.ofNullable(clazz.cast(b())); case "SS": return Optional.ofNullable(clazz.cast(ss())); case "NS": return Optional.ofNullable(clazz.cast(ns())); case "BS": return Optional.ofNullable(clazz.cast(bs())); case "M": return Optional.ofNullable(clazz.cast(m())); case "L": return Optional.ofNullable(clazz.cast(l())); case "BOOL": return Optional.ofNullable(clazz.cast(bool())); case "NUL": return Optional.ofNullable(clazz.cast(nul())); default: return Optional.empty(); } } @SdkInternalApi @Override public void marshall(ProtocolMarshaller protocolMarshaller) { AttributeValueMarshaller.getInstance().marshall(this, protocolMarshaller); } public interface Builder extends CopyableBuilder { /** *

* An attribute of type String. For example: *

*

* "S": "Hello" *

* * @param s * An attribute of type String. For example:

*

* "S": "Hello" * @return Returns a reference to this object so that method calls can be chained together. */ Builder s(String s); /** *

* An attribute of type Number. For example: *

*

* "N": "123.45" *

*

* Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. *

* * @param n * An attribute of type Number. For example:

*

* "N": "123.45" *

*

* Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages * and libraries. However, DynamoDB treats them as number type attributes for mathematical operations. * @return Returns a reference to this object so that method calls can be chained together. */ Builder n(String n); /** *

* An attribute of type Binary. For example: *

*

* "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" *

* * @param b * An attribute of type Binary. For example:

*

* "B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk" * @return Returns a reference to this object so that method calls can be chained together. */ Builder b(SdkBytes b); /** *

* An attribute of type String Set. For example: *

*

* "SS": ["Giraffe", "Hippo" ,"Zebra"] *

* * @param ss * An attribute of type String Set. For example:

*

* "SS": ["Giraffe", "Hippo" ,"Zebra"] * @return Returns a reference to this object so that method calls can be chained together. */ Builder ss(Collection ss); /** *

* An attribute of type String Set. For example: *

*

* "SS": ["Giraffe", "Hippo" ,"Zebra"] *

* * @param ss * An attribute of type String Set. For example:

*

* "SS": ["Giraffe", "Hippo" ,"Zebra"] * @return Returns a reference to this object so that method calls can be chained together. */ Builder ss(String... ss); /** *

* An attribute of type Number Set. For example: *

*

* "NS": ["42.2", "-19", "7.5", "3.14"] *

*

* Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. *

* * @param ns * An attribute of type Number Set. For example:

*

* "NS": ["42.2", "-19", "7.5", "3.14"] *

*

* Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages * and libraries. However, DynamoDB treats them as number type attributes for mathematical operations. * @return Returns a reference to this object so that method calls can be chained together. */ Builder ns(Collection ns); /** *

* An attribute of type Number Set. For example: *

*

* "NS": ["42.2", "-19", "7.5", "3.14"] *

*

* Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages and * libraries. However, DynamoDB treats them as number type attributes for mathematical operations. *

* * @param ns * An attribute of type Number Set. For example:

*

* "NS": ["42.2", "-19", "7.5", "3.14"] *

*

* Numbers are sent across the network to DynamoDB as strings, to maximize compatibility across languages * and libraries. However, DynamoDB treats them as number type attributes for mathematical operations. * @return Returns a reference to this object so that method calls can be chained together. */ Builder ns(String... ns); /** *

* An attribute of type Binary Set. For example: *

*

* "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] *

* * @param bs * An attribute of type Binary Set. For example:

*

* "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] * @return Returns a reference to this object so that method calls can be chained together. */ Builder bs(Collection bs); /** *

* An attribute of type Binary Set. For example: *

*

* "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] *

* * @param bs * An attribute of type Binary Set. For example:

*

* "BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="] * @return Returns a reference to this object so that method calls can be chained together. */ Builder bs(SdkBytes... bs); /** *

* An attribute of type Map. For example: *

*

* "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} *

* * @param m * An attribute of type Map. For example:

*

* "M": {"Name": {"S": "Joe"}, "Age": {"N": "35"}} * @return Returns a reference to this object so that method calls can be chained together. */ Builder m(Map m); /** *

* An attribute of type List. For example: *

*

* "L": ["Cookies", "Coffee", 3.14159] *

* * @param l * An attribute of type List. For example:

*

* "L": ["Cookies", "Coffee", 3.14159] * @return Returns a reference to this object so that method calls can be chained together. */ Builder l(Collection l); /** *

* An attribute of type List. For example: *

*

* "L": ["Cookies", "Coffee", 3.14159] *

* * @param l * An attribute of type List. For example:

*

* "L": ["Cookies", "Coffee", 3.14159] * @return Returns a reference to this object so that method calls can be chained together. */ Builder l(AttributeValue... l); /** *

* An attribute of type List. For example: *

*

* "L": ["Cookies", "Coffee", 3.14159] *

* This is a convenience that creates an instance of the {@link List.Builder} avoiding the need * to create one manually via {@link List#builder()}. * * When the {@link Consumer} completes, {@link List.Builder#build()} is called immediately and * its result is passed to {@link #l(List)}. * * @param l * a consumer that will call methods on {@link List.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #l(List) */ Builder l(Consumer... l); /** *

* An attribute of type Boolean. For example: *

*

* "BOOL": true *

* * @param bool * An attribute of type Boolean. For example:

*

* "BOOL": true * @return Returns a reference to this object so that method calls can be chained together. */ Builder bool(Boolean bool); /** *

* An attribute of type Null. For example: *

*

* "NULL": true *

* * @param nul * An attribute of type Null. For example:

*

* "NULL": true * @return Returns a reference to this object so that method calls can be chained together. */ Builder nul(Boolean nul); } static final class BuilderImpl implements Builder { private String s; private String n; private SdkBytes b; private List ss = DefaultSdkAutoConstructList.getInstance(); private List ns = DefaultSdkAutoConstructList.getInstance(); private List bs = DefaultSdkAutoConstructList.getInstance(); private Map m = DefaultSdkAutoConstructMap.getInstance(); private List l = DefaultSdkAutoConstructList.getInstance(); private Boolean bool; private Boolean nul; private BuilderImpl() { } private BuilderImpl(AttributeValue model) { s(model.s); n(model.n); b(model.b); ss(model.ss); ns(model.ns); bs(model.bs); m(model.m); l(model.l); bool(model.bool); nul(model.nul); } public final String getS() { return s; } @Override public final Builder s(String s) { this.s = s; return this; } public final void setS(String s) { this.s = s; } public final String getN() { return n; } @Override public final Builder n(String n) { this.n = n; return this; } public final void setN(String n) { this.n = n; } public final ByteBuffer getB() { return b == null ? null : b.asByteBuffer(); } @Override public final Builder b(SdkBytes b) { this.b = StandardMemberCopier.copy(b); return this; } public final void setB(ByteBuffer b) { b(b == null ? null : SdkBytes.fromByteBuffer(b)); } public final Collection getSS() { return ss; } @Override public final Builder ss(Collection ss) { this.ss = StringSetAttributeValueCopier.copy(ss); return this; } @Override @SafeVarargs public final Builder ss(String... ss) { ss(Arrays.asList(ss)); return this; } public final void setSS(Collection ss) { this.ss = StringSetAttributeValueCopier.copy(ss); } public final Collection getNS() { return ns; } @Override public final Builder ns(Collection ns) { this.ns = NumberSetAttributeValueCopier.copy(ns); return this; } @Override @SafeVarargs public final Builder ns(String... ns) { ns(Arrays.asList(ns)); return this; } public final void setNS(Collection ns) { this.ns = NumberSetAttributeValueCopier.copy(ns); } public final List getBS() { return bs == null ? null : bs.stream().map(SdkBytes::asByteBuffer).collect(Collectors.toList()); } @Override public final Builder bs(Collection bs) { this.bs = BinarySetAttributeValueCopier.copy(bs); return this; } @Override @SafeVarargs public final Builder bs(SdkBytes... bs) { bs(Arrays.asList(bs)); return this; } public final void setBS(Collection bs) { bs(bs == null ? null : bs.stream().map(SdkBytes::fromByteBuffer).collect(Collectors.toList())); } public final Map getM() { return m != null ? CollectionUtils.mapValues(m, AttributeValue::toBuilder) : null; } @Override public final Builder m(Map m) { this.m = MapAttributeValueCopier.copy(m); return this; } public final void setM(Map m) { this.m = MapAttributeValueCopier.copyFromBuilder(m); } public final Collection getL() { return l != null ? l.stream().map(AttributeValue::toBuilder).collect(Collectors.toList()) : null; } @Override public final Builder l(Collection l) { this.l = ListAttributeValueCopier.copy(l); return this; } @Override @SafeVarargs public final Builder l(AttributeValue... l) { l(Arrays.asList(l)); return this; } @Override @SafeVarargs public final Builder l(Consumer... l) { l(Stream.of(l).map(c -> AttributeValue.builder().applyMutation(c).build()).collect(Collectors.toList())); return this; } public final void setL(Collection l) { this.l = ListAttributeValueCopier.copyFromBuilder(l); } public final Boolean getBOOL() { return bool; } @Override public final Builder bool(Boolean bool) { this.bool = bool; return this; } public final void setBOOL(Boolean bool) { this.bool = bool; } public final Boolean getNUL() { return nul; } @Override public final Builder nul(Boolean nul) { this.nul = nul; return this; } public final void setNUL(Boolean nul) { this.nul = nul; } @Override public AttributeValue build() { return new AttributeValue(this); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy