com.arakelian.elastic.model.search.ImmutablePrefixQuery Maven / Gradle / Ivy
package com.arakelian.elastic.model.search;
import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.model.enums.Rewrite;
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.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link PrefixQuery}.
*
* Use the builder to create immutable instances:
* {@code ImmutablePrefixQuery.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutablePrefixQuery implements PrefixQuery {
private final String fieldName;
private final @Nullable Rewrite rewrite;
private final String value;
private final @Nullable Float boost;
private final @Nullable String name;
private final boolean hasStandardDefaults;
private ImmutablePrefixQuery(ImmutablePrefixQuery.Builder builder) {
this.fieldName = builder.fieldName;
this.rewrite = builder.rewrite;
this.value = builder.value;
this.boost = builder.boost;
this.name = builder.name;
this.hasStandardDefaults = PrefixQuery.super.hasStandardDefaults();
}
/**
* @return The value of the {@code fieldName} attribute
*/
@JsonProperty("field")
@Override
public String getFieldName() {
return fieldName;
}
/**
* @return The value of the {@code rewrite} attribute
*/
@JsonProperty("rewrite")
@Override
public @Nullable Rewrite getRewrite() {
return rewrite;
}
/**
* @return The value of the {@code value} attribute
*/
@JsonProperty("value")
@Override
public String getValue() {
return value;
}
/**
* @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;
}
/**
* This instance is equal to all instances of {@code ImmutablePrefixQuery} 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 ImmutablePrefixQuery
&& equalTo((ImmutablePrefixQuery) another);
}
private boolean equalTo(ImmutablePrefixQuery another) {
return fieldName.equals(another.fieldName)
&& Objects.equals(rewrite, another.rewrite)
&& value.equals(another.value)
&& Objects.equals(boost, another.boost)
&& Objects.equals(name, another.name);
}
/**
* Computes a hash code from attributes: {@code fieldName}, {@code rewrite}, {@code value}, {@code boost}, {@code name}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + fieldName.hashCode();
h += (h << 5) + Objects.hashCode(rewrite);
h += (h << 5) + value.hashCode();
h += (h << 5) + Objects.hashCode(boost);
h += (h << 5) + Objects.hashCode(name);
return h;
}
/**
* Prints the immutable value {@code PrefixQuery} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("PrefixQuery")
.omitNullValues()
.add("fieldName", fieldName)
.add("rewrite", rewrite)
.add("value", value)
.add("boost", boost)
.add("name", name)
.toString();
}
/**
* Creates a builder for {@link ImmutablePrefixQuery ImmutablePrefixQuery}.
* @return A new ImmutablePrefixQuery builder
*/
public static ImmutablePrefixQuery.Builder builder() {
return new ImmutablePrefixQuery.Builder();
}
/**
* Builds instances of type {@link ImmutablePrefixQuery ImmutablePrefixQuery}.
* 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
@JsonTypeName("prefix")
public static final class Builder {
private static final long INIT_BIT_FIELD_NAME = 0x1L;
private static final long INIT_BIT_VALUE = 0x2L;
private long initBits = 0x3L;
private @javax.annotation.Nullable String fieldName;
private @javax.annotation.Nullable Rewrite rewrite;
private @javax.annotation.Nullable String value;
private @javax.annotation.Nullable Float boost;
private @javax.annotation.Nullable String name;
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.PrefixQuery} 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(PrefixQuery 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 PrefixQuery) {
PrefixQuery instance = (PrefixQuery) object;
value(instance.getValue());
Rewrite rewriteValue = instance.getRewrite();
if (rewriteValue != null) {
rewrite(rewriteValue);
}
fieldName(instance.getFieldName());
}
}
/**
* Initializes the value for the {@link PrefixQuery#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;
}
/**
* Initializes the value for the {@link PrefixQuery#getRewrite() rewrite} attribute.
* @param rewrite The value for rewrite (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("rewrite")
public final Builder rewrite(@Nullable Rewrite rewrite) {
this.rewrite = rewrite;
return this;
}
/**
* Initializes the value for the {@link PrefixQuery#getValue() value} attribute.
* @param value The value for value
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("value")
public final Builder value(String value) {
this.value = Objects.requireNonNull(value, "value");
initBits &= ~INIT_BIT_VALUE;
return this;
}
/**
* Initializes the value for the {@link PrefixQuery#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 PrefixQuery#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;
}
/**
* Builds a new {@link ImmutablePrefixQuery ImmutablePrefixQuery}.
* @return An immutable instance of PrefixQuery
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutablePrefixQuery build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutablePrefixQuery(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_FIELD_NAME) != 0) attributes.add("fieldName");
if ((initBits & INIT_BIT_VALUE) != 0) attributes.add("value");
return "Cannot build PrefixQuery, some of required attributes are not set " + attributes;
}
}
}