com.arakelian.elastic.model.search.ImmutableExistsQuery Maven / Gradle / Ivy
package com.arakelian.elastic.model.search;
import com.arakelian.core.feature.Nullable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
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 ExistsQuery}.
*
* Use the builder to create immutable instances:
* {@code ImmutableExistsQuery.builder()}.
*/
@Generated(from = "ExistsQuery", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableExistsQuery implements ExistsQuery {
private final @Nullable Float boost;
private final @Nullable String name;
private final boolean hasStandardDefaults;
private final String fieldName;
private ImmutableExistsQuery(ImmutableExistsQuery.Builder builder) {
this.boost = builder.boost;
this.name = builder.name;
this.fieldName = builder.fieldName;
this.hasStandardDefaults = ExistsQuery.super.hasStandardDefaults();
}
/**
* @return The value of the {@code boost} attribute
*/
@JsonProperty("boost")
@Override
public @Nullable Float getBoost() {
return boost;
}
/**
* Returns the name of the query
* @return name of the query
* @see Named
* Queries
*/
@JsonProperty("_name")
@Override
public @Nullable String getName() {
return name;
}
/**
* @return The computed-at-construction value of the {@code hasStandardDefaults} attribute
*/
@JsonProperty("hasStandardDefaults")
@JsonIgnore
@Override
public boolean hasStandardDefaults() {
return hasStandardDefaults;
}
/**
* @return The value of the {@code fieldName} attribute
*/
@JsonProperty("field")
@Override
public String getFieldName() {
return fieldName;
}
/**
* This instance is equal to all instances of {@code ImmutableExistsQuery} 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 ImmutableExistsQuery
&& equalTo((ImmutableExistsQuery) another);
}
private boolean equalTo(ImmutableExistsQuery another) {
return Objects.equals(boost, another.boost)
&& Objects.equals(name, another.name)
&& fieldName.equals(another.fieldName);
}
/**
* Computes a hash code from attributes: {@code boost}, {@code name}, {@code fieldName}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(boost);
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + fieldName.hashCode();
return h;
}
/**
* Prints the immutable value {@code ExistsQuery} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ExistsQuery")
.omitNullValues()
.add("boost", boost)
.add("name", name)
.add("fieldName", fieldName)
.toString();
}
/**
* Creates a builder for {@link ImmutableExistsQuery ImmutableExistsQuery}.
*
* ImmutableExistsQuery.builder()
* .boost(Float | null) // nullable {@link ExistsQuery#getBoost() boost}
* .name(String | null) // nullable {@link ExistsQuery#getName() name}
* .fieldName(String) // required {@link ExistsQuery#getFieldName() fieldName}
* .build();
*
* @return A new ImmutableExistsQuery builder
*/
public static ImmutableExistsQuery.Builder builder() {
return new ImmutableExistsQuery.Builder();
}
/**
* Builds instances of type {@link ImmutableExistsQuery ImmutableExistsQuery}.
* 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 = "ExistsQuery", generator = "Immutables")
@NotThreadSafe
@JsonTypeName("exists")
public static final class Builder {
private static final long INIT_BIT_FIELD_NAME = 0x1L;
private long initBits = 0x1L;
private @javax.annotation.Nullable Float boost;
private @javax.annotation.Nullable String name;
private @javax.annotation.Nullable String fieldName;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.search.StandardQuery} 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(StandardQuery instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.search.ExistsQuery} 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(ExistsQuery instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof StandardQuery) {
StandardQuery instance = (StandardQuery) object;
String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
Float boostValue = instance.getBoost();
if (boostValue != null) {
boost(boostValue);
}
}
if (object instanceof ExistsQuery) {
ExistsQuery instance = (ExistsQuery) object;
fieldName(instance.getFieldName());
}
}
/**
* Initializes the value for the {@link ExistsQuery#getBoost() boost} attribute.
* @param boost The value for boost (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("boost")
public final Builder boost(@Nullable Float boost) {
this.boost = boost;
return this;
}
/**
* Initializes the value for the {@link ExistsQuery#getName() name} attribute.
* @param name The value for name (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_name")
public final Builder name(@Nullable String name) {
this.name = name;
return this;
}
/**
* Initializes the value for the {@link ExistsQuery#getFieldName() fieldName} attribute.
* @param fieldName The value for fieldName
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("field")
public final Builder fieldName(String fieldName) {
this.fieldName = Objects.requireNonNull(fieldName, "fieldName");
initBits &= ~INIT_BIT_FIELD_NAME;
return this;
}
/**
* Builds a new {@link ImmutableExistsQuery ImmutableExistsQuery}.
* @return An immutable instance of ExistsQuery
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableExistsQuery build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableExistsQuery(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_FIELD_NAME) != 0) attributes.add("fieldName");
return "Cannot build ExistsQuery, some of required attributes are not set " + attributes;
}
}
}