com.arakelian.elastic.model.ImmutableDocument 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.fasterxml.jackson.databind.JsonNode;
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.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link Document}.
*
* Use the builder to create immutable instances:
* {@code ImmutableDocument.builder()}.
*/
@Generated(from = "Document", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableDocument implements Document {
private final String id;
private final String index;
private final String type;
private final @Nullable Long seqNo;
private final @Nullable Integer primaryTerm;
private final @Nullable Shards shards;
private final @Nullable Long version;
private final @Nullable JsonNode source;
private final @Nullable Boolean found;
private ImmutableDocument(ImmutableDocument.Builder builder) {
this.id = builder.id;
this.index = builder.index;
this.type = builder.type;
this.seqNo = builder.seqNo;
this.primaryTerm = builder.primaryTerm;
this.shards = builder.shards;
this.version = builder.version;
this.source = builder.source;
this.found = builder.found;
}
/**
* @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;
}
/**
* @return The value of the {@code seqNo} attribute
*/
@JsonProperty("_seq_no")
@JsonView(Views.Elastic.Version6.class)
@Override
public @Nullable Long getSeqNo() {
return seqNo;
}
/**
* @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 shards} attribute
*/
@JsonProperty("_shards")
@Override
public @Nullable Shards getShards() {
return shards;
}
/**
* @return The value of the {@code version} attribute
*/
@JsonProperty("_version")
@Override
public @Nullable Long getVersion() {
return version;
}
/**
* @return The value of the {@code source} attribute
*/
@JsonProperty("_source")
@Override
public @Nullable JsonNode getSource() {
return source;
}
/**
* @return The value of the {@code found} attribute
*/
@JsonProperty("found")
@Override
public @Nullable Boolean isFound() {
return found;
}
/**
* This instance is equal to all instances of {@code ImmutableDocument} 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 ImmutableDocument
&& equalTo((ImmutableDocument) another);
}
private boolean equalTo(ImmutableDocument another) {
return id.equals(another.id)
&& index.equals(another.index)
&& type.equals(another.type)
&& Objects.equals(seqNo, another.seqNo)
&& Objects.equals(primaryTerm, another.primaryTerm)
&& Objects.equals(shards, another.shards)
&& Objects.equals(version, another.version)
&& Objects.equals(source, another.source)
&& Objects.equals(found, another.found);
}
/**
* Computes a hash code from attributes: {@code id}, {@code index}, {@code type}, {@code seqNo}, {@code primaryTerm}, {@code shards}, {@code version}, {@code source}, {@code found}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + id.hashCode();
h += (h << 5) + index.hashCode();
h += (h << 5) + type.hashCode();
h += (h << 5) + Objects.hashCode(seqNo);
h += (h << 5) + Objects.hashCode(primaryTerm);
h += (h << 5) + Objects.hashCode(shards);
h += (h << 5) + Objects.hashCode(version);
h += (h << 5) + Objects.hashCode(source);
h += (h << 5) + Objects.hashCode(found);
return h;
}
/**
* Prints the immutable value {@code Document} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Document")
.omitNullValues()
.add("id", id)
.add("index", index)
.add("type", type)
.add("seqNo", seqNo)
.add("primaryTerm", primaryTerm)
.add("shards", shards)
.add("version", version)
.add("source", source)
.add("found", found)
.toString();
}
/**
* Creates a builder for {@link ImmutableDocument ImmutableDocument}.
*
* ImmutableDocument.builder()
* .id(String) // required {@link Document#getId() id}
* .index(String) // required {@link Document#getIndex() index}
* .type(String) // required {@link Document#getType() type}
* .seqNo(Long | null) // nullable {@link Document#getSeqNo() seqNo}
* .primaryTerm(Integer | null) // nullable {@link Document#getPrimaryTerm() primaryTerm}
* .shards(com.arakelian.elastic.model.Shards | null) // nullable {@link Document#getShards() shards}
* .version(Long | null) // nullable {@link Document#getVersion() version}
* .source(com.fasterxml.jackson.databind.JsonNode | null) // nullable {@link Document#getSource() source}
* .found(Boolean | null) // nullable {@link Document#isFound() found}
* .build();
*
* @return A new ImmutableDocument builder
*/
public static ImmutableDocument.Builder builder() {
return new ImmutableDocument.Builder();
}
/**
* Builds instances of type {@link ImmutableDocument ImmutableDocument}.
* 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.
*/
@Generated(from = "Document", generator = "Immutables")
@NotThreadSafe
@JsonPropertyOrder({"_index", "_type", "_id", "_version", "_seq_no", "_primary_term", "found", "_source"})
public static final class Builder {
private static final long INIT_BIT_ID = 0x1L;
private static final long INIT_BIT_INDEX = 0x2L;
private static final long INIT_BIT_TYPE = 0x4L;
private long initBits = 0x7L;
private @javax.annotation.Nullable String id;
private @javax.annotation.Nullable String index;
private @javax.annotation.Nullable String type;
private @javax.annotation.Nullable Long seqNo;
private @javax.annotation.Nullable Integer primaryTerm;
private @javax.annotation.Nullable Shards shards;
private @javax.annotation.Nullable Long version;
private @javax.annotation.Nullable JsonNode source;
private @javax.annotation.Nullable Boolean found;
private Builder() {
}
/**
* 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.Document} 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(Document 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 DocumentId) {
DocumentId instance = (DocumentId) object;
Shards shardsValue = instance.getShards();
if (shardsValue != null) {
shards(shardsValue);
}
index(instance.getIndex());
id(instance.getId());
Long seqNoValue = instance.getSeqNo();
if (seqNoValue != null) {
seqNo(seqNoValue);
}
type(instance.getType());
Integer primaryTermValue = instance.getPrimaryTerm();
if (primaryTermValue != null) {
primaryTerm(primaryTermValue);
}
}
if (object instanceof Document) {
Document instance = (Document) object;
Boolean foundValue = instance.isFound();
if (foundValue != null) {
found(foundValue);
}
JsonNode sourceValue = instance.getSource();
if (sourceValue != null) {
source(sourceValue);
}
}
if (object instanceof VersionedDocumentId) {
VersionedDocumentId instance = (VersionedDocumentId) object;
Long versionValue = instance.getVersion();
if (versionValue != null) {
version(versionValue);
}
}
}
/**
* Initializes the value for the {@link Document#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 Document#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 Document#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;
}
/**
* Initializes the value for the {@link Document#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 Long seqNo) {
this.seqNo = seqNo;
return this;
}
/**
* Initializes the value for the {@link Document#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 Document#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 Document#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 Document#getSource() source} attribute.
* @param source The value for source (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_source")
public final Builder source(@Nullable JsonNode source) {
this.source = source;
return this;
}
/**
* Initializes the value for the {@link Document#isFound() 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;
}
/**
* Builds a new {@link ImmutableDocument ImmutableDocument}.
* @return An immutable instance of Document
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableDocument build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableDocument(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
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 Document, some of required attributes are not set " + attributes;
}
}
}