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

com.arakelian.elastic.model.ImmutableNamedNormalizer 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.NamedNormalizer}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableNamedNormalizer.builder()}. */ @Generated(from = "IndexSettings.NamedNormalizer", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableNamedNormalizer implements IndexSettings.NamedNormalizer { private final ImmutableList charFilter; private final ImmutableList filter; private final String type; private ImmutableNamedNormalizer(ImmutableNamedNormalizer.Builder builder) { this.type = builder.type; 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.NamedNormalizer", 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 NamedNormalizer, attribute initializers form cycle " + attributes; } } private List getCharFilterInitialize() { return IndexSettings.NamedNormalizer.super.getCharFilter(); } private List getFilterInitialize() { return IndexSettings.NamedNormalizer.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 type} attribute */ @JsonProperty("type") @Override public String getType() { return type; } /** * This instance is equal to all instances of {@code ImmutableNamedNormalizer} 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 ImmutableNamedNormalizer && equalTo((ImmutableNamedNormalizer) another); } private boolean equalTo(ImmutableNamedNormalizer another) { return charFilter.equals(another.charFilter) && filter.equals(another.filter) && type.equals(another.type); } /** * Computes a hash code from attributes: {@code charFilter}, {@code filter}, {@code type}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + charFilter.hashCode(); h += (h << 5) + filter.hashCode(); h += (h << 5) + type.hashCode(); return h; } /** * Prints the immutable value {@code NamedNormalizer} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("NamedNormalizer") .omitNullValues() .add("charFilter", charFilter) .add("filter", filter) .add("type", type) .toString(); } /** * Creates a builder for {@link ImmutableNamedNormalizer ImmutableNamedNormalizer}. *

   * ImmutableNamedNormalizer.builder()
   *    .addCharFilter|addAllCharFilter(String) // {@link IndexSettings.NamedNormalizer#getCharFilter() charFilter} elements
   *    .addFilter|addAllFilter(String) // {@link IndexSettings.NamedNormalizer#getFilter() filter} elements
   *    .type(String) // required {@link IndexSettings.NamedNormalizer#getType() type}
   *    .build();
   * 
* @return A new ImmutableNamedNormalizer builder */ public static ImmutableNamedNormalizer.Builder builder() { return new ImmutableNamedNormalizer.Builder(); } /** * Builds instances of type {@link ImmutableNamedNormalizer ImmutableNamedNormalizer}. * 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.NamedNormalizer", generator = "Immutables") @NotThreadSafe @JsonPropertyOrder({"type", "char_filter", "filter"}) public static final class Builder { private static final long INIT_BIT_TYPE = 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 type; private Builder() { } /** * Fill a builder with attribute values from the provided {@code NamedNormalizer} 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.NamedNormalizer instance) { Objects.requireNonNull(instance, "instance"); addAllCharFilter(instance.getCharFilter()); addAllFilter(instance.getFilter()); type(instance.getType()); return this; } /** * Adds one element to {@link IndexSettings.NamedNormalizer#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.NamedNormalizer#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.NamedNormalizer#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.NamedNormalizer#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.NamedNormalizer#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.NamedNormalizer#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.NamedNormalizer#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.NamedNormalizer#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.NamedNormalizer#getType() type} attribute. * @param type The value for type * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("type") public final Builder type(String type) { this.type = Objects.requireNonNull(type, "type"); initBits &= ~INIT_BIT_TYPE; return this; } /** * Builds a new {@link ImmutableNamedNormalizer ImmutableNamedNormalizer}. * @return An immutable instance of NamedNormalizer * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableNamedNormalizer build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableNamedNormalizer(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_TYPE) != 0) attributes.add("type"); return "Cannot build NamedNormalizer, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy