All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.arakelian.elastic.model.search.ImmutableRangeQuery Maven / Gradle / Ivy

package com.arakelian.elastic.model.search;

import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.model.enums.ShapeRelation;
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.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.io.ObjectStreamException;
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 RangeQuery}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableRangeQuery.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableRangeQuery implements RangeQuery { private final String fieldName; private final @Nullable Object lower; private final @Nullable ShapeRelation relation; private final @Nullable Object upper; private final boolean includeLower; private final boolean includeUpper; private final @Nullable Float boost; private final @Nullable String name; private final boolean hasStandardDefaults; private ImmutableRangeQuery(ImmutableRangeQuery.Builder builder) { this.fieldName = builder.fieldName; this.lower = builder.lower; this.relation = builder.relation; this.upper = builder.upper; this.boost = builder.boost; this.name = builder.name; if (builder.includeLowerIsSet()) { initShim.includeLower(builder.includeLower); } if (builder.includeUpperIsSet()) { initShim.includeUpper(builder.includeUpper); } this.includeLower = initShim.isIncludeLower(); this.includeUpper = initShim.isIncludeUpper(); 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 includeLowerBuildStage = STAGE_UNINITIALIZED; private boolean includeLower; boolean isIncludeLower() { if (includeLowerBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (includeLowerBuildStage == STAGE_UNINITIALIZED) { includeLowerBuildStage = STAGE_INITIALIZING; this.includeLower = isIncludeLowerInitialize(); includeLowerBuildStage = STAGE_INITIALIZED; } return this.includeLower; } void includeLower(boolean includeLower) { this.includeLower = includeLower; includeLowerBuildStage = STAGE_INITIALIZED; } private byte includeUpperBuildStage = STAGE_UNINITIALIZED; private boolean includeUpper; boolean isIncludeUpper() { if (includeUpperBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (includeUpperBuildStage == STAGE_UNINITIALIZED) { includeUpperBuildStage = STAGE_INITIALIZING; this.includeUpper = isIncludeUpperInitialize(); includeUpperBuildStage = STAGE_INITIALIZED; } return this.includeUpper; } void includeUpper(boolean includeUpper) { this.includeUpper = includeUpper; includeUpperBuildStage = STAGE_INITIALIZED; } 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 (includeLowerBuildStage == STAGE_INITIALIZING) attributes.add("includeLower"); if (includeUpperBuildStage == STAGE_INITIALIZING) attributes.add("includeUpper"); if (hasStandardDefaultsBuildStage == STAGE_INITIALIZING) attributes.add("hasStandardDefaults"); return "Cannot build RangeQuery, attribute initializers form cycle " + attributes; } } private boolean isIncludeLowerInitialize() { return RangeQuery.super.isIncludeLower(); } private boolean isIncludeUpperInitialize() { return RangeQuery.super.isIncludeUpper(); } private boolean hasStandardDefaultsInitialize() { return RangeQuery.super.hasStandardDefaults(); } /** * @return The value of the {@code fieldName} attribute */ @JsonProperty("fieldName") @Override public String getFieldName() { return fieldName; } /** * @return The value of the {@code lower} attribute */ @JsonProperty("from") @Override public @Nullable Object getLower() { return lower; } /** * @return The value of the {@code relation} attribute */ @JsonProperty("relation") @Override public @Nullable ShapeRelation getRelation() { return relation; } /** * @return The value of the {@code upper} attribute */ @JsonProperty("to") @Override public @Nullable Object getUpper() { return upper; } /** * @return The value of the {@code includeLower} attribute */ @JsonProperty("includeLower") @Override public boolean isIncludeLower() { InitShim shim = this.initShim; return shim != null ? shim.isIncludeLower() : this.includeLower; } /** * @return The value of the {@code includeUpper} attribute */ @JsonProperty("includeUpper") @Override public boolean isIncludeUpper() { InitShim shim = this.initShim; return shim != null ? shim.isIncludeUpper() : this.includeUpper; } /** * @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 ImmutableRangeQuery} 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 ImmutableRangeQuery && equalTo((ImmutableRangeQuery) another); } private boolean equalTo(ImmutableRangeQuery another) { return fieldName.equals(another.fieldName) && Objects.equals(lower, another.lower) && Objects.equals(relation, another.relation) && Objects.equals(upper, another.upper) && includeLower == another.includeLower && includeUpper == another.includeUpper && Objects.equals(boost, another.boost) && Objects.equals(name, another.name); } /** * Computes a hash code from attributes: {@code fieldName}, {@code lower}, {@code relation}, {@code upper}, {@code includeLower}, {@code includeUpper}, {@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(lower); h += (h << 5) + Objects.hashCode(relation); h += (h << 5) + Objects.hashCode(upper); h += (h << 5) + Booleans.hashCode(includeLower); h += (h << 5) + Booleans.hashCode(includeUpper); h += (h << 5) + Objects.hashCode(boost); h += (h << 5) + Objects.hashCode(name); return h; } /** * Prints the immutable value {@code RangeQuery} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("RangeQuery") .omitNullValues() .add("fieldName", fieldName) .add("lower", lower) .add("relation", relation) .add("upper", upper) .add("includeLower", includeLower) .add("includeUpper", includeUpper) .add("boost", boost) .add("name", name) .toString(); } private static ImmutableRangeQuery validate(ImmutableRangeQuery instance) { instance.checkType(); return instance; } private Object readResolve() throws ObjectStreamException { return validate(this); } /** * Creates a builder for {@link ImmutableRangeQuery ImmutableRangeQuery}. * @return A new ImmutableRangeQuery builder */ public static ImmutableRangeQuery.Builder builder() { return new ImmutableRangeQuery.Builder(); } /** * Builds instances of type {@link ImmutableRangeQuery ImmutableRangeQuery}. * 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("range") public static final class Builder { private static final long INIT_BIT_FIELD_NAME = 0x1L; private static final long OPT_BIT_INCLUDE_LOWER = 0x1L; private static final long OPT_BIT_INCLUDE_UPPER = 0x2L; private long initBits = 0x1L; private long optBits; private @javax.annotation.Nullable String fieldName; private @javax.annotation.Nullable Object lower; private @javax.annotation.Nullable ShapeRelation relation; private @javax.annotation.Nullable Object upper; private boolean includeLower; private boolean includeUpper; 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.RangeQuery} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder using(RangeQuery 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 using(StandardQuery instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { if (object instanceof RangeQuery) { RangeQuery instance = (RangeQuery) object; includeUpper(instance.isIncludeUpper()); fieldName(instance.getFieldName()); includeLower(instance.isIncludeLower()); Object lowerValue = instance.getLower(); if (lowerValue != null) { lower(lowerValue); } Object upperValue = instance.getUpper(); if (upperValue != null) { upper(upperValue); } ShapeRelation relationValue = instance.getRelation(); if (relationValue != null) { relation(relationValue); } } 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 RangeQuery#getFieldName() fieldName} attribute. * @param fieldName The value for fieldName * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("fieldName") 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 RangeQuery#getLower() lower} attribute. * @param lower The value for lower (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("from") public final Builder lower(@Nullable Object lower) { this.lower = lower; return this; } /** * Initializes the value for the {@link RangeQuery#getRelation() relation} attribute. * @param relation The value for relation (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("relation") public final Builder relation(@Nullable ShapeRelation relation) { this.relation = relation; return this; } /** * Initializes the value for the {@link RangeQuery#getUpper() upper} attribute. * @param upper The value for upper (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("to") public final Builder upper(@Nullable Object upper) { this.upper = upper; return this; } /** * Initializes the value for the {@link RangeQuery#isIncludeLower() includeLower} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link RangeQuery#isIncludeLower() includeLower}. * @param includeLower The value for includeLower * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("includeLower") public final Builder includeLower(boolean includeLower) { this.includeLower = includeLower; optBits |= OPT_BIT_INCLUDE_LOWER; return this; } /** * Initializes the value for the {@link RangeQuery#isIncludeUpper() includeUpper} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link RangeQuery#isIncludeUpper() includeUpper}. * @param includeUpper The value for includeUpper * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("includeUpper") public final Builder includeUpper(boolean includeUpper) { this.includeUpper = includeUpper; optBits |= OPT_BIT_INCLUDE_UPPER; return this; } /** * Initializes the value for the {@link RangeQuery#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 RangeQuery#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 ImmutableRangeQuery ImmutableRangeQuery}. * @return An immutable instance of RangeQuery * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableRangeQuery build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return ImmutableRangeQuery.validate(new ImmutableRangeQuery(this)); } private boolean includeLowerIsSet() { return (optBits & OPT_BIT_INCLUDE_LOWER) != 0; } private boolean includeUpperIsSet() { return (optBits & OPT_BIT_INCLUDE_UPPER) != 0; } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_FIELD_NAME) != 0) attributes.add("fieldName"); return "Cannot build RangeQuery, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy