
software.amazon.awssdk.services.dynamodb.model.CreateGlobalSecondaryIndexAction Maven / Gradle / Ivy
/*
* Copyright 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.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Represents a new global secondary index to be added to an existing table.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class CreateGlobalSecondaryIndexAction implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField INDEX_NAME_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("IndexName").getter(getter(CreateGlobalSecondaryIndexAction::indexName))
.setter(setter(Builder::indexName))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("IndexName").build()).build();
private static final SdkField> KEY_SCHEMA_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("KeySchema")
.getter(getter(CreateGlobalSecondaryIndexAction::keySchema))
.setter(setter(Builder::keySchema))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("KeySchema").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(KeySchemaElement::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField PROJECTION_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("Projection").getter(getter(CreateGlobalSecondaryIndexAction::projection))
.setter(setter(Builder::projection)).constructor(Projection::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Projection").build()).build();
private static final SdkField PROVISIONED_THROUGHPUT_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).memberName("ProvisionedThroughput")
.getter(getter(CreateGlobalSecondaryIndexAction::provisionedThroughput))
.setter(setter(Builder::provisionedThroughput)).constructor(ProvisionedThroughput::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ProvisionedThroughput").build())
.build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(INDEX_NAME_FIELD,
KEY_SCHEMA_FIELD, PROJECTION_FIELD, PROVISIONED_THROUGHPUT_FIELD));
private static final long serialVersionUID = 1L;
private final String indexName;
private final List keySchema;
private final Projection projection;
private final ProvisionedThroughput provisionedThroughput;
private CreateGlobalSecondaryIndexAction(BuilderImpl builder) {
this.indexName = builder.indexName;
this.keySchema = builder.keySchema;
this.projection = builder.projection;
this.provisionedThroughput = builder.provisionedThroughput;
}
/**
*
* The name of the global secondary index to be created.
*
*
* @return The name of the global secondary index to be created.
*/
public final String indexName() {
return indexName;
}
/**
* For responses, this returns true if the service returned a value for the KeySchema 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 hasKeySchema() {
return keySchema != null && !(keySchema instanceof SdkAutoConstructList);
}
/**
*
* The key schema for the global secondary index.
*
*
* 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 #hasKeySchema} method.
*
*
* @return The key schema for the global secondary index.
*/
public final List keySchema() {
return keySchema;
}
/**
*
* Represents attributes that are copied (projected) from the table into an index. These are in addition to the
* primary key attributes and index key attributes, which are automatically projected.
*
*
* @return Represents attributes that are copied (projected) from the table into an index. These are in addition to
* the primary key attributes and index key attributes, which are automatically projected.
*/
public final Projection projection() {
return projection;
}
/**
*
* Represents the provisioned throughput settings for the specified global secondary index.
*
*
* For current minimum and maximum provisioned throughput values, see Service, Account, and Table
* Quotas in the Amazon DynamoDB Developer Guide.
*
*
* @return Represents the provisioned throughput settings for the specified global secondary index.
*
* For current minimum and maximum provisioned throughput values, see Service, Account, and
* Table Quotas in the Amazon DynamoDB Developer Guide.
*/
public final ProvisionedThroughput provisionedThroughput() {
return provisionedThroughput;
}
@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(indexName());
hashCode = 31 * hashCode + Objects.hashCode(hasKeySchema() ? keySchema() : null);
hashCode = 31 * hashCode + Objects.hashCode(projection());
hashCode = 31 * hashCode + Objects.hashCode(provisionedThroughput());
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 CreateGlobalSecondaryIndexAction)) {
return false;
}
CreateGlobalSecondaryIndexAction other = (CreateGlobalSecondaryIndexAction) obj;
return Objects.equals(indexName(), other.indexName()) && hasKeySchema() == other.hasKeySchema()
&& Objects.equals(keySchema(), other.keySchema()) && Objects.equals(projection(), other.projection())
&& Objects.equals(provisionedThroughput(), other.provisionedThroughput());
}
/**
* 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("CreateGlobalSecondaryIndexAction").add("IndexName", indexName())
.add("KeySchema", hasKeySchema() ? keySchema() : null).add("Projection", projection())
.add("ProvisionedThroughput", provisionedThroughput()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "IndexName":
return Optional.ofNullable(clazz.cast(indexName()));
case "KeySchema":
return Optional.ofNullable(clazz.cast(keySchema()));
case "Projection":
return Optional.ofNullable(clazz.cast(projection()));
case "ProvisionedThroughput":
return Optional.ofNullable(clazz.cast(provisionedThroughput()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function