package com.arakelian.elastic.model.aggs.bucket;
import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.model.aggs.Aggregation;
import com.arakelian.elastic.model.enums.ExecutionHint;
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 SignificantTermsAggregation}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSignificantTermsAggregation.builder()}.
*/
@Generated(from = "SignificantTermsAggregation", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableSignificantTermsAggregation
implements SignificantTermsAggregation {
private final ImmutableList exclude;
private final @Nullable ExecutionHint executionHint;
private final ImmutableList include;
private final @Nullable Long minDocCount;
private final @Nullable Long shardMinDocCount;
private final @Nullable Long shardSize;
private final @Nullable Integer size;
private final String name;
private final ImmutableList subAggregations;
private final boolean empty;
private ImmutableSignificantTermsAggregation(ImmutableSignificantTermsAggregation.Builder builder) {
this.executionHint = builder.executionHint;
this.minDocCount = builder.minDocCount;
this.shardMinDocCount = builder.shardMinDocCount;
this.shardSize = builder.shardSize;
this.size = builder.size;
this.name = builder.name;
if (builder.excludeIsSet()) {
initShim.exclude(builder.exclude.build());
}
if (builder.includeIsSet()) {
initShim.include(builder.include.build());
}
if (builder.subAggregationsIsSet()) {
initShim.subAggregations(builder.subAggregations.build());
}
this.exclude = initShim.getExclude();
this.include = initShim.getInclude();
this.subAggregations = initShim.getSubAggregations();
this.empty = initShim.isEmpty();
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 = "SignificantTermsAggregation", generator = "Immutables")
private final class InitShim {
private byte excludeBuildStage = STAGE_UNINITIALIZED;
private ImmutableList exclude;
ImmutableList getExclude() {
if (excludeBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (excludeBuildStage == STAGE_UNINITIALIZED) {
excludeBuildStage = STAGE_INITIALIZING;
this.exclude = ImmutableList.copyOf(getExcludeInitialize());
excludeBuildStage = STAGE_INITIALIZED;
}
return this.exclude;
}
void exclude(ImmutableList exclude) {
this.exclude = exclude;
excludeBuildStage = STAGE_INITIALIZED;
}
private byte includeBuildStage = STAGE_UNINITIALIZED;
private ImmutableList include;
ImmutableList getInclude() {
if (includeBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (includeBuildStage == STAGE_UNINITIALIZED) {
includeBuildStage = STAGE_INITIALIZING;
this.include = ImmutableList.copyOf(getIncludeInitialize());
includeBuildStage = STAGE_INITIALIZED;
}
return this.include;
}
void include(ImmutableList include) {
this.include = include;
includeBuildStage = STAGE_INITIALIZED;
}
private byte subAggregationsBuildStage = STAGE_UNINITIALIZED;
private ImmutableList subAggregations;
ImmutableList getSubAggregations() {
if (subAggregationsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (subAggregationsBuildStage == STAGE_UNINITIALIZED) {
subAggregationsBuildStage = STAGE_INITIALIZING;
this.subAggregations = ImmutableList.copyOf(getSubAggregationsInitialize());
subAggregationsBuildStage = STAGE_INITIALIZED;
}
return this.subAggregations;
}
void subAggregations(ImmutableList subAggregations) {
this.subAggregations = subAggregations;
subAggregationsBuildStage = STAGE_INITIALIZED;
}
private byte emptyBuildStage = STAGE_UNINITIALIZED;
private boolean empty;
boolean isEmpty() {
if (emptyBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (emptyBuildStage == STAGE_UNINITIALIZED) {
emptyBuildStage = STAGE_INITIALIZING;
this.empty = isEmptyInitialize();
emptyBuildStage = STAGE_INITIALIZED;
}
return this.empty;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (excludeBuildStage == STAGE_INITIALIZING) attributes.add("exclude");
if (includeBuildStage == STAGE_INITIALIZING) attributes.add("include");
if (subAggregationsBuildStage == STAGE_INITIALIZING) attributes.add("subAggregations");
if (emptyBuildStage == STAGE_INITIALIZING) attributes.add("empty");
return "Cannot build SignificantTermsAggregation, attribute initializers form cycle " + attributes;
}
}
private List getExcludeInitialize() {
return SignificantTermsAggregation.super.getExclude();
}
private List getIncludeInitialize() {
return SignificantTermsAggregation.super.getInclude();
}
private List getSubAggregationsInitialize() {
return SignificantTermsAggregation.super.getSubAggregations();
}
private boolean isEmptyInitialize() {
return SignificantTermsAggregation.super.isEmpty();
}
/**
* @return The value of the {@code exclude} attribute
*/
@JsonProperty("exclude")
@Override
public ImmutableList getExclude() {
InitShim shim = this.initShim;
return shim != null
? shim.getExclude()
: this.exclude;
}
/**
* Returns the mechanism by which terms aggregation is executed.
* @return the mechanism by which terms aggregation is executed.
*/
@JsonProperty("executionHint")
@Override
public @Nullable ExecutionHint getExecutionHint() {
return executionHint;
}
/**
* @return The value of the {@code include} attribute
*/
@JsonProperty("include")
@Override
public ImmutableList getInclude() {
InitShim shim = this.initShim;
return shim != null
? shim.getInclude()
: this.include;
}
/**
* Returns the minimum number of hits required before returning a term.
* @return the minimum number of hits required before returning a term.
*/
@JsonProperty("minDocCount")
@Override
public @Nullable Long getMinDocCount() {
return minDocCount;
}
/**
* Returns the minimum number of hits required on a local shard before a term is returned.
* @return the minimum number of hits required on a local shard before a term is returned.
*/
@JsonProperty("shardMinDocCount")
@Override
public @Nullable Long getShardMinDocCount() {
return shardMinDocCount;
}
/**
* Returns how many terms the coordinating node will request from each shard. Once all the
* shards responded, the coordinating node will then reduce them to a final result which will be
* based on the size parameter - this way, one can increase the accuracy of the returned terms
* and avoid the overhead of streaming a big list of buckets back to the client.
* @return the number of terms the coordinating node will request from each shard.
*/
@JsonProperty("shardSize")
@Override
public @Nullable Long getShardSize() {
return shardSize;
}
/**
* Returns how many term buckets should be returned out of the overall terms list. By default,
* the node coordinating the search process will request each shard to provide its own top size
* term buckets and once all shards respond, it will reduce the results to the final list that
* will then be returned to the client.
* @return how many term buckets should be returned out of the overall terms list.
*/
@JsonProperty("size")
@Override
public @Nullable Integer getSize() {
return size;
}
/**
* Returns the name of the aggregation
* @return name of the aggregation
*/
@JsonProperty("name")
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code subAggregations} attribute
*/
@JsonProperty("subAggregations")
@Override
public ImmutableList getSubAggregations() {
InitShim shim = this.initShim;
return shim != null
? shim.getSubAggregations()
: this.subAggregations;
}
/**
* @return The computed-at-construction value of the {@code empty} attribute
*/
@JsonProperty("empty")
@JsonIgnore
@Override
public boolean isEmpty() {
InitShim shim = this.initShim;
return shim != null
? shim.isEmpty()
: this.empty;
}
/**
* This instance is equal to all instances of {@code ImmutableSignificantTermsAggregation} 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 ImmutableSignificantTermsAggregation
&& equalTo((ImmutableSignificantTermsAggregation) another);
}
private boolean equalTo(ImmutableSignificantTermsAggregation another) {
return exclude.equals(another.exclude)
&& Objects.equals(executionHint, another.executionHint)
&& include.equals(another.include)
&& Objects.equals(minDocCount, another.minDocCount)
&& Objects.equals(shardMinDocCount, another.shardMinDocCount)
&& Objects.equals(shardSize, another.shardSize)
&& Objects.equals(size, another.size)
&& name.equals(another.name)
&& subAggregations.equals(another.subAggregations);
}
/**
* Computes a hash code from attributes: {@code exclude}, {@code executionHint}, {@code include}, {@code minDocCount}, {@code shardMinDocCount}, {@code shardSize}, {@code size}, {@code name}, {@code subAggregations}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + exclude.hashCode();
h += (h << 5) + Objects.hashCode(executionHint);
h += (h << 5) + include.hashCode();
h += (h << 5) + Objects.hashCode(minDocCount);
h += (h << 5) + Objects.hashCode(shardMinDocCount);
h += (h << 5) + Objects.hashCode(shardSize);
h += (h << 5) + Objects.hashCode(size);
h += (h << 5) + name.hashCode();
h += (h << 5) + subAggregations.hashCode();
return h;
}
/**
* Prints the immutable value {@code SignificantTermsAggregation} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SignificantTermsAggregation")
.omitNullValues()
.add("exclude", exclude)
.add("executionHint", executionHint)
.add("include", include)
.add("minDocCount", minDocCount)
.add("shardMinDocCount", shardMinDocCount)
.add("shardSize", shardSize)
.add("size", size)
.add("name", name)
.add("subAggregations", subAggregations)
.toString();
}
/**
* Creates a builder for {@link ImmutableSignificantTermsAggregation ImmutableSignificantTermsAggregation}.
* @return A new ImmutableSignificantTermsAggregation builder
*/
public static ImmutableSignificantTermsAggregation.Builder builder() {
return new ImmutableSignificantTermsAggregation.Builder();
}
/**
* Builds instances of type {@link ImmutableSignificantTermsAggregation ImmutableSignificantTermsAggregation}.
* 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 = "SignificantTermsAggregation", generator = "Immutables")
@NotThreadSafe
@JsonTypeName("significant_terms")
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private static final long OPT_BIT_EXCLUDE = 0x1L;
private static final long OPT_BIT_INCLUDE = 0x2L;
private static final long OPT_BIT_SUB_AGGREGATIONS = 0x4L;
private long initBits = 0x1L;
private long optBits;
private ImmutableList.Builder exclude = ImmutableList.builder();
private @javax.annotation.Nullable ExecutionHint executionHint;
private ImmutableList.Builder include = ImmutableList.builder();
private @javax.annotation.Nullable Long minDocCount;
private @javax.annotation.Nullable Long shardMinDocCount;
private @javax.annotation.Nullable Long shardSize;
private @javax.annotation.Nullable Integer size;
private @javax.annotation.Nullable String name;
private ImmutableList.Builder subAggregations = ImmutableList.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.aggs.bucket.SignificantTermsAggregation} 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(SignificantTermsAggregation instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.aggs.Aggregation} 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(Aggregation instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof SignificantTermsAggregation) {
SignificantTermsAggregation instance = (SignificantTermsAggregation) object;
addAllInclude(instance.getInclude());
Long shardMinDocCountValue = instance.getShardMinDocCount();
if (shardMinDocCountValue != null) {
shardMinDocCount(shardMinDocCountValue);
}
Integer sizeValue = instance.getSize();
if (sizeValue != null) {
size(sizeValue);
}
Long minDocCountValue = instance.getMinDocCount();
if (minDocCountValue != null) {
minDocCount(minDocCountValue);
}
addAllExclude(instance.getExclude());
Long shardSizeValue = instance.getShardSize();
if (shardSizeValue != null) {
shardSize(shardSizeValue);
}
ExecutionHint executionHintValue = instance.getExecutionHint();
if (executionHintValue != null) {
executionHint(executionHintValue);
}
}
if (object instanceof Aggregation) {
Aggregation instance = (Aggregation) object;
name(instance.getName());
addAllSubAggregations(instance.getSubAggregations());
}
}
/**
* Adds one element to {@link SignificantTermsAggregation#getExclude() exclude} list.
* @param element A exclude element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addExclude(Object element) {
this.exclude.add(element);
optBits |= OPT_BIT_EXCLUDE;
return this;
}
/**
* Adds elements to {@link SignificantTermsAggregation#getExclude() exclude} list.
* @param elements An array of exclude elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addExclude(Object... elements) {
this.exclude.add(elements);
optBits |= OPT_BIT_EXCLUDE;
return this;
}
/**
* Sets or replaces all elements for {@link SignificantTermsAggregation#getExclude() exclude} list.
* @param elements An iterable of exclude elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("exclude")
public final Builder exclude(Iterable extends Object> elements) {
this.exclude = ImmutableList.builder();
return addAllExclude(elements);
}
/**
* Adds elements to {@link SignificantTermsAggregation#getExclude() exclude} list.
* @param elements An iterable of exclude elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllExclude(Iterable extends Object> elements) {
this.exclude.addAll(elements);
optBits |= OPT_BIT_EXCLUDE;
return this;
}
/**
* Initializes the value for the {@link SignificantTermsAggregation#getExecutionHint() executionHint} attribute.
* @param executionHint The value for executionHint (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("executionHint")
public final Builder executionHint(@Nullable ExecutionHint executionHint) {
this.executionHint = executionHint;
return this;
}
/**
* Adds one element to {@link SignificantTermsAggregation#getInclude() include} list.
* @param element A include element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addInclude(Object element) {
this.include.add(element);
optBits |= OPT_BIT_INCLUDE;
return this;
}
/**
* Adds elements to {@link SignificantTermsAggregation#getInclude() include} list.
* @param elements An array of include elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addInclude(Object... elements) {
this.include.add(elements);
optBits |= OPT_BIT_INCLUDE;
return this;
}
/**
* Sets or replaces all elements for {@link SignificantTermsAggregation#getInclude() include} list.
* @param elements An iterable of include elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("include")
public final Builder include(Iterable extends Object> elements) {
this.include = ImmutableList.builder();
return addAllInclude(elements);
}
/**
* Adds elements to {@link SignificantTermsAggregation#getInclude() include} list.
* @param elements An iterable of include elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllInclude(Iterable extends Object> elements) {
this.include.addAll(elements);
optBits |= OPT_BIT_INCLUDE;
return this;
}
/**
* Initializes the value for the {@link SignificantTermsAggregation#getMinDocCount() minDocCount} attribute.
* @param minDocCount The value for minDocCount (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("minDocCount")
public final Builder minDocCount(@Nullable Long minDocCount) {
this.minDocCount = minDocCount;
return this;
}
/**
* Initializes the value for the {@link SignificantTermsAggregation#getShardMinDocCount() shardMinDocCount} attribute.
* @param shardMinDocCount The value for shardMinDocCount (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("shardMinDocCount")
public final Builder shardMinDocCount(@Nullable Long shardMinDocCount) {
this.shardMinDocCount = shardMinDocCount;
return this;
}
/**
* Initializes the value for the {@link SignificantTermsAggregation#getShardSize() shardSize} attribute.
* @param shardSize The value for shardSize (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("shardSize")
public final Builder shardSize(@Nullable Long shardSize) {
this.shardSize = shardSize;
return this;
}
/**
* Initializes the value for the {@link SignificantTermsAggregation#getSize() size} attribute.
* @param size The value for size (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("size")
public final Builder size(@Nullable Integer size) {
this.size = size;
return this;
}
/**
* Initializes the value for the {@link SignificantTermsAggregation#getName() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("name")
public final Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Adds one element to {@link SignificantTermsAggregation#getSubAggregations() subAggregations} list.
* @param element A subAggregations element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addSubAggregation(Aggregation element) {
this.subAggregations.add(element);
optBits |= OPT_BIT_SUB_AGGREGATIONS;
return this;
}
/**
* Adds elements to {@link SignificantTermsAggregation#getSubAggregations() subAggregations} list.
* @param elements An array of subAggregations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addSubAggregations(Aggregation... elements) {
this.subAggregations.add(elements);
optBits |= OPT_BIT_SUB_AGGREGATIONS;
return this;
}
/**
* Sets or replaces all elements for {@link SignificantTermsAggregation#getSubAggregations() subAggregations} list.
* @param elements An iterable of subAggregations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("subAggregations")
public final Builder subAggregations(Iterable extends Aggregation> elements) {
this.subAggregations = ImmutableList.builder();
return addAllSubAggregations(elements);
}
/**
* Adds elements to {@link SignificantTermsAggregation#getSubAggregations() subAggregations} list.
* @param elements An iterable of subAggregations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllSubAggregations(Iterable extends Aggregation> elements) {
this.subAggregations.addAll(elements);
optBits |= OPT_BIT_SUB_AGGREGATIONS;
return this;
}
/**
* Builds a new {@link ImmutableSignificantTermsAggregation ImmutableSignificantTermsAggregation}.
* @return An immutable instance of SignificantTermsAggregation
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSignificantTermsAggregation build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableSignificantTermsAggregation(this);
}
private boolean excludeIsSet() {
return (optBits & OPT_BIT_EXCLUDE) != 0;
}
private boolean includeIsSet() {
return (optBits & OPT_BIT_INCLUDE) != 0;
}
private boolean subAggregationsIsSet() {
return (optBits & OPT_BIT_SUB_AGGREGATIONS) != 0;
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
return "Cannot build SignificantTermsAggregation, some of required attributes are not set " + attributes;
}
}
}