
software.amazon.awssdk.services.dynamodb.model.GetItemResponse Maven / Gradle / Ivy
/*
* 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.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap;
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 output of a GetItem
operation.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class GetItemResponse extends DynamoDbResponse implements
ToCopyableBuilder {
private final Map item;
private final ConsumedCapacity consumedCapacity;
private GetItemResponse(BuilderImpl builder) {
super(builder);
this.item = builder.item;
this.consumedCapacity = builder.consumedCapacity;
}
/**
*
* A map of attribute names to AttributeValue
objects, as specified by
* ProjectionExpression
.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return A map of attribute names to AttributeValue
objects, as specified by
* ProjectionExpression
.
*/
public Map item() {
return item;
}
/**
*
* The capacity units consumed by the GetItem
operation. The data returned includes the total
* provisioned throughput consumed, along with statistics for the table and any indexes involved in the operation.
* ConsumedCapacity
is only returned if the ReturnConsumedCapacity
parameter was
* specified. For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide.
*
*
* @return The capacity units consumed by the GetItem
operation. The data returned includes the total
* provisioned throughput consumed, along with statistics for the table and any indexes involved in the
* operation. ConsumedCapacity
is only returned if the ReturnConsumedCapacity
* parameter was specified. For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide.
*/
public ConsumedCapacity consumedCapacity() {
return consumedCapacity;
}
@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 int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(item());
hashCode = 31 * hashCode + Objects.hashCode(consumedCapacity());
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof GetItemResponse)) {
return false;
}
GetItemResponse other = (GetItemResponse) obj;
return Objects.equals(item(), other.item()) && Objects.equals(consumedCapacity(), other.consumedCapacity());
}
@Override
public String toString() {
return ToString.builder("GetItemResponse").add("Item", item()).add("ConsumedCapacity", consumedCapacity()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "Item":
return Optional.ofNullable(clazz.cast(item()));
case "ConsumedCapacity":
return Optional.ofNullable(clazz.cast(consumedCapacity()));
default:
return Optional.empty();
}
}
public interface Builder extends DynamoDbResponse.Builder, CopyableBuilder {
/**
*
* A map of attribute names to AttributeValue
objects, as specified by
* ProjectionExpression
.
*
*
* @param item
* A map of attribute names to AttributeValue
objects, as specified by
* ProjectionExpression
.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder item(Map item);
/**
*
* The capacity units consumed by the GetItem
operation. The data returned includes the total
* provisioned throughput consumed, along with statistics for the table and any indexes involved in the
* operation. ConsumedCapacity
is only returned if the ReturnConsumedCapacity
* parameter was specified. For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide.
*
*
* @param consumedCapacity
* The capacity units consumed by the GetItem
operation. The data returned includes the
* total provisioned throughput consumed, along with statistics for the table and any indexes involved in
* the operation. ConsumedCapacity
is only returned if the
* ReturnConsumedCapacity
parameter was specified. For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder consumedCapacity(ConsumedCapacity consumedCapacity);
/**
*
* The capacity units consumed by the GetItem
operation. The data returned includes the total
* provisioned throughput consumed, along with statistics for the table and any indexes involved in the
* operation. ConsumedCapacity
is only returned if the ReturnConsumedCapacity
* parameter was specified. For more information, see Provisioned Throughput in the Amazon DynamoDB Developer Guide.
*
* This is a convenience that creates an instance of the {@link ConsumedCapacity.Builder} avoiding the need to
* create one manually via {@link ConsumedCapacity#builder()}.
*
* When the {@link Consumer} completes, {@link ConsumedCapacity.Builder#build()} is called immediately and its
* result is passed to {@link #consumedCapacity(ConsumedCapacity)}.
*
* @param consumedCapacity
* a consumer that will call methods on {@link ConsumedCapacity.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #consumedCapacity(ConsumedCapacity)
*/
default Builder consumedCapacity(Consumer consumedCapacity) {
return consumedCapacity(ConsumedCapacity.builder().applyMutation(consumedCapacity).build());
}
}
static final class BuilderImpl extends DynamoDbResponse.BuilderImpl implements Builder {
private Map item = DefaultSdkAutoConstructMap.getInstance();
private ConsumedCapacity consumedCapacity;
private BuilderImpl() {
}
private BuilderImpl(GetItemResponse model) {
super(model);
item(model.item);
consumedCapacity(model.consumedCapacity);
}
public final Map getItem() {
return item != null ? CollectionUtils.mapValues(item, AttributeValue::toBuilder) : null;
}
@Override
public final Builder item(Map item) {
this.item = AttributeMapCopier.copy(item);
return this;
}
public final void setItem(Map item) {
this.item = AttributeMapCopier.copyFromBuilder(item);
}
public final ConsumedCapacity.Builder getConsumedCapacity() {
return consumedCapacity != null ? consumedCapacity.toBuilder() : null;
}
@Override
public final Builder consumedCapacity(ConsumedCapacity consumedCapacity) {
this.consumedCapacity = consumedCapacity;
return this;
}
public final void setConsumedCapacity(ConsumedCapacity.BuilderImpl consumedCapacity) {
this.consumedCapacity = consumedCapacity != null ? consumedCapacity.build() : null;
}
@Override
public GetItemResponse build() {
return new GetItemResponse(this);
}
}
}