record;
private final Type type;
private AttributeValue(BuilderImpl builder) {
this.booleanValue = builder.booleanValue;
this.entityIdentifier = builder.entityIdentifier;
this.longValue = builder.longValue;
this.string = builder.string;
this.set = builder.set;
this.record = builder.record;
this.type = builder.type;
}
/**
*
* An attribute value of Boolean
* type.
*
*
* Example: {"boolean": true}
*
*
* @return An attribute value of Boolean type.
*
* Example: {"boolean": true}
*/
public final Boolean booleanValue() {
return booleanValue;
}
/**
*
* An attribute value of type EntityIdentifier .
*
*
* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"}
*
*
* @return An attribute value of type EntityIdentifier .
*
* Example:
* "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"}
*/
public final EntityIdentifier entityIdentifier() {
return entityIdentifier;
}
/**
*
* An attribute value of Long type.
*
*
* Example: {"long": 0}
*
*
* @return An attribute value of Long
* type.
*
* Example: {"long": 0}
*/
public final Long longValue() {
return longValue;
}
/**
*
* An attribute value of String
* type.
*
*
* Example: {"string": "abc"}
*
*
* @return An attribute value of String type.
*
* Example: {"string": "abc"}
*/
public final String string() {
return string;
}
/**
* For responses, this returns true if the service returned a value for the Set property. This DOES NOT check that
* the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful
* because the SDK will never return a null collection or map, but you may need to differentiate between the service
* returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true
* if a value for the property was specified in the request builder, and false if a value was not specified.
*/
public final boolean hasSet() {
return set != null && !(set instanceof SdkAutoConstructList);
}
/**
*
* An attribute value of Set type.
*
*
* Example: {"set": [ {} ] }
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasSet} method.
*
*
* @return An attribute value of Set
* type.
*
* Example: {"set": [ {} ] }
*/
public final List set() {
return set;
}
/**
* For responses, this returns true if the service returned a value for the Record property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasRecord() {
return record != null && !(record instanceof SdkAutoConstructMap);
}
/**
*
* An attribute value of Record
* type.
*
*
* Example: {"record": { "keyName": {} } }
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasRecord} method.
*
*
* @return An attribute value of Record type.
*
* Example: {"record": { "keyName": {} } }
*/
public final Map record() {
return record;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(booleanValue());
hashCode = 31 * hashCode + Objects.hashCode(entityIdentifier());
hashCode = 31 * hashCode + Objects.hashCode(longValue());
hashCode = 31 * hashCode + Objects.hashCode(string());
hashCode = 31 * hashCode + Objects.hashCode(hasSet() ? set() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasRecord() ? record() : null);
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(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(booleanValue(), other.booleanValue())
&& Objects.equals(entityIdentifier(), other.entityIdentifier()) && Objects.equals(longValue(), other.longValue())
&& Objects.equals(string(), other.string()) && hasSet() == other.hasSet() && Objects.equals(set(), other.set())
&& hasRecord() == other.hasRecord() && Objects.equals(record(), other.record());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("AttributeValue")
.add("Boolean", booleanValue() == null ? null : "*** Sensitive Data Redacted ***")
.add("EntityIdentifier", entityIdentifier())
.add("Long", longValue() == null ? null : "*** Sensitive Data Redacted ***")
.add("String", string() == null ? null : "*** Sensitive Data Redacted ***").add("Set", hasSet() ? set() : null)
.add("Record", hasRecord() ? record() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "boolean":
return Optional.ofNullable(clazz.cast(booleanValue()));
case "entityIdentifier":
return Optional.ofNullable(clazz.cast(entityIdentifier()));
case "long":
return Optional.ofNullable(clazz.cast(longValue()));
case "string":
return Optional.ofNullable(clazz.cast(string()));
case "set":
return Optional.ofNullable(clazz.cast(set()));
case "record":
return Optional.ofNullable(clazz.cast(record()));
default:
return Optional.empty();
}
}
/**
* Create an instance of this class with {@link #booleanValue()} initialized to the given value.
*
*
* An attribute value of Boolean
* type.
*
*
* Example: {"boolean": true}
*
*
* @param booleanValue
* An attribute value of Boolean type.
*
* Example: {"boolean": true}
*/
public static AttributeValue fromBooleanValue(Boolean booleanValue) {
return builder().booleanValue(booleanValue).build();
}
/**
* Create an instance of this class with {@link #entityIdentifier()} initialized to the given value.
*
*
* An attribute value of type EntityIdentifier .
*
*
* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"}
*
*
* @param entityIdentifier
* An attribute value of type EntityIdentifier .
*
* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"}
*/
public static AttributeValue fromEntityIdentifier(EntityIdentifier entityIdentifier) {
return builder().entityIdentifier(entityIdentifier).build();
}
/**
* Create an instance of this class with {@link #entityIdentifier()} initialized to the given value.
*
*
* An attribute value of type EntityIdentifier .
*
*
* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"}
*
*
* @param entityIdentifier
* An attribute value of type EntityIdentifier .
*
* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"}
*/
public static AttributeValue fromEntityIdentifier(Consumer entityIdentifier) {
EntityIdentifier.Builder builder = EntityIdentifier.builder();
entityIdentifier.accept(builder);
return fromEntityIdentifier(builder.build());
}
/**
* Create an instance of this class with {@link #longValue()} initialized to the given value.
*
*
* An attribute value of Long type.
*
*
* Example: {"long": 0}
*
*
* @param longValue
* An attribute value of Long
* type.
*
* Example: {"long": 0}
*/
public static AttributeValue fromLongValue(Long longValue) {
return builder().longValue(longValue).build();
}
/**
* Create an instance of this class with {@link #string()} initialized to the given value.
*
*
* An attribute value of String
* type.
*
*
* Example: {"string": "abc"}
*
*
* @param string
* An attribute value of String type.
*
* Example: {"string": "abc"}
*/
public static AttributeValue fromString(String string) {
return builder().string(string).build();
}
/**
* Create an instance of this class with {@link #set()} initialized to the given value.
*
*
* An attribute value of Set type.
*
*
* Example: {"set": [ {} ] }
*
*
* @param set
* An attribute value of Set
* type.
*
* Example: {"set": [ {} ] }
*/
public static AttributeValue fromSet(List set) {
return builder().set(set).build();
}
/**
* Create an instance of this class with {@link #record()} initialized to the given value.
*
*
* An attribute value of Record
* type.
*
*
* Example: {"record": { "keyName": {} } }
*
*
* @param record
* An attribute value of Record type.
*
* Example: {"record": { "keyName": {} } }
*/
public static AttributeValue fromRecord(Map record) {
return builder().record(record).build();
}
/**
* Retrieve an enum value representing which member of this object is populated.
*
* When this class is returned in a service response, this will be {@link Type#UNKNOWN_TO_SDK_VERSION} if the
* service returned a member that is only known to a newer SDK version.
*
* When this class is created directly in your code, this will be {@link Type#UNKNOWN_TO_SDK_VERSION} if zero
* members are set, and {@code null} if more than one member is set.
*/
public Type type() {
return type;
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function getter(Function g) {
return obj -> g.apply((AttributeValue) obj);
}
private static BiConsumer setter(BiConsumer s) {
return (obj, val) -> s.accept((Builder) obj, val);
}
public interface Builder extends SdkPojo, CopyableBuilder {
/**
*
* An attribute value of Boolean type.
*
*
* Example: {"boolean": true}
*
*
* @param booleanValue
* An attribute value of Boolean type.
*
* Example: {"boolean": true}
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder booleanValue(Boolean booleanValue);
/**
*
* An attribute value of type EntityIdentifier .
*
*
* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"}
*
*
* @param entityIdentifier
* An attribute value of type EntityIdentifier .
*
* Example:
* "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"}
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder entityIdentifier(EntityIdentifier entityIdentifier);
/**
*
* An attribute value of type EntityIdentifier .
*
*
* Example: "entityIdentifier": { "entityId": "<id>", "entityType": "<entity type>"}
*
* This is a convenience method that creates an instance of the {@link EntityIdentifier.Builder} avoiding the
* need to create one manually via {@link EntityIdentifier#builder()}.
*
*
* When the {@link Consumer} completes, {@link EntityIdentifier.Builder#build()} is called immediately and its
* result is passed to {@link #entityIdentifier(EntityIdentifier)}.
*
* @param entityIdentifier
* a consumer that will call methods on {@link EntityIdentifier.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #entityIdentifier(EntityIdentifier)
*/
default Builder entityIdentifier(Consumer entityIdentifier) {
return entityIdentifier(EntityIdentifier.builder().applyMutation(entityIdentifier).build());
}
/**
*
* An attribute value of Long
* type.
*
*
* Example: {"long": 0}
*
*
* @param longValue
* An attribute value of Long type.
*
* Example: {"long": 0}
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder longValue(Long longValue);
/**
*
* An attribute value of String
* type.
*
*
* Example: {"string": "abc"}
*
*
* @param string
* An attribute value of String type.
*
* Example: {"string": "abc"}
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder string(String string);
/**
*
* An attribute value of Set type.
*
*
* Example: {"set": [ {} ] }
*
*
* @param set
* An attribute value of Set type.
*
* Example: {"set": [ {} ] }
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder set(Collection set);
/**
*
* An attribute value of Set type.
*
*
* Example: {"set": [ {} ] }
*
*
* @param set
* An attribute value of Set type.
*
* Example: {"set": [ {} ] }
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder set(AttributeValue... set);
/**
*
* An attribute value of Set type.
*
*
* Example: {"set": [ {} ] }
*
* This is a convenience method that creates an instance of the
* {@link software.amazon.awssdk.services.verifiedpermissions.model.AttributeValue.Builder} avoiding the need to
* create one manually via
* {@link software.amazon.awssdk.services.verifiedpermissions.model.AttributeValue#builder()}.
*
*
* When the {@link Consumer} completes,
* {@link software.amazon.awssdk.services.verifiedpermissions.model.AttributeValue.Builder#build()} is called
* immediately and its result is passed to {@link #set(List)}.
*
* @param set
* a consumer that will call methods on
* {@link software.amazon.awssdk.services.verifiedpermissions.model.AttributeValue.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #set(java.util.Collection)
*/
Builder set(Consumer... set);
/**
*
* An attribute value of Record
* type.
*
*
* Example: {"record": { "keyName": {} } }
*
*
* @param record
* An attribute value of Record type.
*
* Example: {"record": { "keyName": {} } }
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder record(Map record);
}
static final class BuilderImpl implements Builder {
private Boolean booleanValue;
private EntityIdentifier entityIdentifier;
private Long longValue;
private String string;
private List set = DefaultSdkAutoConstructList.getInstance();
private Map record = DefaultSdkAutoConstructMap.getInstance();
private Type type = Type.UNKNOWN_TO_SDK_VERSION;
private Set setTypes = EnumSet.noneOf(Type.class);
private BuilderImpl() {
}
private BuilderImpl(AttributeValue model) {
booleanValue(model.booleanValue);
entityIdentifier(model.entityIdentifier);
longValue(model.longValue);
string(model.string);
set(model.set);
record(model.record);
}
public final Boolean getBooleanValue() {
return booleanValue;
}
public final void setBooleanValue(Boolean booleanValue) {
Object oldValue = this.booleanValue;
this.booleanValue = booleanValue;
handleUnionValueChange(Type.BOOLEAN, oldValue, this.booleanValue);
}
@Override
public final Builder booleanValue(Boolean booleanValue) {
Object oldValue = this.booleanValue;
this.booleanValue = booleanValue;
handleUnionValueChange(Type.BOOLEAN, oldValue, this.booleanValue);
return this;
}
public final EntityIdentifier.Builder getEntityIdentifier() {
return entityIdentifier != null ? entityIdentifier.toBuilder() : null;
}
public final void setEntityIdentifier(EntityIdentifier.BuilderImpl entityIdentifier) {
Object oldValue = this.entityIdentifier;
this.entityIdentifier = entityIdentifier != null ? entityIdentifier.build() : null;
handleUnionValueChange(Type.ENTITY_IDENTIFIER, oldValue, this.entityIdentifier);
}
@Override
public final Builder entityIdentifier(EntityIdentifier entityIdentifier) {
Object oldValue = this.entityIdentifier;
this.entityIdentifier = entityIdentifier;
handleUnionValueChange(Type.ENTITY_IDENTIFIER, oldValue, this.entityIdentifier);
return this;
}
public final Long getLongValue() {
return longValue;
}
public final void setLongValue(Long longValue) {
Object oldValue = this.longValue;
this.longValue = longValue;
handleUnionValueChange(Type.LONG, oldValue, this.longValue);
}
@Override
public final Builder longValue(Long longValue) {
Object oldValue = this.longValue;
this.longValue = longValue;
handleUnionValueChange(Type.LONG, oldValue, this.longValue);
return this;
}
public final String getString() {
return string;
}
public final void setString(String string) {
Object oldValue = this.string;
this.string = string;
handleUnionValueChange(Type.STRING, oldValue, this.string);
}
@Override
public final Builder string(String string) {
Object oldValue = this.string;
this.string = string;
handleUnionValueChange(Type.STRING, oldValue, this.string);
return this;
}
public final List getSet() {
List result = SetAttributeCopier.copyToBuilder(this.set);
if (result instanceof SdkAutoConstructList) {
return null;
}
return result;
}
public final void setSet(Collection set) {
Object oldValue = this.set;
this.set = SetAttributeCopier.copyFromBuilder(set);
handleUnionValueChange(Type.SET, oldValue, this.set);
}
@Override
@Transient
public final Builder set(Collection set) {
Object oldValue = this.set;
this.set = SetAttributeCopier.copy(set);
handleUnionValueChange(Type.SET, oldValue, this.set);
return this;
}
@Override
@Transient
@SafeVarargs
public final Builder set(AttributeValue... set) {
set(Arrays.asList(set));
return this;
}
@Override
@Transient
@SafeVarargs
public final Builder set(Consumer... set) {
set(Stream.of(set).map(c -> AttributeValue.builder().applyMutation(c).build()).collect(Collectors.toList()));
return this;
}
public final Map getRecord() {
Map result = RecordAttributeCopier.copyToBuilder(this.record);
if (result instanceof SdkAutoConstructMap) {
return null;
}
return result;
}
public final void setRecord(Map record) {
Object oldValue = this.record;
this.record = RecordAttributeCopier.copyFromBuilder(record);
handleUnionValueChange(Type.RECORD, oldValue, this.record);
}
@Override
public final Builder record(Map record) {
Object oldValue = this.record;
this.record = RecordAttributeCopier.copy(record);
handleUnionValueChange(Type.RECORD, oldValue, this.record);
return this;
}
@Override
public AttributeValue build() {
return new AttributeValue(this);
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
private final void handleUnionValueChange(Type type, Object oldValue, Object newValue) {
if (this.type == type || oldValue == newValue) {
return;
}
if (newValue == null || newValue instanceof SdkAutoConstructList || newValue instanceof SdkAutoConstructMap) {
setTypes.remove(type);
} else if (oldValue == null || oldValue instanceof SdkAutoConstructList || oldValue instanceof SdkAutoConstructMap) {
setTypes.add(type);
}
if (setTypes.size() == 1) {
this.type = setTypes.iterator().next();
} else if (setTypes.isEmpty()) {
this.type = Type.UNKNOWN_TO_SDK_VERSION;
} else {
this.type = null;
}
}
}
/**
* @see AttributeValue#type()
*/
public enum Type {
BOOLEAN,
ENTITY_IDENTIFIER,
LONG,
STRING,
SET,
RECORD,
UNKNOWN_TO_SDK_VERSION
}
}