com.arakelian.elastic.model.ImmutableMgetDocument Maven / Gradle / Ivy
package com.arakelian.elastic.model;
import com.arakelian.core.feature.Nullable;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
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 Mget.MgetDocument}.
*
* Use the builder to create immutable instances:
* {@code ImmutableMgetDocument.builder()}.
*/
@Generated(from = "Mget.MgetDocument", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableMgetDocument implements Mget.MgetDocument {
private final @Nullable String sourceFields;
private final String id;
private final String index;
private final String type;
private ImmutableMgetDocument(ImmutableMgetDocument.Builder builder) {
this.sourceFields = builder.sourceFields;
this.id = builder.id;
this.index = builder.index;
this.type = builder.type;
}
/**
* @return The value of the {@code sourceFields} attribute
*/
@JsonProperty("_source")
@Override
public @Nullable String getSourceFields() {
return sourceFields;
}
/**
* @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 ImmutableMgetDocument} 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 ImmutableMgetDocument
&& equalTo((ImmutableMgetDocument) another);
}
private boolean equalTo(ImmutableMgetDocument another) {
return Objects.equals(sourceFields, another.sourceFields)
&& id.equals(another.id)
&& index.equals(another.index)
&& type.equals(another.type);
}
/**
* Computes a hash code from attributes: {@code sourceFields}, {@code id}, {@code index}, {@code type}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(sourceFields);
h += (h << 5) + id.hashCode();
h += (h << 5) + index.hashCode();
h += (h << 5) + type.hashCode();
return h;
}
/**
* Prints the immutable value {@code MgetDocument} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("MgetDocument")
.omitNullValues()
.add("sourceFields", sourceFields)
.add("id", id)
.add("index", index)
.add("type", type)
.toString();
}
/**
* Creates a builder for {@link ImmutableMgetDocument ImmutableMgetDocument}.
* @return A new ImmutableMgetDocument builder
*/
public static ImmutableMgetDocument.Builder builder() {
return new ImmutableMgetDocument.Builder();
}
/**
* Builds instances of type {@link ImmutableMgetDocument ImmutableMgetDocument}.
* 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 = "Mget.MgetDocument", generator = "Immutables")
@NotThreadSafe
@JsonPropertyOrder({"_index", "_type", "_id", "_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 sourceFields;
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.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.Mget.MgetDocument} 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(Mget.MgetDocument instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof DocumentId) {
DocumentId instance = (DocumentId) object;
type(instance.getType());
index(instance.getIndex());
id(instance.getId());
}
if (object instanceof Mget.MgetDocument) {
Mget.MgetDocument instance = (Mget.MgetDocument) object;
String sourceFieldsValue = instance.getSourceFields();
if (sourceFieldsValue != null) {
sourceFields(sourceFieldsValue);
}
}
}
/**
* Initializes the value for the {@link Mget.MgetDocument#getSourceFields() sourceFields} attribute.
* @param sourceFields The value for sourceFields (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_source")
public final Builder sourceFields(@Nullable String sourceFields) {
this.sourceFields = sourceFields;
return this;
}
/**
* Initializes the value for the {@link Mget.MgetDocument#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 Mget.MgetDocument#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 Mget.MgetDocument#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 ImmutableMgetDocument ImmutableMgetDocument}.
* @return An immutable instance of MgetDocument
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableMgetDocument build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableMgetDocument(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 MgetDocument, some of required attributes are not set " + attributes;
}
}
}