com.arakelian.elastic.model.ImmutableBulkOperationResponse Maven / Gradle / Ivy
package com.arakelian.elastic.model;
import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.Views;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonView;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link BulkResponse.BulkOperationResponse}.
*
* Use the builder to create immutable instances:
* {@code ImmutableBulkOperationResponse.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableBulkOperationResponse
implements BulkResponse.BulkOperationResponse {
private final @Nullable Boolean created;
private final @Nullable Cause error;
private final @Nullable Boolean found;
private final @Nullable Integer primaryTerm;
private final @Nullable String result;
private final @Nullable Integer seqNo;
private final @Nullable Shards shards;
private final int status;
private final @Nullable Long version;
private final String id;
private final String index;
private final String type;
private ImmutableBulkOperationResponse(ImmutableBulkOperationResponse.Builder builder) {
this.created = builder.created;
this.error = builder.error;
this.found = builder.found;
this.primaryTerm = builder.primaryTerm;
this.result = builder.result;
this.seqNo = builder.seqNo;
this.shards = builder.shards;
this.status = builder.status;
this.version = builder.version;
this.id = builder.id;
this.index = builder.index;
this.type = builder.type;
}
/**
* @return The value of the {@code created} attribute
*/
@JsonProperty("created")
@Override
public @Nullable Boolean getCreated() {
return created;
}
/**
* @return The value of the {@code error} attribute
*/
@JsonProperty("error")
@Override
public @Nullable Cause getError() {
return error;
}
/**
* @return The value of the {@code found} attribute
*/
@JsonProperty("found")
@Override
public @Nullable Boolean getFound() {
return found;
}
/**
* @return The value of the {@code primaryTerm} attribute
*/
@JsonProperty("_primary_term")
@JsonView(Views.Elastic.Version6.class)
@Override
public @Nullable Integer getPrimaryTerm() {
return primaryTerm;
}
/**
* @return The value of the {@code result} attribute
*/
@JsonProperty("result")
@Override
public @Nullable String getResult() {
return result;
}
/**
* @return The value of the {@code seqNo} attribute
*/
@JsonProperty("_seq_no")
@JsonView(Views.Elastic.Version6.class)
@Override
public @Nullable Integer getSeqNo() {
return seqNo;
}
/**
* @return The value of the {@code shards} attribute
*/
@JsonProperty("_shards")
@Override
public @Nullable Shards getShards() {
return shards;
}
/**
* @return The value of the {@code status} attribute
*/
@JsonProperty("status")
@Override
public int getStatus() {
return status;
}
/**
* @return The value of the {@code version} attribute
*/
@JsonProperty("_version")
@Override
public @Nullable Long getVersion() {
return version;
}
/**
* @return The value of the {@code id} attribute
*/
@JsonProperty("_id")
@Override
public String getId() {
return id;
}
/**
* @return The value of the {@code index} attribute
*/
@JsonProperty("_index")
@Override
public String getIndex() {
return index;
}
/**
* @return The value of the {@code type} attribute
*/
@JsonProperty("_type")
@Override
public String getType() {
return type;
}
/**
* This instance is equal to all instances of {@code ImmutableBulkOperationResponse} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@javax.annotation.Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableBulkOperationResponse
&& equalTo((ImmutableBulkOperationResponse) another);
}
private boolean equalTo(ImmutableBulkOperationResponse another) {
return Objects.equals(error, another.error)
&& Objects.equals(primaryTerm, another.primaryTerm)
&& Objects.equals(result, another.result)
&& Objects.equals(seqNo, another.seqNo)
&& status == another.status
&& Objects.equals(version, another.version)
&& id.equals(another.id)
&& index.equals(another.index)
&& type.equals(another.type);
}
/**
* Computes a hash code from attributes: {@code error}, {@code primaryTerm}, {@code result}, {@code seqNo}, {@code status}, {@code version}, {@code id}, {@code index}, {@code type}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(error);
h += (h << 5) + Objects.hashCode(primaryTerm);
h += (h << 5) + Objects.hashCode(result);
h += (h << 5) + Objects.hashCode(seqNo);
h += (h << 5) + status;
h += (h << 5) + Objects.hashCode(version);
h += (h << 5) + id.hashCode();
h += (h << 5) + index.hashCode();
h += (h << 5) + type.hashCode();
return h;
}
/**
* Prints the immutable value {@code BulkOperationResponse} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("BulkOperationResponse")
.omitNullValues()
.add("error", error)
.add("primaryTerm", primaryTerm)
.add("result", result)
.add("seqNo", seqNo)
.add("status", status)
.add("version", version)
.add("id", id)
.add("index", index)
.add("type", type)
.toString();
}
/**
* Creates a builder for {@link ImmutableBulkOperationResponse ImmutableBulkOperationResponse}.
* @return A new ImmutableBulkOperationResponse builder
*/
public static ImmutableBulkOperationResponse.Builder builder() {
return new ImmutableBulkOperationResponse.Builder();
}
/**
* Builds instances of type {@link ImmutableBulkOperationResponse ImmutableBulkOperationResponse}.
* Initialize attributes and then invoke the {@link #build()} method to create an
* immutable instance.
*
{@code Builder} is not thread-safe and generally should not be stored in a field or collection,
* but instead used immediately to create instances.
*/
@NotThreadSafe
@JsonPropertyOrder({"_index", "_type", "_id", "_version", "result", "status", "created", "found", "error", "_shards"})
public static final class Builder {
private static final long INIT_BIT_STATUS = 0x1L;
private static final long INIT_BIT_ID = 0x2L;
private static final long INIT_BIT_INDEX = 0x4L;
private static final long INIT_BIT_TYPE = 0x8L;
private long initBits = 0xfL;
private @javax.annotation.Nullable Boolean created;
private @javax.annotation.Nullable Cause error;
private @javax.annotation.Nullable Boolean found;
private @javax.annotation.Nullable Integer primaryTerm;
private @javax.annotation.Nullable String result;
private @javax.annotation.Nullable Integer seqNo;
private @javax.annotation.Nullable Shards shards;
private int status;
private @javax.annotation.Nullable Long version;
private @javax.annotation.Nullable String id;
private @javax.annotation.Nullable String index;
private @javax.annotation.Nullable String type;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.BulkResponse.BulkOperationResponse} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(BulkResponse.BulkOperationResponse instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.DocumentId} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(DocumentId instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.VersionedDocumentId} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(VersionedDocumentId instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof BulkResponse.BulkOperationResponse) {
BulkResponse.BulkOperationResponse instance = (BulkResponse.BulkOperationResponse) object;
String resultValue = instance.getResult();
if (resultValue != null) {
result(resultValue);
}
Shards shardsValue = instance.getShards();
if (shardsValue != null) {
shards(shardsValue);
}
Boolean foundValue = instance.getFound();
if (foundValue != null) {
found(foundValue);
}
Integer seqNoValue = instance.getSeqNo();
if (seqNoValue != null) {
seqNo(seqNoValue);
}
Boolean createdValue = instance.getCreated();
if (createdValue != null) {
created(createdValue);
}
Integer primaryTermValue = instance.getPrimaryTerm();
if (primaryTermValue != null) {
primaryTerm(primaryTermValue);
}
Cause errorValue = instance.getError();
if (errorValue != null) {
error(errorValue);
}
status(instance.getStatus());
}
if (object instanceof DocumentId) {
DocumentId instance = (DocumentId) object;
type(instance.getType());
index(instance.getIndex());
id(instance.getId());
}
if (object instanceof VersionedDocumentId) {
VersionedDocumentId instance = (VersionedDocumentId) object;
Long versionValue = instance.getVersion();
if (versionValue != null) {
version(versionValue);
}
}
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getCreated() created} attribute.
* @param created The value for created (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("created")
public final Builder created(@Nullable Boolean created) {
this.created = created;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getError() error} attribute.
* @param error The value for error (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("error")
public final Builder error(@Nullable Cause error) {
this.error = error;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getFound() found} attribute.
* @param found The value for found (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("found")
public final Builder found(@Nullable Boolean found) {
this.found = found;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getPrimaryTerm() primaryTerm} attribute.
* @param primaryTerm The value for primaryTerm (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_primary_term")
@JsonView(Views.Elastic.Version6.class)
public final Builder primaryTerm(@Nullable Integer primaryTerm) {
this.primaryTerm = primaryTerm;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getResult() result} attribute.
* @param result The value for result (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("result")
public final Builder result(@Nullable String result) {
this.result = result;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getSeqNo() seqNo} attribute.
* @param seqNo The value for seqNo (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_seq_no")
@JsonView(Views.Elastic.Version6.class)
public final Builder seqNo(@Nullable Integer seqNo) {
this.seqNo = seqNo;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getShards() shards} attribute.
* @param shards The value for shards (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_shards")
public final Builder shards(@Nullable Shards shards) {
this.shards = shards;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getStatus() status} attribute.
* @param status The value for status
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("status")
public final Builder status(int status) {
this.status = status;
initBits &= ~INIT_BIT_STATUS;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getVersion() version} attribute.
* @param version The value for version (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_version")
public final Builder version(@Nullable Long version) {
this.version = version;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getId() id} attribute.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_id")
public final Builder id(String id) {
this.id = Objects.requireNonNull(id, "id");
initBits &= ~INIT_BIT_ID;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getIndex() index} attribute.
* @param index The value for index
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_index")
public final Builder index(String index) {
this.index = Objects.requireNonNull(index, "index");
initBits &= ~INIT_BIT_INDEX;
return this;
}
/**
* Initializes the value for the {@link BulkResponse.BulkOperationResponse#getType() type} attribute.
* @param type The value for type
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_type")
public final Builder type(String type) {
this.type = Objects.requireNonNull(type, "type");
initBits &= ~INIT_BIT_TYPE;
return this;
}
/**
* Builds a new {@link ImmutableBulkOperationResponse ImmutableBulkOperationResponse}.
* @return An immutable instance of BulkOperationResponse
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableBulkOperationResponse build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableBulkOperationResponse(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_STATUS) != 0) attributes.add("status");
if ((initBits & INIT_BIT_ID) != 0) attributes.add("id");
if ((initBits & INIT_BIT_INDEX) != 0) attributes.add("index");
if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type");
return "Cannot build BulkOperationResponse, some of required attributes are not set " + attributes;
}
}
}