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

com.arakelian.elastic.model.search.ImmutableBoolQuery 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.common.collect.ImmutableList;
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 BoolQuery}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableBoolQuery.builder()}. */ @Generated(from = "BoolQuery", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableBoolQuery implements BoolQuery { private final @Nullable Float boost; private final @Nullable String name; private final boolean hasStandardDefaults; private final ImmutableList filterClauses; private final @Nullable String minimumShouldMatch; private final ImmutableList mustClauses; private final ImmutableList mustNotClauses; private final ImmutableList shouldClauses; private final @Nullable Boolean adjustPureNegative; private ImmutableBoolQuery(ImmutableBoolQuery.Builder builder) { this.boost = builder.boost; this.name = builder.name; this.minimumShouldMatch = builder.minimumShouldMatch; this.adjustPureNegative = builder.adjustPureNegative; if (builder.filterClausesIsSet()) { initShim.filterClauses(builder.filterClauses.build()); } if (builder.mustClausesIsSet()) { initShim.mustClauses(builder.mustClauses.build()); } if (builder.mustNotClausesIsSet()) { initShim.mustNotClauses(builder.mustNotClauses.build()); } if (builder.shouldClausesIsSet()) { initShim.shouldClauses(builder.shouldClauses.build()); } this.hasStandardDefaults = initShim.hasStandardDefaults(); this.filterClauses = initShim.getFilterClauses(); this.mustClauses = initShim.getMustClauses(); this.mustNotClauses = initShim.getMustNotClauses(); this.shouldClauses = initShim.getShouldClauses(); 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(); @Generated(from = "BoolQuery", generator = "Immutables") private final class InitShim { 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 byte filterClausesBuildStage = STAGE_UNINITIALIZED; private ImmutableList filterClauses; ImmutableList getFilterClauses() { if (filterClausesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (filterClausesBuildStage == STAGE_UNINITIALIZED) { filterClausesBuildStage = STAGE_INITIALIZING; this.filterClauses = ImmutableList.copyOf(getFilterClausesInitialize()); filterClausesBuildStage = STAGE_INITIALIZED; } return this.filterClauses; } void filterClauses(ImmutableList filterClauses) { this.filterClauses = filterClauses; filterClausesBuildStage = STAGE_INITIALIZED; } private byte mustClausesBuildStage = STAGE_UNINITIALIZED; private ImmutableList mustClauses; ImmutableList getMustClauses() { if (mustClausesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (mustClausesBuildStage == STAGE_UNINITIALIZED) { mustClausesBuildStage = STAGE_INITIALIZING; this.mustClauses = ImmutableList.copyOf(getMustClausesInitialize()); mustClausesBuildStage = STAGE_INITIALIZED; } return this.mustClauses; } void mustClauses(ImmutableList mustClauses) { this.mustClauses = mustClauses; mustClausesBuildStage = STAGE_INITIALIZED; } private byte mustNotClausesBuildStage = STAGE_UNINITIALIZED; private ImmutableList mustNotClauses; ImmutableList getMustNotClauses() { if (mustNotClausesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (mustNotClausesBuildStage == STAGE_UNINITIALIZED) { mustNotClausesBuildStage = STAGE_INITIALIZING; this.mustNotClauses = ImmutableList.copyOf(getMustNotClausesInitialize()); mustNotClausesBuildStage = STAGE_INITIALIZED; } return this.mustNotClauses; } void mustNotClauses(ImmutableList mustNotClauses) { this.mustNotClauses = mustNotClauses; mustNotClausesBuildStage = STAGE_INITIALIZED; } private byte shouldClausesBuildStage = STAGE_UNINITIALIZED; private ImmutableList shouldClauses; ImmutableList getShouldClauses() { if (shouldClausesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (shouldClausesBuildStage == STAGE_UNINITIALIZED) { shouldClausesBuildStage = STAGE_INITIALIZING; this.shouldClauses = ImmutableList.copyOf(getShouldClausesInitialize()); shouldClausesBuildStage = STAGE_INITIALIZED; } return this.shouldClauses; } void shouldClauses(ImmutableList shouldClauses) { this.shouldClauses = shouldClauses; shouldClausesBuildStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (hasStandardDefaultsBuildStage == STAGE_INITIALIZING) attributes.add("hasStandardDefaults"); if (filterClausesBuildStage == STAGE_INITIALIZING) attributes.add("filterClauses"); if (mustClausesBuildStage == STAGE_INITIALIZING) attributes.add("mustClauses"); if (mustNotClausesBuildStage == STAGE_INITIALIZING) attributes.add("mustNotClauses"); if (shouldClausesBuildStage == STAGE_INITIALIZING) attributes.add("shouldClauses"); return "Cannot build BoolQuery, attribute initializers form cycle " + attributes; } } private boolean hasStandardDefaultsInitialize() { return BoolQuery.super.hasStandardDefaults(); } private List getFilterClausesInitialize() { return BoolQuery.super.getFilterClauses(); } private List getMustClausesInitialize() { return BoolQuery.super.getMustClauses(); } private List getMustNotClausesInitialize() { return BoolQuery.super.getMustNotClauses(); } private List getShouldClausesInitialize() { return BoolQuery.super.getShouldClauses(); } /** * @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; } /** * @return The value of the {@code filterClauses} attribute */ @JsonProperty("filter") @Override public ImmutableList getFilterClauses() { InitShim shim = this.initShim; return shim != null ? shim.getFilterClauses() : this.filterClauses; } /** * @return The value of the {@code minimumShouldMatch} attribute */ @JsonProperty("minimum_should_match") @Override public @Nullable String getMinimumShouldMatch() { return minimumShouldMatch; } /** * @return The value of the {@code mustClauses} attribute */ @JsonProperty("must") @Override public ImmutableList getMustClauses() { InitShim shim = this.initShim; return shim != null ? shim.getMustClauses() : this.mustClauses; } /** * @return The value of the {@code mustNotClauses} attribute */ @JsonProperty("must_not") @Override public ImmutableList getMustNotClauses() { InitShim shim = this.initShim; return shim != null ? shim.getMustNotClauses() : this.mustNotClauses; } /** * @return The value of the {@code shouldClauses} attribute */ @JsonProperty("should") @Override public ImmutableList getShouldClauses() { InitShim shim = this.initShim; return shim != null ? shim.getShouldClauses() : this.shouldClauses; } /** * @return The value of the {@code adjustPureNegative} attribute */ @JsonProperty("adjustPureNegative") @Override public @Nullable Boolean isAdjustPureNegative() { return adjustPureNegative; } /** * This instance is equal to all instances of {@code ImmutableBoolQuery} 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 ImmutableBoolQuery && equalTo((ImmutableBoolQuery) another); } private boolean equalTo(ImmutableBoolQuery another) { return Objects.equals(boost, another.boost) && Objects.equals(name, another.name) && filterClauses.equals(another.filterClauses) && Objects.equals(minimumShouldMatch, another.minimumShouldMatch) && mustClauses.equals(another.mustClauses) && mustNotClauses.equals(another.mustNotClauses) && shouldClauses.equals(another.shouldClauses) && Objects.equals(adjustPureNegative, another.adjustPureNegative); } /** * Computes a hash code from attributes: {@code boost}, {@code name}, {@code filterClauses}, {@code minimumShouldMatch}, {@code mustClauses}, {@code mustNotClauses}, {@code shouldClauses}, {@code adjustPureNegative}. * @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) + filterClauses.hashCode(); h += (h << 5) + Objects.hashCode(minimumShouldMatch); h += (h << 5) + mustClauses.hashCode(); h += (h << 5) + mustNotClauses.hashCode(); h += (h << 5) + shouldClauses.hashCode(); h += (h << 5) + Objects.hashCode(adjustPureNegative); return h; } /** * Prints the immutable value {@code BoolQuery} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("BoolQuery") .omitNullValues() .add("boost", boost) .add("name", name) .add("filterClauses", filterClauses) .add("minimumShouldMatch", minimumShouldMatch) .add("mustClauses", mustClauses) .add("mustNotClauses", mustNotClauses) .add("shouldClauses", shouldClauses) .add("adjustPureNegative", adjustPureNegative) .toString(); } /** * Creates a builder for {@link ImmutableBoolQuery ImmutableBoolQuery}. *

   * ImmutableBoolQuery.builder()
   *    .boost(Float | null) // nullable {@link BoolQuery#getBoost() boost}
   *    .name(String | null) // nullable {@link BoolQuery#getName() name}
   *    .addFilterClause|addAllFilterClauses(com.arakelian.elastic.model.search.Query) // {@link BoolQuery#getFilterClauses() filterClauses} elements
   *    .minimumShouldMatch(String | null) // nullable {@link BoolQuery#getMinimumShouldMatch() minimumShouldMatch}
   *    .addMustClause|addAllMustClauses(com.arakelian.elastic.model.search.Query) // {@link BoolQuery#getMustClauses() mustClauses} elements
   *    .addMustNotClause|addAllMustNotClauses(com.arakelian.elastic.model.search.Query) // {@link BoolQuery#getMustNotClauses() mustNotClauses} elements
   *    .addShouldClause|addAllShouldClauses(com.arakelian.elastic.model.search.Query) // {@link BoolQuery#getShouldClauses() shouldClauses} elements
   *    .adjustPureNegative(Boolean | null) // nullable {@link BoolQuery#isAdjustPureNegative() adjustPureNegative}
   *    .build();
   * 
* @return A new ImmutableBoolQuery builder */ public static ImmutableBoolQuery.Builder builder() { return new ImmutableBoolQuery.Builder(); } /** * Builds instances of type {@link ImmutableBoolQuery ImmutableBoolQuery}. * 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 = "BoolQuery", generator = "Immutables") @NotThreadSafe @JsonTypeName("bool") public static final class Builder { private static final long OPT_BIT_FILTER_CLAUSES = 0x1L; private static final long OPT_BIT_MUST_CLAUSES = 0x2L; private static final long OPT_BIT_MUST_NOT_CLAUSES = 0x4L; private static final long OPT_BIT_SHOULD_CLAUSES = 0x8L; private long optBits; private @javax.annotation.Nullable Float boost; private @javax.annotation.Nullable String name; private ImmutableList.Builder filterClauses = ImmutableList.builder(); private @javax.annotation.Nullable String minimumShouldMatch; private ImmutableList.Builder mustClauses = ImmutableList.builder(); private ImmutableList.Builder mustNotClauses = ImmutableList.builder(); private ImmutableList.Builder shouldClauses = ImmutableList.builder(); private @javax.annotation.Nullable Boolean adjustPureNegative; private Builder() { } /** * Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.search.BoolQuery} 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(BoolQuery 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 BoolQuery) { BoolQuery instance = (BoolQuery) object; addAllFilterClauses(instance.getFilterClauses()); addAllShouldClauses(instance.getShouldClauses()); Boolean adjustPureNegativeValue = instance.isAdjustPureNegative(); if (adjustPureNegativeValue != null) { adjustPureNegative(adjustPureNegativeValue); } addAllMustClauses(instance.getMustClauses()); addAllMustNotClauses(instance.getMustNotClauses()); String minimumShouldMatchValue = instance.getMinimumShouldMatch(); if (minimumShouldMatchValue != null) { minimumShouldMatch(minimumShouldMatchValue); } } 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 BoolQuery#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 BoolQuery#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; } /** * Adds one element to {@link BoolQuery#getFilterClauses() filterClauses} list. * @param element A filterClauses element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addFilterClause(Query element) { this.filterClauses.add(element); optBits |= OPT_BIT_FILTER_CLAUSES; return this; } /** * Adds elements to {@link BoolQuery#getFilterClauses() filterClauses} list. * @param elements An array of filterClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addFilterClauses(Query... elements) { this.filterClauses.add(elements); optBits |= OPT_BIT_FILTER_CLAUSES; return this; } /** * Sets or replaces all elements for {@link BoolQuery#getFilterClauses() filterClauses} list. * @param elements An iterable of filterClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("filter") public final Builder filterClauses(Iterable elements) { this.filterClauses = ImmutableList.builder(); return addAllFilterClauses(elements); } /** * Adds elements to {@link BoolQuery#getFilterClauses() filterClauses} list. * @param elements An iterable of filterClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllFilterClauses(Iterable elements) { this.filterClauses.addAll(elements); optBits |= OPT_BIT_FILTER_CLAUSES; return this; } /** * Initializes the value for the {@link BoolQuery#getMinimumShouldMatch() minimumShouldMatch} attribute. * @param minimumShouldMatch The value for minimumShouldMatch (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("minimum_should_match") public final Builder minimumShouldMatch(@Nullable String minimumShouldMatch) { this.minimumShouldMatch = minimumShouldMatch; return this; } /** * Adds one element to {@link BoolQuery#getMustClauses() mustClauses} list. * @param element A mustClauses element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addMustClause(Query element) { this.mustClauses.add(element); optBits |= OPT_BIT_MUST_CLAUSES; return this; } /** * Adds elements to {@link BoolQuery#getMustClauses() mustClauses} list. * @param elements An array of mustClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addMustClauses(Query... elements) { this.mustClauses.add(elements); optBits |= OPT_BIT_MUST_CLAUSES; return this; } /** * Sets or replaces all elements for {@link BoolQuery#getMustClauses() mustClauses} list. * @param elements An iterable of mustClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("must") public final Builder mustClauses(Iterable elements) { this.mustClauses = ImmutableList.builder(); return addAllMustClauses(elements); } /** * Adds elements to {@link BoolQuery#getMustClauses() mustClauses} list. * @param elements An iterable of mustClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllMustClauses(Iterable elements) { this.mustClauses.addAll(elements); optBits |= OPT_BIT_MUST_CLAUSES; return this; } /** * Adds one element to {@link BoolQuery#getMustNotClauses() mustNotClauses} list. * @param element A mustNotClauses element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addMustNotClause(Query element) { this.mustNotClauses.add(element); optBits |= OPT_BIT_MUST_NOT_CLAUSES; return this; } /** * Adds elements to {@link BoolQuery#getMustNotClauses() mustNotClauses} list. * @param elements An array of mustNotClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addMustNotClauses(Query... elements) { this.mustNotClauses.add(elements); optBits |= OPT_BIT_MUST_NOT_CLAUSES; return this; } /** * Sets or replaces all elements for {@link BoolQuery#getMustNotClauses() mustNotClauses} list. * @param elements An iterable of mustNotClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("must_not") public final Builder mustNotClauses(Iterable elements) { this.mustNotClauses = ImmutableList.builder(); return addAllMustNotClauses(elements); } /** * Adds elements to {@link BoolQuery#getMustNotClauses() mustNotClauses} list. * @param elements An iterable of mustNotClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllMustNotClauses(Iterable elements) { this.mustNotClauses.addAll(elements); optBits |= OPT_BIT_MUST_NOT_CLAUSES; return this; } /** * Adds one element to {@link BoolQuery#getShouldClauses() shouldClauses} list. * @param element A shouldClauses element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addShouldClause(Query element) { this.shouldClauses.add(element); optBits |= OPT_BIT_SHOULD_CLAUSES; return this; } /** * Adds elements to {@link BoolQuery#getShouldClauses() shouldClauses} list. * @param elements An array of shouldClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addShouldClauses(Query... elements) { this.shouldClauses.add(elements); optBits |= OPT_BIT_SHOULD_CLAUSES; return this; } /** * Sets or replaces all elements for {@link BoolQuery#getShouldClauses() shouldClauses} list. * @param elements An iterable of shouldClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("should") public final Builder shouldClauses(Iterable elements) { this.shouldClauses = ImmutableList.builder(); return addAllShouldClauses(elements); } /** * Adds elements to {@link BoolQuery#getShouldClauses() shouldClauses} list. * @param elements An iterable of shouldClauses elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllShouldClauses(Iterable elements) { this.shouldClauses.addAll(elements); optBits |= OPT_BIT_SHOULD_CLAUSES; return this; } /** * Initializes the value for the {@link BoolQuery#isAdjustPureNegative() adjustPureNegative} attribute. * @param adjustPureNegative The value for adjustPureNegative (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("adjustPureNegative") public final Builder adjustPureNegative(@Nullable Boolean adjustPureNegative) { this.adjustPureNegative = adjustPureNegative; return this; } /** * Builds a new {@link ImmutableBoolQuery ImmutableBoolQuery}. * @return An immutable instance of BoolQuery * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableBoolQuery build() { return new ImmutableBoolQuery(this); } private boolean filterClausesIsSet() { return (optBits & OPT_BIT_FILTER_CLAUSES) != 0; } private boolean mustClausesIsSet() { return (optBits & OPT_BIT_MUST_CLAUSES) != 0; } private boolean mustNotClausesIsSet() { return (optBits & OPT_BIT_MUST_NOT_CLAUSES) != 0; } private boolean shouldClausesIsSet() { return (optBits & OPT_BIT_SHOULD_CLAUSES) != 0; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy