com.arakelian.elastic.model.ImmutableAnalyzerSettings Maven / Gradle / Ivy
package com.arakelian.elastic.model;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.Map;
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.AnalyzerSettings}.
*
* Use the builder to create immutable instances:
* {@code ImmutableAnalyzerSettings.builder()}.
*/
@Generated(from = "IndexSettings.AnalyzerSettings", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableAnalyzerSettings
implements IndexSettings.AnalyzerSettings {
private final ImmutableMap analyzers;
private ImmutableAnalyzerSettings(ImmutableAnalyzerSettings.Builder builder) {
this.analyzers = builder.analyzersIsSet()
? builder.analyzers.build()
: ImmutableMap.copyOf(IndexSettings.AnalyzerSettings.super.getAnalyzers());
}
/**
* @return The value of the {@code analyzers} attribute
*/
@JsonProperty("analyzers")
@JsonAnyGetter
@Override
public ImmutableMap getAnalyzers() {
return analyzers;
}
/**
* This instance is equal to all instances of {@code ImmutableAnalyzerSettings} 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 ImmutableAnalyzerSettings
&& equalTo((ImmutableAnalyzerSettings) another);
}
private boolean equalTo(ImmutableAnalyzerSettings another) {
return analyzers.equals(another.analyzers);
}
/**
* Computes a hash code from attributes: {@code analyzers}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + analyzers.hashCode();
return h;
}
/**
* Prints the immutable value {@code AnalyzerSettings} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("AnalyzerSettings")
.omitNullValues()
.add("analyzers", analyzers)
.toString();
}
/**
* Creates a builder for {@link ImmutableAnalyzerSettings ImmutableAnalyzerSettings}.
*
* ImmutableAnalyzerSettings.builder()
* .putAnalyzer|putAllAnalyzers(String => com.arakelian.elastic.model.IndexSettings.NamedAnalyzer) // {@link IndexSettings.AnalyzerSettings#getAnalyzers() analyzers} mappings
* .build();
*
* @return A new ImmutableAnalyzerSettings builder
*/
public static ImmutableAnalyzerSettings.Builder builder() {
return new ImmutableAnalyzerSettings.Builder();
}
/**
* Builds instances of type {@link ImmutableAnalyzerSettings ImmutableAnalyzerSettings}.
* 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.AnalyzerSettings", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long OPT_BIT_ANALYZERS = 0x1L;
private long optBits;
private ImmutableMap.Builder analyzers = ImmutableMap.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code AnalyzerSettings} 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.AnalyzerSettings instance) {
Objects.requireNonNull(instance, "instance");
putAllAnalyzers(instance.getAnalyzers());
return this;
}
/**
* Put one entry to the {@link IndexSettings.AnalyzerSettings#getAnalyzers() analyzers} map.
* @param key The key in the analyzers map
* @param value The associated value in the analyzers map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonAnySetter
public final Builder putAnalyzer(String key, IndexSettings.NamedAnalyzer value) {
this.analyzers.put(key, value);
optBits |= OPT_BIT_ANALYZERS;
return this;
}
/**
* Put one entry to the {@link IndexSettings.AnalyzerSettings#getAnalyzers() analyzers} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAnalyzer(Map.Entry entry) {
this.analyzers.put(entry);
optBits |= OPT_BIT_ANALYZERS;
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link IndexSettings.AnalyzerSettings#getAnalyzers() analyzers} map. Nulls are not permitted
* @param entries The entries that will be added to the analyzers map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("analyzers")
public final Builder analyzers(Map entries) {
this.analyzers = ImmutableMap.builder();
optBits |= OPT_BIT_ANALYZERS;
return putAllAnalyzers(entries);
}
/**
* Put all mappings from the specified map as entries to {@link IndexSettings.AnalyzerSettings#getAnalyzers() analyzers} map. Nulls are not permitted
* @param entries The entries that will be added to the analyzers map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllAnalyzers(Map entries) {
this.analyzers.putAll(entries);
optBits |= OPT_BIT_ANALYZERS;
return this;
}
/**
* Builds a new {@link ImmutableAnalyzerSettings ImmutableAnalyzerSettings}.
* @return An immutable instance of AnalyzerSettings
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableAnalyzerSettings build() {
return new ImmutableAnalyzerSettings(this);
}
private boolean analyzersIsSet() {
return (optBits & OPT_BIT_ANALYZERS) != 0;
}
}
}