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

com.arakelian.elastic.model.ImmutableNamedAnalyzer Maven / Gradle / Ivy

package com.arakelian.elastic.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
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.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link IndexSettings.NamedAnalyzer}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableNamedAnalyzer.builder()}. */ @Generated(from = "IndexSettings.NamedAnalyzer", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableNamedAnalyzer implements IndexSettings.NamedAnalyzer { private final ImmutableList charFilter; private final ImmutableList filter; private final String tokenizer; private ImmutableNamedAnalyzer(ImmutableNamedAnalyzer.Builder builder) { this.tokenizer = builder.tokenizer; if (builder.charFilterIsSet()) { initShim.charFilter(builder.charFilter.build()); } if (builder.filterIsSet()) { initShim.filter(builder.filter.build()); } this.charFilter = initShim.getCharFilter(); this.filter = initShim.getFilter(); 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 = "IndexSettings.NamedAnalyzer", generator = "Immutables") private final class InitShim { private byte charFilterBuildStage = STAGE_UNINITIALIZED; private ImmutableList charFilter; ImmutableList getCharFilter() { if (charFilterBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (charFilterBuildStage == STAGE_UNINITIALIZED) { charFilterBuildStage = STAGE_INITIALIZING; this.charFilter = ImmutableList.copyOf(getCharFilterInitialize()); charFilterBuildStage = STAGE_INITIALIZED; } return this.charFilter; } void charFilter(ImmutableList charFilter) { this.charFilter = charFilter; charFilterBuildStage = STAGE_INITIALIZED; } private byte filterBuildStage = STAGE_UNINITIALIZED; private ImmutableList filter; ImmutableList getFilter() { if (filterBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (filterBuildStage == STAGE_UNINITIALIZED) { filterBuildStage = STAGE_INITIALIZING; this.filter = ImmutableList.copyOf(getFilterInitialize()); filterBuildStage = STAGE_INITIALIZED; } return this.filter; } void filter(ImmutableList filter) { this.filter = filter; filterBuildStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (charFilterBuildStage == STAGE_INITIALIZING) attributes.add("charFilter"); if (filterBuildStage == STAGE_INITIALIZING) attributes.add("filter"); return "Cannot build NamedAnalyzer, attribute initializers form cycle " + attributes; } } private List getCharFilterInitialize() { return IndexSettings.NamedAnalyzer.super.getCharFilter(); } private List getFilterInitialize() { return IndexSettings.NamedAnalyzer.super.getFilter(); } /** * @return The value of the {@code charFilter} attribute */ @JsonProperty("char_filter") @Override public ImmutableList getCharFilter() { InitShim shim = this.initShim; return shim != null ? shim.getCharFilter() : this.charFilter; } /** * @return The value of the {@code filter} attribute */ @JsonProperty("filter") @Override public ImmutableList getFilter() { InitShim shim = this.initShim; return shim != null ? shim.getFilter() : this.filter; } /** * @return The value of the {@code tokenizer} attribute */ @JsonProperty("tokenizer") @Override public String getTokenizer() { return tokenizer; } /** * This instance is equal to all instances of {@code ImmutableNamedAnalyzer} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { if (this == another) return true; return another instanceof ImmutableNamedAnalyzer && equalTo((ImmutableNamedAnalyzer) another); } private boolean equalTo(ImmutableNamedAnalyzer another) { return charFilter.equals(another.charFilter) && filter.equals(another.filter) && tokenizer.equals(another.tokenizer); } /** * Computes a hash code from attributes: {@code charFilter}, {@code filter}, {@code tokenizer}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + charFilter.hashCode(); h += (h << 5) + filter.hashCode(); h += (h << 5) + tokenizer.hashCode(); return h; } /** * Prints the immutable value {@code NamedAnalyzer} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("NamedAnalyzer") .omitNullValues() .add("charFilter", charFilter) .add("filter", filter) .add("tokenizer", tokenizer) .toString(); } /** * Creates a builder for {@link ImmutableNamedAnalyzer ImmutableNamedAnalyzer}. *

   * ImmutableNamedAnalyzer.builder()
   *    .addCharFilter|addAllCharFilter(String) // {@link IndexSettings.NamedAnalyzer#getCharFilter() charFilter} elements
   *    .addFilter|addAllFilter(String) // {@link IndexSettings.NamedAnalyzer#getFilter() filter} elements
   *    .tokenizer(String) // required {@link IndexSettings.NamedAnalyzer#getTokenizer() tokenizer}
   *    .build();
   * 
* @return A new ImmutableNamedAnalyzer builder */ public static ImmutableNamedAnalyzer.Builder builder() { return new ImmutableNamedAnalyzer.Builder(); } /** * Builds instances of type {@link ImmutableNamedAnalyzer ImmutableNamedAnalyzer}. * 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 = "IndexSettings.NamedAnalyzer", generator = "Immutables") @NotThreadSafe @JsonPropertyOrder({"tokenizer", "char_filter", "filter"}) public static final class Builder { private static final long INIT_BIT_TOKENIZER = 0x1L; private static final long OPT_BIT_CHAR_FILTER = 0x1L; private static final long OPT_BIT_FILTER = 0x2L; private long initBits = 0x1L; private long optBits; private ImmutableList.Builder charFilter = ImmutableList.builder(); private ImmutableList.Builder filter = ImmutableList.builder(); private @Nullable String tokenizer; private Builder() { } /** * Fill a builder with attribute values from the provided {@code NamedAnalyzer} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(IndexSettings.NamedAnalyzer instance) { Objects.requireNonNull(instance, "instance"); addAllCharFilter(instance.getCharFilter()); addAllFilter(instance.getFilter()); tokenizer(instance.getTokenizer()); return this; } /** * Adds one element to {@link IndexSettings.NamedAnalyzer#getCharFilter() charFilter} list. * @param element A charFilter element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addCharFilter(String element) { this.charFilter.add(element); optBits |= OPT_BIT_CHAR_FILTER; return this; } /** * Adds elements to {@link IndexSettings.NamedAnalyzer#getCharFilter() charFilter} list. * @param elements An array of charFilter elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addCharFilter(String... elements) { this.charFilter.add(elements); optBits |= OPT_BIT_CHAR_FILTER; return this; } /** * Sets or replaces all elements for {@link IndexSettings.NamedAnalyzer#getCharFilter() charFilter} list. * @param elements An iterable of charFilter elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("char_filter") public final Builder charFilter(Iterable elements) { this.charFilter = ImmutableList.builder(); return addAllCharFilter(elements); } /** * Adds elements to {@link IndexSettings.NamedAnalyzer#getCharFilter() charFilter} list. * @param elements An iterable of charFilter elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllCharFilter(Iterable elements) { this.charFilter.addAll(elements); optBits |= OPT_BIT_CHAR_FILTER; return this; } /** * Adds one element to {@link IndexSettings.NamedAnalyzer#getFilter() filter} list. * @param element A filter element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addFilter(String element) { this.filter.add(element); optBits |= OPT_BIT_FILTER; return this; } /** * Adds elements to {@link IndexSettings.NamedAnalyzer#getFilter() filter} list. * @param elements An array of filter elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addFilter(String... elements) { this.filter.add(elements); optBits |= OPT_BIT_FILTER; return this; } /** * Sets or replaces all elements for {@link IndexSettings.NamedAnalyzer#getFilter() filter} list. * @param elements An iterable of filter elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("filter") public final Builder filter(Iterable elements) { this.filter = ImmutableList.builder(); return addAllFilter(elements); } /** * Adds elements to {@link IndexSettings.NamedAnalyzer#getFilter() filter} list. * @param elements An iterable of filter elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllFilter(Iterable elements) { this.filter.addAll(elements); optBits |= OPT_BIT_FILTER; return this; } /** * Initializes the value for the {@link IndexSettings.NamedAnalyzer#getTokenizer() tokenizer} attribute. * @param tokenizer The value for tokenizer * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("tokenizer") public final Builder tokenizer(String tokenizer) { this.tokenizer = Objects.requireNonNull(tokenizer, "tokenizer"); initBits &= ~INIT_BIT_TOKENIZER; return this; } /** * Builds a new {@link ImmutableNamedAnalyzer ImmutableNamedAnalyzer}. * @return An immutable instance of NamedAnalyzer * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableNamedAnalyzer build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableNamedAnalyzer(this); } private boolean charFilterIsSet() { return (optBits & OPT_BIT_CHAR_FILTER) != 0; } private boolean filterIsSet() { return (optBits & OPT_BIT_FILTER) != 0; } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_TOKENIZER) != 0) attributes.add("tokenizer"); return "Cannot build NamedAnalyzer, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy