com.arakelian.elastic.doc.plugins.ImmutableHasLengthConfig Maven / Gradle / Ivy
package com.arakelian.elastic.doc.plugins;
import com.arakelian.elastic.model.Field;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSet;
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 java.util.Set;
import java.util.function.Predicate;
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 HasLengthPlugin.HasLengthConfig}.
*
* Use the builder to create immutable instances:
* {@code ImmutableHasLengthConfig.builder()}.
*/
@Generated(from = "HasLengthPlugin.HasLengthConfig", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableHasLengthConfig
implements HasLengthPlugin.HasLengthConfig {
private final ImmutableSet excludeFields;
private final ImmutableSet includeFields;
private final String indicator;
private final String indicatorPrefix;
private final int length;
private transient final Predicate namePredicate;
private final Predicate predicate;
private final String separator;
private ImmutableHasLengthConfig(ImmutableHasLengthConfig.Builder builder) {
this.indicator = builder.indicator;
if (builder.excludeFieldsIsSet()) {
initShim.excludeFields(builder.excludeFields.build());
}
if (builder.includeFieldsIsSet()) {
initShim.includeFields(builder.includeFields.build());
}
if (builder.indicatorPrefix != null) {
initShim.indicatorPrefix(builder.indicatorPrefix);
}
if (builder.lengthIsSet()) {
initShim.length(builder.length);
}
if (builder.predicate != null) {
initShim.predicate(builder.predicate);
}
if (builder.separator != null) {
initShim.separator(builder.separator);
}
this.excludeFields = initShim.getExcludeFields();
this.includeFields = initShim.getIncludeFields();
this.indicatorPrefix = initShim.getIndicatorPrefix();
this.length = initShim.getLength();
this.namePredicate = initShim.getNamePredicate();
this.predicate = initShim.getPredicate();
this.separator = initShim.getSeparator();
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 = "HasLengthPlugin.HasLengthConfig", generator = "Immutables")
private final class InitShim {
private byte excludeFieldsBuildStage = STAGE_UNINITIALIZED;
private ImmutableSet excludeFields;
ImmutableSet getExcludeFields() {
if (excludeFieldsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (excludeFieldsBuildStage == STAGE_UNINITIALIZED) {
excludeFieldsBuildStage = STAGE_INITIALIZING;
this.excludeFields = ImmutableSet.copyOf(getExcludeFieldsInitialize());
excludeFieldsBuildStage = STAGE_INITIALIZED;
}
return this.excludeFields;
}
void excludeFields(ImmutableSet excludeFields) {
this.excludeFields = excludeFields;
excludeFieldsBuildStage = STAGE_INITIALIZED;
}
private byte includeFieldsBuildStage = STAGE_UNINITIALIZED;
private ImmutableSet includeFields;
ImmutableSet getIncludeFields() {
if (includeFieldsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (includeFieldsBuildStage == STAGE_UNINITIALIZED) {
includeFieldsBuildStage = STAGE_INITIALIZING;
this.includeFields = ImmutableSet.copyOf(getIncludeFieldsInitialize());
includeFieldsBuildStage = STAGE_INITIALIZED;
}
return this.includeFields;
}
void includeFields(ImmutableSet includeFields) {
this.includeFields = includeFields;
includeFieldsBuildStage = STAGE_INITIALIZED;
}
private byte indicatorPrefixBuildStage = STAGE_UNINITIALIZED;
private String indicatorPrefix;
String getIndicatorPrefix() {
if (indicatorPrefixBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (indicatorPrefixBuildStage == STAGE_UNINITIALIZED) {
indicatorPrefixBuildStage = STAGE_INITIALIZING;
this.indicatorPrefix = Objects.requireNonNull(getIndicatorPrefixInitialize(), "indicatorPrefix");
indicatorPrefixBuildStage = STAGE_INITIALIZED;
}
return this.indicatorPrefix;
}
void indicatorPrefix(String indicatorPrefix) {
this.indicatorPrefix = indicatorPrefix;
indicatorPrefixBuildStage = STAGE_INITIALIZED;
}
private byte lengthBuildStage = STAGE_UNINITIALIZED;
private int length;
int getLength() {
if (lengthBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (lengthBuildStage == STAGE_UNINITIALIZED) {
lengthBuildStage = STAGE_INITIALIZING;
this.length = getLengthInitialize();
lengthBuildStage = STAGE_INITIALIZED;
}
return this.length;
}
void length(int length) {
this.length = length;
lengthBuildStage = STAGE_INITIALIZED;
}
private byte namePredicateBuildStage = STAGE_UNINITIALIZED;
private Predicate namePredicate;
Predicate getNamePredicate() {
if (namePredicateBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (namePredicateBuildStage == STAGE_UNINITIALIZED) {
namePredicateBuildStage = STAGE_INITIALIZING;
this.namePredicate = Objects.requireNonNull(getNamePredicateInitialize(), "namePredicate");
namePredicateBuildStage = STAGE_INITIALIZED;
}
return this.namePredicate;
}
private byte predicateBuildStage = STAGE_UNINITIALIZED;
private Predicate predicate;
Predicate getPredicate() {
if (predicateBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (predicateBuildStage == STAGE_UNINITIALIZED) {
predicateBuildStage = STAGE_INITIALIZING;
this.predicate = Objects.requireNonNull(getPredicateInitialize(), "predicate");
predicateBuildStage = STAGE_INITIALIZED;
}
return this.predicate;
}
void predicate(Predicate predicate) {
this.predicate = predicate;
predicateBuildStage = STAGE_INITIALIZED;
}
private byte separatorBuildStage = STAGE_UNINITIALIZED;
private String separator;
String getSeparator() {
if (separatorBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (separatorBuildStage == STAGE_UNINITIALIZED) {
separatorBuildStage = STAGE_INITIALIZING;
this.separator = Objects.requireNonNull(getSeparatorInitialize(), "separator");
separatorBuildStage = STAGE_INITIALIZED;
}
return this.separator;
}
void separator(String separator) {
this.separator = separator;
separatorBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (excludeFieldsBuildStage == STAGE_INITIALIZING) attributes.add("excludeFields");
if (includeFieldsBuildStage == STAGE_INITIALIZING) attributes.add("includeFields");
if (indicatorPrefixBuildStage == STAGE_INITIALIZING) attributes.add("indicatorPrefix");
if (lengthBuildStage == STAGE_INITIALIZING) attributes.add("length");
if (namePredicateBuildStage == STAGE_INITIALIZING) attributes.add("namePredicate");
if (predicateBuildStage == STAGE_INITIALIZING) attributes.add("predicate");
if (separatorBuildStage == STAGE_INITIALIZING) attributes.add("separator");
return "Cannot build HasLengthConfig, attribute initializers form cycle " + attributes;
}
}
private Set getExcludeFieldsInitialize() {
return HasLengthPlugin.HasLengthConfig.super.getExcludeFields();
}
private Set getIncludeFieldsInitialize() {
return HasLengthPlugin.HasLengthConfig.super.getIncludeFields();
}
private String getIndicatorPrefixInitialize() {
return HasLengthPlugin.HasLengthConfig.super.getIndicatorPrefix();
}
private int getLengthInitialize() {
return HasLengthPlugin.HasLengthConfig.super.getLength();
}
private Predicate getNamePredicateInitialize() {
return HasLengthPlugin.HasLengthConfig.super.getNamePredicate();
}
private Predicate getPredicateInitialize() {
return HasLengthPlugin.HasLengthConfig.super.getPredicate();
}
private String getSeparatorInitialize() {
return HasLengthPlugin.HasLengthConfig.super.getSeparator();
}
/**
* Returns a list of field names that should be excluded from the plugin.
* @return a list of field names that should be excluded from the plugin.
*/
@JsonProperty("excludeFields")
@Override
public ImmutableSet getExcludeFields() {
InitShim shim = this.initShim;
return shim != null
? shim.getExcludeFields()
: this.excludeFields;
}
/**
* Returns a list of field names that should be included by the plugin. Note that if
* includes are specified, we only include those.
* @return a list of field names that should be included by the plugin.
*/
@JsonProperty("includeFields")
@Override
public ImmutableSet getIncludeFields() {
InitShim shim = this.initShim;
return shim != null
? shim.getIncludeFields()
: this.includeFields;
}
/**
* Returns the name of the indicator field in the Elastic index.
* @return the name of the indicator field in the Elastic index.
*/
@JsonProperty("indicator")
@Override
public String getIndicator() {
return indicator;
}
/**
* @return The value of the {@code indicatorPrefix} attribute
*/
@JsonProperty("indicatorPrefix")
@Override
public String getIndicatorPrefix() {
InitShim shim = this.initShim;
return shim != null
? shim.getIndicatorPrefix()
: this.indicatorPrefix;
}
/**
* Returns the length of a text value considered 'lengthy', e.g. beyond which we trigger an
* indicator value for the field.
* @return the length of a text value considered 'lengthy'
*/
@JsonProperty("length")
@Override
public int getLength() {
InitShim shim = this.initShim;
return shim != null
? shim.getLength()
: this.length;
}
/**
* @return The computed-at-construction value of the {@code namePredicate} attribute
*/
@JsonProperty("namePredicate")
@Override
public Predicate getNamePredicate() {
InitShim shim = this.initShim;
return shim != null
? shim.getNamePredicate()
: this.namePredicate;
}
/**
* @return The value of the {@code predicate} attribute
*/
@JsonProperty("predicate")
@Override
public Predicate getPredicate() {
InitShim shim = this.initShim;
return shim != null
? shim.getPredicate()
: this.predicate;
}
/**
* @return The value of the {@code separator} attribute
*/
@JsonProperty("separator")
@Override
public String getSeparator() {
InitShim shim = this.initShim;
return shim != null
? shim.getSeparator()
: this.separator;
}
/**
* This instance is equal to all instances of {@code ImmutableHasLengthConfig} 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 ImmutableHasLengthConfig
&& equalTo((ImmutableHasLengthConfig) another);
}
private boolean equalTo(ImmutableHasLengthConfig another) {
return excludeFields.equals(another.excludeFields)
&& includeFields.equals(another.includeFields)
&& indicator.equals(another.indicator)
&& indicatorPrefix.equals(another.indicatorPrefix)
&& length == another.length
&& separator.equals(another.separator);
}
/**
* Computes a hash code from attributes: {@code excludeFields}, {@code includeFields}, {@code indicator}, {@code indicatorPrefix}, {@code length}, {@code separator}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + excludeFields.hashCode();
h += (h << 5) + includeFields.hashCode();
h += (h << 5) + indicator.hashCode();
h += (h << 5) + indicatorPrefix.hashCode();
h += (h << 5) + length;
h += (h << 5) + separator.hashCode();
return h;
}
/**
* Prints the immutable value {@code HasLengthConfig} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("HasLengthConfig")
.omitNullValues()
.add("excludeFields", excludeFields)
.add("includeFields", includeFields)
.add("indicator", indicator)
.add("indicatorPrefix", indicatorPrefix)
.add("length", length)
.add("separator", separator)
.toString();
}
/**
* Creates a builder for {@link ImmutableHasLengthConfig ImmutableHasLengthConfig}.
* @return A new ImmutableHasLengthConfig builder
*/
public static ImmutableHasLengthConfig.Builder builder() {
return new ImmutableHasLengthConfig.Builder();
}
/**
* Builds instances of type {@link ImmutableHasLengthConfig ImmutableHasLengthConfig}.
* 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 = "HasLengthPlugin.HasLengthConfig", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_INDICATOR = 0x1L;
private static final long OPT_BIT_EXCLUDE_FIELDS = 0x1L;
private static final long OPT_BIT_INCLUDE_FIELDS = 0x2L;
private static final long OPT_BIT_LENGTH = 0x4L;
private long initBits = 0x1L;
private long optBits;
private ImmutableSet.Builder excludeFields = ImmutableSet.builder();
private ImmutableSet.Builder includeFields = ImmutableSet.builder();
private @Nullable String indicator;
private @Nullable String indicatorPrefix;
private int length;
private @Nullable Predicate predicate;
private @Nullable String separator;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code HasLengthConfig} 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(HasLengthPlugin.HasLengthConfig instance) {
Objects.requireNonNull(instance, "instance");
addAllExcludeFields(instance.getExcludeFields());
addAllIncludeFields(instance.getIncludeFields());
indicator(instance.getIndicator());
indicatorPrefix(instance.getIndicatorPrefix());
length(instance.getLength());
predicate(instance.getPredicate());
separator(instance.getSeparator());
return this;
}
/**
* Adds one element to {@link HasLengthPlugin.HasLengthConfig#getExcludeFields() excludeFields} set.
* @param element A excludeFields element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addExcludeField(String element) {
this.excludeFields.add(element);
optBits |= OPT_BIT_EXCLUDE_FIELDS;
return this;
}
/**
* Adds elements to {@link HasLengthPlugin.HasLengthConfig#getExcludeFields() excludeFields} set.
* @param elements An array of excludeFields elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addExcludeFields(String... elements) {
this.excludeFields.add(elements);
optBits |= OPT_BIT_EXCLUDE_FIELDS;
return this;
}
/**
* Sets or replaces all elements for {@link HasLengthPlugin.HasLengthConfig#getExcludeFields() excludeFields} set.
* @param elements An iterable of excludeFields elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("excludeFields")
public final Builder excludeFields(Iterable elements) {
this.excludeFields = ImmutableSet.builder();
return addAllExcludeFields(elements);
}
/**
* Adds elements to {@link HasLengthPlugin.HasLengthConfig#getExcludeFields() excludeFields} set.
* @param elements An iterable of excludeFields elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllExcludeFields(Iterable elements) {
this.excludeFields.addAll(elements);
optBits |= OPT_BIT_EXCLUDE_FIELDS;
return this;
}
/**
* Adds one element to {@link HasLengthPlugin.HasLengthConfig#getIncludeFields() includeFields} set.
* @param element A includeFields element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addIncludeField(String element) {
this.includeFields.add(element);
optBits |= OPT_BIT_INCLUDE_FIELDS;
return this;
}
/**
* Adds elements to {@link HasLengthPlugin.HasLengthConfig#getIncludeFields() includeFields} set.
* @param elements An array of includeFields elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addIncludeFields(String... elements) {
this.includeFields.add(elements);
optBits |= OPT_BIT_INCLUDE_FIELDS;
return this;
}
/**
* Sets or replaces all elements for {@link HasLengthPlugin.HasLengthConfig#getIncludeFields() includeFields} set.
* @param elements An iterable of includeFields elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("includeFields")
public final Builder includeFields(Iterable elements) {
this.includeFields = ImmutableSet.builder();
return addAllIncludeFields(elements);
}
/**
* Adds elements to {@link HasLengthPlugin.HasLengthConfig#getIncludeFields() includeFields} set.
* @param elements An iterable of includeFields elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllIncludeFields(Iterable elements) {
this.includeFields.addAll(elements);
optBits |= OPT_BIT_INCLUDE_FIELDS;
return this;
}
/**
* Initializes the value for the {@link HasLengthPlugin.HasLengthConfig#getIndicator() indicator} attribute.
* @param indicator The value for indicator
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("indicator")
public final Builder indicator(String indicator) {
this.indicator = Objects.requireNonNull(indicator, "indicator");
initBits &= ~INIT_BIT_INDICATOR;
return this;
}
/**
* Initializes the value for the {@link HasLengthPlugin.HasLengthConfig#getIndicatorPrefix() indicatorPrefix} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link HasLengthPlugin.HasLengthConfig#getIndicatorPrefix() indicatorPrefix}.
* @param indicatorPrefix The value for indicatorPrefix
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("indicatorPrefix")
public final Builder indicatorPrefix(String indicatorPrefix) {
this.indicatorPrefix = Objects.requireNonNull(indicatorPrefix, "indicatorPrefix");
return this;
}
/**
* Initializes the value for the {@link HasLengthPlugin.HasLengthConfig#getLength() length} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link HasLengthPlugin.HasLengthConfig#getLength() length}.
* @param length The value for length
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("length")
public final Builder length(int length) {
this.length = length;
optBits |= OPT_BIT_LENGTH;
return this;
}
/**
* Initializes the value for the {@link HasLengthPlugin.HasLengthConfig#getPredicate() predicate} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link HasLengthPlugin.HasLengthConfig#getPredicate() predicate}.
* @param predicate The value for predicate
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("predicate")
public final Builder predicate(Predicate predicate) {
this.predicate = Objects.requireNonNull(predicate, "predicate");
return this;
}
/**
* Initializes the value for the {@link HasLengthPlugin.HasLengthConfig#getSeparator() separator} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link HasLengthPlugin.HasLengthConfig#getSeparator() separator}.
* @param separator The value for separator
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("separator")
public final Builder separator(String separator) {
this.separator = Objects.requireNonNull(separator, "separator");
return this;
}
/**
* Builds a new {@link ImmutableHasLengthConfig ImmutableHasLengthConfig}.
* @return An immutable instance of HasLengthConfig
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableHasLengthConfig build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableHasLengthConfig(this);
}
private boolean excludeFieldsIsSet() {
return (optBits & OPT_BIT_EXCLUDE_FIELDS) != 0;
}
private boolean includeFieldsIsSet() {
return (optBits & OPT_BIT_INCLUDE_FIELDS) != 0;
}
private boolean lengthIsSet() {
return (optBits & OPT_BIT_LENGTH) != 0;
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_INDICATOR) != 0) attributes.add("indicator");
return "Cannot build HasLengthConfig, some of required attributes are not set " + attributes;
}
}
}