com.arakelian.elastic.model.search.ImmutableItem Maven / Gradle / Ivy
package com.arakelian.elastic.model.search;
import com.arakelian.core.feature.Nullable;
import com.arakelian.jackson.MapPath;
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.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 MoreLikeThisQuery.Item}.
*
* Use the builder to create immutable instances:
* {@code ImmutableItem.builder()}.
*/
@Generated(from = "MoreLikeThisQuery.Item", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableItem implements MoreLikeThisQuery.Item {
private final @Nullable MapPath doc;
private final @Nullable String id;
private final @Nullable String index;
private final @Nullable String type;
private ImmutableItem(ImmutableItem.Builder builder) {
this.doc = builder.doc;
this.id = builder.id;
this.index = builder.index;
this.type = builder.type;
}
/**
* @return The value of the {@code doc} attribute
*/
@JsonProperty("doc")
@Override
public @Nullable MapPath getDoc() {
return doc;
}
/**
* @return The value of the {@code id} attribute
*/
@JsonProperty("_id")
@Override
public @Nullable String getId() {
return id;
}
/**
* @return The value of the {@code index} attribute
*/
@JsonProperty("_index")
@Override
public @Nullable String getIndex() {
return index;
}
/**
* @return The value of the {@code type} attribute
*/
@JsonProperty("_type")
@Override
public @Nullable String getType() {
return type;
}
/**
* This instance is equal to all instances of {@code ImmutableItem} 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 ImmutableItem
&& equalTo((ImmutableItem) another);
}
private boolean equalTo(ImmutableItem another) {
return Objects.equals(doc, another.doc)
&& Objects.equals(id, another.id)
&& Objects.equals(index, another.index)
&& Objects.equals(type, another.type);
}
/**
* Computes a hash code from attributes: {@code doc}, {@code id}, {@code index}, {@code type}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(doc);
h += (h << 5) + Objects.hashCode(id);
h += (h << 5) + Objects.hashCode(index);
h += (h << 5) + Objects.hashCode(type);
return h;
}
/**
* Prints the immutable value {@code Item} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Item")
.omitNullValues()
.add("doc", doc)
.add("id", id)
.add("index", index)
.add("type", type)
.toString();
}
private static ImmutableItem validate(ImmutableItem instance) {
instance.checkItem();
return instance;
}
/**
* Creates a builder for {@link ImmutableItem ImmutableItem}.
*
* ImmutableItem.builder()
* .doc(com.arakelian.jackson.MapPath | null) // nullable {@link MoreLikeThisQuery.Item#getDoc() doc}
* .id(String | null) // nullable {@link MoreLikeThisQuery.Item#getId() id}
* .index(String | null) // nullable {@link MoreLikeThisQuery.Item#getIndex() index}
* .type(String | null) // nullable {@link MoreLikeThisQuery.Item#getType() type}
* .build();
*
* @return A new ImmutableItem builder
*/
public static ImmutableItem.Builder builder() {
return new ImmutableItem.Builder();
}
/**
* Builds instances of type {@link ImmutableItem ImmutableItem}.
* 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 = "MoreLikeThisQuery.Item", generator = "Immutables")
@NotThreadSafe
@JsonPropertyOrder({"_index", "_type", "_id", "doc"})
public static final class Builder {
private @javax.annotation.Nullable MapPath doc;
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 Item} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(MoreLikeThisQuery.Item instance) {
Objects.requireNonNull(instance, "instance");
MapPath docValue = instance.getDoc();
if (docValue != null) {
doc(docValue);
}
String idValue = instance.getId();
if (idValue != null) {
id(idValue);
}
String indexValue = instance.getIndex();
if (indexValue != null) {
index(indexValue);
}
String typeValue = instance.getType();
if (typeValue != null) {
type(typeValue);
}
return this;
}
/**
* Initializes the value for the {@link MoreLikeThisQuery.Item#getDoc() doc} attribute.
* @param doc The value for doc (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("doc")
public final Builder doc(@Nullable MapPath doc) {
this.doc = doc;
return this;
}
/**
* Initializes the value for the {@link MoreLikeThisQuery.Item#getId() id} attribute.
* @param id The value for id (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_id")
public final Builder id(@Nullable String id) {
this.id = id;
return this;
}
/**
* Initializes the value for the {@link MoreLikeThisQuery.Item#getIndex() index} attribute.
* @param index The value for index (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_index")
public final Builder index(@Nullable String index) {
this.index = index;
return this;
}
/**
* Initializes the value for the {@link MoreLikeThisQuery.Item#getType() type} attribute.
* @param type The value for type (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_type")
public final Builder type(@Nullable String type) {
this.type = type;
return this;
}
/**
* Builds a new {@link ImmutableItem ImmutableItem}.
* @return An immutable instance of Item
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableItem build() {
return ImmutableItem.validate(new ImmutableItem(this));
}
}
}