
software.amazon.awssdk.services.kinesis.model.Shard 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.kinesis.model;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.core.protocol.ProtocolMarshaller;
import software.amazon.awssdk.core.protocol.StructuredPojo;
import software.amazon.awssdk.services.kinesis.transform.ShardMarshaller;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* A uniquely identified group of data records in a Kinesis data stream.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class Shard implements StructuredPojo, ToCopyableBuilder {
private final String shardId;
private final String parentShardId;
private final String adjacentParentShardId;
private final HashKeyRange hashKeyRange;
private final SequenceNumberRange sequenceNumberRange;
private Shard(BuilderImpl builder) {
this.shardId = builder.shardId;
this.parentShardId = builder.parentShardId;
this.adjacentParentShardId = builder.adjacentParentShardId;
this.hashKeyRange = builder.hashKeyRange;
this.sequenceNumberRange = builder.sequenceNumberRange;
}
/**
*
* The unique identifier of the shard within the stream.
*
*
* @return The unique identifier of the shard within the stream.
*/
public String shardId() {
return shardId;
}
/**
*
* The shard ID of the shard's parent.
*
*
* @return The shard ID of the shard's parent.
*/
public String parentShardId() {
return parentShardId;
}
/**
*
* The shard ID of the shard adjacent to the shard's parent.
*
*
* @return The shard ID of the shard adjacent to the shard's parent.
*/
public String adjacentParentShardId() {
return adjacentParentShardId;
}
/**
*
* The range of possible hash key values for the shard, which is a set of ordered contiguous positive integers.
*
*
* @return The range of possible hash key values for the shard, which is a set of ordered contiguous positive
* integers.
*/
public HashKeyRange hashKeyRange() {
return hashKeyRange;
}
/**
*
* The range of possible sequence numbers for the shard.
*
*
* @return The range of possible sequence numbers for the shard.
*/
public SequenceNumberRange sequenceNumberRange() {
return sequenceNumberRange;
}
@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(shardId());
hashCode = 31 * hashCode + Objects.hashCode(parentShardId());
hashCode = 31 * hashCode + Objects.hashCode(adjacentParentShardId());
hashCode = 31 * hashCode + Objects.hashCode(hashKeyRange());
hashCode = 31 * hashCode + Objects.hashCode(sequenceNumberRange());
return hashCode;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Shard)) {
return false;
}
Shard other = (Shard) obj;
return Objects.equals(shardId(), other.shardId()) && Objects.equals(parentShardId(), other.parentShardId())
&& Objects.equals(adjacentParentShardId(), other.adjacentParentShardId())
&& Objects.equals(hashKeyRange(), other.hashKeyRange())
&& Objects.equals(sequenceNumberRange(), other.sequenceNumberRange());
}
@Override
public String toString() {
return ToString.builder("Shard").add("ShardId", shardId()).add("ParentShardId", parentShardId())
.add("AdjacentParentShardId", adjacentParentShardId()).add("HashKeyRange", hashKeyRange())
.add("SequenceNumberRange", sequenceNumberRange()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "ShardId":
return Optional.ofNullable(clazz.cast(shardId()));
case "ParentShardId":
return Optional.ofNullable(clazz.cast(parentShardId()));
case "AdjacentParentShardId":
return Optional.ofNullable(clazz.cast(adjacentParentShardId()));
case "HashKeyRange":
return Optional.ofNullable(clazz.cast(hashKeyRange()));
case "SequenceNumberRange":
return Optional.ofNullable(clazz.cast(sequenceNumberRange()));
default:
return Optional.empty();
}
}
@SdkInternalApi
@Override
public void marshall(ProtocolMarshaller protocolMarshaller) {
ShardMarshaller.getInstance().marshall(this, protocolMarshaller);
}
public interface Builder extends CopyableBuilder {
/**
*
* The unique identifier of the shard within the stream.
*
*
* @param shardId
* The unique identifier of the shard within the stream.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder shardId(String shardId);
/**
*
* The shard ID of the shard's parent.
*
*
* @param parentShardId
* The shard ID of the shard's parent.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder parentShardId(String parentShardId);
/**
*
* The shard ID of the shard adjacent to the shard's parent.
*
*
* @param adjacentParentShardId
* The shard ID of the shard adjacent to the shard's parent.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder adjacentParentShardId(String adjacentParentShardId);
/**
*
* The range of possible hash key values for the shard, which is a set of ordered contiguous positive integers.
*
*
* @param hashKeyRange
* The range of possible hash key values for the shard, which is a set of ordered contiguous positive
* integers.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder hashKeyRange(HashKeyRange hashKeyRange);
/**
*
* The range of possible hash key values for the shard, which is a set of ordered contiguous positive integers.
*
* This is a convenience that creates an instance of the {@link HashKeyRange.Builder} avoiding the need to
* create one manually via {@link HashKeyRange#builder()}.
*
* When the {@link Consumer} completes, {@link HashKeyRange.Builder#build()} is called immediately and its
* result is passed to {@link #hashKeyRange(HashKeyRange)}.
*
* @param hashKeyRange
* a consumer that will call methods on {@link HashKeyRange.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #hashKeyRange(HashKeyRange)
*/
default Builder hashKeyRange(Consumer hashKeyRange) {
return hashKeyRange(HashKeyRange.builder().applyMutation(hashKeyRange).build());
}
/**
*
* The range of possible sequence numbers for the shard.
*
*
* @param sequenceNumberRange
* The range of possible sequence numbers for the shard.
* @return Returns a reference to this object so that method calls can be chained together.
*/
Builder sequenceNumberRange(SequenceNumberRange sequenceNumberRange);
/**
*
* The range of possible sequence numbers for the shard.
*
* This is a convenience that creates an instance of the {@link SequenceNumberRange.Builder} avoiding the need
* to create one manually via {@link SequenceNumberRange#builder()}.
*
* When the {@link Consumer} completes, {@link SequenceNumberRange.Builder#build()} is called immediately and
* its result is passed to {@link #sequenceNumberRange(SequenceNumberRange)}.
*
* @param sequenceNumberRange
* a consumer that will call methods on {@link SequenceNumberRange.Builder}
* @return Returns a reference to this object so that method calls can be chained together.
* @see #sequenceNumberRange(SequenceNumberRange)
*/
default Builder sequenceNumberRange(Consumer sequenceNumberRange) {
return sequenceNumberRange(SequenceNumberRange.builder().applyMutation(sequenceNumberRange).build());
}
}
static final class BuilderImpl implements Builder {
private String shardId;
private String parentShardId;
private String adjacentParentShardId;
private HashKeyRange hashKeyRange;
private SequenceNumberRange sequenceNumberRange;
private BuilderImpl() {
}
private BuilderImpl(Shard model) {
shardId(model.shardId);
parentShardId(model.parentShardId);
adjacentParentShardId(model.adjacentParentShardId);
hashKeyRange(model.hashKeyRange);
sequenceNumberRange(model.sequenceNumberRange);
}
public final String getShardId() {
return shardId;
}
@Override
public final Builder shardId(String shardId) {
this.shardId = shardId;
return this;
}
public final void setShardId(String shardId) {
this.shardId = shardId;
}
public final String getParentShardId() {
return parentShardId;
}
@Override
public final Builder parentShardId(String parentShardId) {
this.parentShardId = parentShardId;
return this;
}
public final void setParentShardId(String parentShardId) {
this.parentShardId = parentShardId;
}
public final String getAdjacentParentShardId() {
return adjacentParentShardId;
}
@Override
public final Builder adjacentParentShardId(String adjacentParentShardId) {
this.adjacentParentShardId = adjacentParentShardId;
return this;
}
public final void setAdjacentParentShardId(String adjacentParentShardId) {
this.adjacentParentShardId = adjacentParentShardId;
}
public final HashKeyRange.Builder getHashKeyRange() {
return hashKeyRange != null ? hashKeyRange.toBuilder() : null;
}
@Override
public final Builder hashKeyRange(HashKeyRange hashKeyRange) {
this.hashKeyRange = hashKeyRange;
return this;
}
public final void setHashKeyRange(HashKeyRange.BuilderImpl hashKeyRange) {
this.hashKeyRange = hashKeyRange != null ? hashKeyRange.build() : null;
}
public final SequenceNumberRange.Builder getSequenceNumberRange() {
return sequenceNumberRange != null ? sequenceNumberRange.toBuilder() : null;
}
@Override
public final Builder sequenceNumberRange(SequenceNumberRange sequenceNumberRange) {
this.sequenceNumberRange = sequenceNumberRange;
return this;
}
public final void setSequenceNumberRange(SequenceNumberRange.BuilderImpl sequenceNumberRange) {
this.sequenceNumberRange = sequenceNumberRange != null ? sequenceNumberRange.build() : null;
}
@Override
public Shard build() {
return new Shard(this);
}
}
}