com.arakelian.elastic.model.search.ImmutableFuzzyQuery 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 FuzzyQuery}.
*
* Use the builder to create immutable instances:
* {@code ImmutableFuzzyQuery.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableFuzzyQuery implements FuzzyQuery {
private final String fieldName;
private final @Nullable String fuzziness;
private final @Nullable Integer maxExpansions;
private final @Nullable Integer prefixLength;
private final @Nullable Rewrite rewrite;
private final @Nullable Boolean transpositions;
private final @Nullable Object value;
private final boolean hasFuzzyDefaults;
private final @Nullable Float boost;
private final @Nullable String name;
private final boolean hasStandardDefaults;
private ImmutableFuzzyQuery(ImmutableFuzzyQuery.Builder builder) {
this.fieldName = builder.fieldName;
this.fuzziness = builder.fuzziness;
this.maxExpansions = builder.maxExpansions;
this.prefixLength = builder.prefixLength;
this.rewrite = builder.rewrite;
this.transpositions = builder.transpositions;
this.value = builder.value;
this.boost = builder.boost;
this.name = builder.name;
this.hasFuzzyDefaults = initShim.hasFuzzyDefaults();
this.hasStandardDefaults = initShim.hasStandardDefaults();
this.initShim = null;
}
private static final byte STAGE_INITIALIZING = -1;
private static final byte STAGE_UNINITIALIZED = 0;
private static final byte STAGE_INITIALIZED = 1;
@SuppressWarnings("Immutable")
private transient volatile InitShim initShim = new InitShim();
private final class InitShim {
private byte hasFuzzyDefaultsBuildStage = STAGE_UNINITIALIZED;
private boolean hasFuzzyDefaults;
boolean hasFuzzyDefaults() {
if (hasFuzzyDefaultsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (hasFuzzyDefaultsBuildStage == STAGE_UNINITIALIZED) {
hasFuzzyDefaultsBuildStage = STAGE_INITIALIZING;
this.hasFuzzyDefaults = hasFuzzyDefaultsInitialize();
hasFuzzyDefaultsBuildStage = STAGE_INITIALIZED;
}
return this.hasFuzzyDefaults;
}
private byte hasStandardDefaultsBuildStage = STAGE_UNINITIALIZED;
private boolean hasStandardDefaults;
boolean hasStandardDefaults() {
if (hasStandardDefaultsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (hasStandardDefaultsBuildStage == STAGE_UNINITIALIZED) {
hasStandardDefaultsBuildStage = STAGE_INITIALIZING;
this.hasStandardDefaults = hasStandardDefaultsInitialize();
hasStandardDefaultsBuildStage = STAGE_INITIALIZED;
}
return this.hasStandardDefaults;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (hasFuzzyDefaultsBuildStage == STAGE_INITIALIZING) attributes.add("hasFuzzyDefaults");
if (hasStandardDefaultsBuildStage == STAGE_INITIALIZING) attributes.add("hasStandardDefaults");
return "Cannot build FuzzyQuery, attribute initializers form cycle " + attributes;
}
}
private boolean hasFuzzyDefaultsInitialize() {
return FuzzyQuery.super.hasFuzzyDefaults();
}
private boolean hasStandardDefaultsInitialize() {
return FuzzyQuery.super.hasStandardDefaults();
}
/**
* @return The value of the {@code fieldName} attribute
*/
@JsonProperty("field")
@Override
public String getFieldName() {
return fieldName;
}
/**
* @return The value of the {@code fuzziness} attribute
*/
@JsonProperty("fuzziness")
@Override
public @Nullable String getFuzziness() {
return fuzziness;
}
/**
* @return The value of the {@code maxExpansions} attribute
*/
@JsonProperty("maxExpansions")
@Override
public @Nullable Integer getMaxExpansions() {
return maxExpansions;
}
/**
* @return The value of the {@code prefixLength} attribute
*/
@JsonProperty("prefixLength")
@Override
public @Nullable Integer getPrefixLength() {
return prefixLength;
}
/**
* @return The value of the {@code rewrite} attribute
*/
@JsonProperty("rewrite")
@Override
public @Nullable Rewrite getRewrite() {
return rewrite;
}
/**
* @return The value of the {@code transpositions} attribute
*/
@JsonProperty("transpositions")
@Override
public @Nullable Boolean getTranspositions() {
return transpositions;
}
/**
* @return The value of the {@code value} attribute
*/
@JsonProperty("value")
@Override
public @Nullable Object getValue() {
return value;
}
/**
* @return The computed-at-construction value of the {@code hasFuzzyDefaults} attribute
*/
@JsonProperty("hasFuzzyDefaults")
@JsonIgnore
@Override
public boolean hasFuzzyDefaults() {
InitShim shim = this.initShim;
return shim != null
? shim.hasFuzzyDefaults()
: this.hasFuzzyDefaults;
}
/**
* @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() {
InitShim shim = this.initShim;
return shim != null
? shim.hasStandardDefaults()
: this.hasStandardDefaults;
}
/**
* This instance is equal to all instances of {@code ImmutableFuzzyQuery} 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 ImmutableFuzzyQuery
&& equalTo((ImmutableFuzzyQuery) another);
}
private boolean equalTo(ImmutableFuzzyQuery another) {
return fieldName.equals(another.fieldName)
&& Objects.equals(fuzziness, another.fuzziness)
&& Objects.equals(maxExpansions, another.maxExpansions)
&& Objects.equals(prefixLength, another.prefixLength)
&& Objects.equals(rewrite, another.rewrite)
&& Objects.equals(transpositions, another.transpositions)
&& Objects.equals(value, another.value)
&& Objects.equals(boost, another.boost)
&& Objects.equals(name, another.name);
}
/**
* Computes a hash code from attributes: {@code fieldName}, {@code fuzziness}, {@code maxExpansions}, {@code prefixLength}, {@code rewrite}, {@code transpositions}, {@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(fuzziness);
h += (h << 5) + Objects.hashCode(maxExpansions);
h += (h << 5) + Objects.hashCode(prefixLength);
h += (h << 5) + Objects.hashCode(rewrite);
h += (h << 5) + Objects.hashCode(transpositions);
h += (h << 5) + Objects.hashCode(value);
h += (h << 5) + Objects.hashCode(boost);
h += (h << 5) + Objects.hashCode(name);
return h;
}
/**
* Prints the immutable value {@code FuzzyQuery} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("FuzzyQuery")
.omitNullValues()
.add("fieldName", fieldName)
.add("fuzziness", fuzziness)
.add("maxExpansions", maxExpansions)
.add("prefixLength", prefixLength)
.add("rewrite", rewrite)
.add("transpositions", transpositions)
.add("value", value)
.add("boost", boost)
.add("name", name)
.toString();
}
/**
* Creates a builder for {@link ImmutableFuzzyQuery ImmutableFuzzyQuery}.
* @return A new ImmutableFuzzyQuery builder
*/
public static ImmutableFuzzyQuery.Builder builder() {
return new ImmutableFuzzyQuery.Builder();
}
/**
* Builds instances of type {@link ImmutableFuzzyQuery ImmutableFuzzyQuery}.
* 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("fuzzy")
public static final class Builder {
private static final long INIT_BIT_FIELD_NAME = 0x1L;
private long initBits = 0x1L;
private @javax.annotation.Nullable String fieldName;
private @javax.annotation.Nullable String fuzziness;
private @javax.annotation.Nullable Integer maxExpansions;
private @javax.annotation.Nullable Integer prefixLength;
private @javax.annotation.Nullable Rewrite rewrite;
private @javax.annotation.Nullable Boolean transpositions;
private @javax.annotation.Nullable Object 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.FuzzyQuery} 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(FuzzyQuery 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.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;
}
private void from(Object object) {
if (object instanceof FuzzyQuery) {
FuzzyQuery instance = (FuzzyQuery) object;
Integer prefixLengthValue = instance.getPrefixLength();
if (prefixLengthValue != null) {
prefixLength(prefixLengthValue);
}
String fuzzinessValue = instance.getFuzziness();
if (fuzzinessValue != null) {
fuzziness(fuzzinessValue);
}
fieldName(instance.getFieldName());
Boolean transpositionsValue = instance.getTranspositions();
if (transpositionsValue != null) {
transpositions(transpositionsValue);
}
Object valueValue = instance.getValue();
if (valueValue != null) {
value(valueValue);
}
Rewrite rewriteValue = instance.getRewrite();
if (rewriteValue != null) {
rewrite(rewriteValue);
}
Integer maxExpansionsValue = instance.getMaxExpansions();
if (maxExpansionsValue != null) {
maxExpansions(maxExpansionsValue);
}
}
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);
}
}
}
/**
* Initializes the value for the {@link FuzzyQuery#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 FuzzyQuery#getFuzziness() fuzziness} attribute.
* @param fuzziness The value for fuzziness (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("fuzziness")
public final Builder fuzziness(@Nullable String fuzziness) {
this.fuzziness = fuzziness;
return this;
}
/**
* Initializes the value for the {@link FuzzyQuery#getMaxExpansions() maxExpansions} attribute.
* @param maxExpansions The value for maxExpansions (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("maxExpansions")
public final Builder maxExpansions(@Nullable Integer maxExpansions) {
this.maxExpansions = maxExpansions;
return this;
}
/**
* Initializes the value for the {@link FuzzyQuery#getPrefixLength() prefixLength} attribute.
* @param prefixLength The value for prefixLength (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("prefixLength")
public final Builder prefixLength(@Nullable Integer prefixLength) {
this.prefixLength = prefixLength;
return this;
}
/**
* Initializes the value for the {@link FuzzyQuery#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 FuzzyQuery#getTranspositions() transpositions} attribute.
* @param transpositions The value for transpositions (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("transpositions")
public final Builder transpositions(@Nullable Boolean transpositions) {
this.transpositions = transpositions;
return this;
}
/**
* Initializes the value for the {@link FuzzyQuery#getValue() value} attribute.
* @param value The value for value (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("value")
public final Builder value(@Nullable Object value) {
this.value = value;
return this;
}
/**
* Initializes the value for the {@link FuzzyQuery#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 FuzzyQuery#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 ImmutableFuzzyQuery ImmutableFuzzyQuery}.
* @return An immutable instance of FuzzyQuery
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableFuzzyQuery build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableFuzzyQuery(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_FIELD_NAME) != 0) attributes.add("fieldName");
return "Cannot build FuzzyQuery, some of required attributes are not set " + attributes;
}
}
}