com.arakelian.elastic.model.aggs.bucket.ImmutableAdjacencyMatrixAggregation Maven / Gradle / Ivy
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.search.Query;
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.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link AdjacencyMatrixAggregation}.
*
* Use the builder to create immutable instances:
* {@code ImmutableAdjacencyMatrixAggregation.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableAdjacencyMatrixAggregation
implements AdjacencyMatrixAggregation {
private final ImmutableMap filters;
private final @Nullable String separator;
private final String name;
private final ImmutableList subAggregations;
private final boolean empty;
private ImmutableAdjacencyMatrixAggregation(ImmutableAdjacencyMatrixAggregation.Builder builder) {
this.separator = builder.separator;
this.name = builder.name;
if (builder.filtersIsSet()) {
initShim.filters(builder.filters.build());
}
if (builder.subAggregationsIsSet()) {
initShim.subAggregations(builder.subAggregations.build());
}
this.filters = initShim.getFilters();
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();
private final class InitShim {
private byte filtersBuildStage = STAGE_UNINITIALIZED;
private ImmutableMap filters;
ImmutableMap getFilters() {
if (filtersBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (filtersBuildStage == STAGE_UNINITIALIZED) {
filtersBuildStage = STAGE_INITIALIZING;
this.filters = ImmutableMap.copyOf(getFiltersInitialize());
filtersBuildStage = STAGE_INITIALIZED;
}
return this.filters;
}
void filters(ImmutableMap filters) {
this.filters = filters;
filtersBuildStage = 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 (filtersBuildStage == STAGE_INITIALIZING) attributes.add("filters");
if (subAggregationsBuildStage == STAGE_INITIALIZING) attributes.add("subAggregations");
if (emptyBuildStage == STAGE_INITIALIZING) attributes.add("empty");
return "Cannot build AdjacencyMatrixAggregation, attribute initializers form cycle " + attributes;
}
}
private Map getFiltersInitialize() {
return AdjacencyMatrixAggregation.super.getFilters();
}
private List getSubAggregationsInitialize() {
return AdjacencyMatrixAggregation.super.getSubAggregations();
}
private boolean isEmptyInitialize() {
return AdjacencyMatrixAggregation.super.isEmpty();
}
/**
* @return The value of the {@code filters} attribute
*/
@JsonProperty("filters")
@Override
public ImmutableMap getFilters() {
InitShim shim = this.initShim;
return shim != null
? shim.getFilters()
: this.filters;
}
/**
* @return The value of the {@code separator} attribute
*/
@JsonProperty("separator")
@Override
public @Nullable String getSeparator() {
return separator;
}
/**
* 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 ImmutableAdjacencyMatrixAggregation} 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 ImmutableAdjacencyMatrixAggregation
&& equalTo((ImmutableAdjacencyMatrixAggregation) another);
}
private boolean equalTo(ImmutableAdjacencyMatrixAggregation another) {
return filters.equals(another.filters)
&& Objects.equals(separator, another.separator)
&& name.equals(another.name)
&& subAggregations.equals(another.subAggregations);
}
/**
* Computes a hash code from attributes: {@code filters}, {@code separator}, {@code name}, {@code subAggregations}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + filters.hashCode();
h += (h << 5) + Objects.hashCode(separator);
h += (h << 5) + name.hashCode();
h += (h << 5) + subAggregations.hashCode();
return h;
}
/**
* Prints the immutable value {@code AdjacencyMatrixAggregation} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("AdjacencyMatrixAggregation")
.omitNullValues()
.add("filters", filters)
.add("separator", separator)
.add("name", name)
.add("subAggregations", subAggregations)
.toString();
}
/**
* Creates a builder for {@link ImmutableAdjacencyMatrixAggregation ImmutableAdjacencyMatrixAggregation}.
* @return A new ImmutableAdjacencyMatrixAggregation builder
*/
public static ImmutableAdjacencyMatrixAggregation.Builder builder() {
return new ImmutableAdjacencyMatrixAggregation.Builder();
}
/**
* Builds instances of type {@link ImmutableAdjacencyMatrixAggregation ImmutableAdjacencyMatrixAggregation}.
* 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.
*/
@NotThreadSafe
@JsonTypeName("adjacency_matrix")
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private static final long OPT_BIT_FILTERS = 0x1L;
private static final long OPT_BIT_SUB_AGGREGATIONS = 0x2L;
private long initBits = 0x1L;
private long optBits;
private ImmutableMap.Builder filters = ImmutableMap.builder();
private @javax.annotation.Nullable String separator;
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.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;
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.aggs.bucket.AdjacencyMatrixAggregation} 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(AdjacencyMatrixAggregation instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof Aggregation) {
Aggregation instance = (Aggregation) object;
name(instance.getName());
addAllSubAggregations(instance.getSubAggregations());
}
if (object instanceof AdjacencyMatrixAggregation) {
AdjacencyMatrixAggregation instance = (AdjacencyMatrixAggregation) object;
String separatorValue = instance.getSeparator();
if (separatorValue != null) {
separator(separatorValue);
}
putAllFilters(instance.getFilters());
}
}
/**
* Put one entry to the {@link AdjacencyMatrixAggregation#getFilters() filters} map.
* @param key The key in the filters map
* @param value The associated value in the filters map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putFilter(String key, Query value) {
this.filters.put(key, value);
optBits |= OPT_BIT_FILTERS;
return this;
}
/**
* Put one entry to the {@link AdjacencyMatrixAggregation#getFilters() filters} 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 putFilter(Map.Entry entry) {
this.filters.put(entry);
optBits |= OPT_BIT_FILTERS;
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link AdjacencyMatrixAggregation#getFilters() filters} map. Nulls are not permitted
* @param entries The entries that will be added to the filters map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("filters")
public final Builder filters(Map entries) {
this.filters = ImmutableMap.builder();
optBits |= OPT_BIT_FILTERS;
return putAllFilters(entries);
}
/**
* Put all mappings from the specified map as entries to {@link AdjacencyMatrixAggregation#getFilters() filters} map. Nulls are not permitted
* @param entries The entries that will be added to the filters map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllFilters(Map entries) {
this.filters.putAll(entries);
optBits |= OPT_BIT_FILTERS;
return this;
}
/**
* Initializes the value for the {@link AdjacencyMatrixAggregation#getSeparator() separator} attribute.
* @param separator The value for separator (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("separator")
public final Builder separator(@Nullable String separator) {
this.separator = separator;
return this;
}
/**
* Initializes the value for the {@link AdjacencyMatrixAggregation#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 AdjacencyMatrixAggregation#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 AdjacencyMatrixAggregation#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 AdjacencyMatrixAggregation#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 AdjacencyMatrixAggregation#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 ImmutableAdjacencyMatrixAggregation ImmutableAdjacencyMatrixAggregation}.
* @return An immutable instance of AdjacencyMatrixAggregation
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableAdjacencyMatrixAggregation build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableAdjacencyMatrixAggregation(this);
}
private boolean filtersIsSet() {
return (optBits & OPT_BIT_FILTERS) != 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 AdjacencyMatrixAggregation, some of required attributes are not set " + attributes;
}
}
}