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

com.arakelian.elastic.model.aggs.metrics.ImmutablePercentilesAggregation Maven / Gradle / Ivy

package com.arakelian.elastic.model.aggs.metrics;

import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.model.aggs.Aggregation;
import com.arakelian.elastic.model.aggs.ValuesSourceAggregation;
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.primitives.Doubles;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.io.ObjectStreamException;
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 PercentilesAggregation}.
 * 

* Use the builder to create immutable instances: * {@code ImmutablePercentilesAggregation.builder()}. */ @Generated(from = "PercentilesAggregation", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutablePercentilesAggregation implements PercentilesAggregation { private final String name; private final ImmutableList subAggregations; private final boolean empty; private final String field; private final @Nullable String format; private final @Nullable Object missing; private final @Nullable String timeZone; private final @Nullable Double compression; private final @Nullable PercentileRanksAggregation.Method method; private final @Nullable Integer numberOfSignificantValueDigits; private final ImmutableList percents; private final @Nullable Boolean keyed; private ImmutablePercentilesAggregation(ImmutablePercentilesAggregation.Builder builder) { this.name = builder.name; this.field = builder.field; this.format = builder.format; this.missing = builder.missing; this.timeZone = builder.timeZone; this.compression = builder.compression; this.numberOfSignificantValueDigits = builder.numberOfSignificantValueDigits; this.percents = builder.percents.build(); this.keyed = builder.keyed; if (builder.subAggregationsIsSet()) { initShim.subAggregations(builder.subAggregations.build()); } this.subAggregations = initShim.getSubAggregations(); this.empty = initShim.isEmpty(); this.method = initShim.getMethod(); 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 = "PercentilesAggregation", generator = "Immutables") private final class InitShim { 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 byte methodBuildStage = STAGE_UNINITIALIZED; private PercentileRanksAggregation.Method method; PercentileRanksAggregation.Method getMethod() { if (methodBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (methodBuildStage == STAGE_UNINITIALIZED) { methodBuildStage = STAGE_INITIALIZING; this.method = getMethodInitialize(); methodBuildStage = STAGE_INITIALIZED; } return this.method; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (subAggregationsBuildStage == STAGE_INITIALIZING) attributes.add("subAggregations"); if (emptyBuildStage == STAGE_INITIALIZING) attributes.add("empty"); if (methodBuildStage == STAGE_INITIALIZING) attributes.add("method"); return "Cannot build PercentilesAggregation, attribute initializers form cycle " + attributes; } } private List getSubAggregationsInitialize() { return PercentilesAggregation.super.getSubAggregations(); } private boolean isEmptyInitialize() { return PercentilesAggregation.super.isEmpty(); } private @Nullable PercentileRanksAggregation.Method getMethodInitialize() { return PercentilesAggregation.super.getMethod(); } /** * 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; } /** * @return The value of the {@code field} attribute */ @JsonProperty("field") @Override public String getField() { return field; } /** * @return The value of the {@code format} attribute */ @JsonProperty("format") @Override public @Nullable String getFormat() { return format; } /** * @return The value of the {@code missing} attribute */ @JsonProperty("missing") @Override public @Nullable Object getMissing() { return missing; } /** * @return The value of the {@code timeZone} attribute */ @JsonProperty("timeZone") @Override public @Nullable String getTimeZone() { return timeZone; } /** * Returns the compression. Higher values improve accuracy but also memory usage. Only relevant * when using * {@link com.arakelian.elastic.model.aggs.metrics.PercentileRanksAggregation.Method#TDIGEST}. * @return the compression * @see Compression */ @JsonProperty("compression") @Override public @Nullable Double getCompression() { return compression; } /** * @return The computed-at-construction value of the {@code method} attribute */ @JsonProperty("method") @Override public @Nullable PercentileRanksAggregation.Method getMethod() { InitShim shim = this.initShim; return shim != null ? shim.getMethod() : this.method; } /** * Returns the number of significant digits in the values. Only relevant when using * {@link com.arakelian.elastic.model.aggs.metrics.PercentileRanksAggregation.Method#HDR}. * @return the number of significant digits in the values */ @JsonProperty("numberOfSignificantValueDigits") @Override public @Nullable Integer getNumberOfSignificantValueDigits() { return numberOfSignificantValueDigits; } /** * @return The value of the {@code percents} attribute */ @JsonProperty("percents") @Override public ImmutableList getPercents() { return percents; } /** * @return The value of the {@code keyed} attribute */ @JsonProperty("keyed") @Override public @Nullable Boolean isKeyed() { return keyed; } /** * This instance is equal to all instances of {@code ImmutablePercentilesAggregation} 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 ImmutablePercentilesAggregation && equalTo((ImmutablePercentilesAggregation) another); } private boolean equalTo(ImmutablePercentilesAggregation another) { return name.equals(another.name) && subAggregations.equals(another.subAggregations) && field.equals(another.field) && Objects.equals(format, another.format) && Objects.equals(missing, another.missing) && Objects.equals(timeZone, another.timeZone) && Objects.equals(compression, another.compression) && Objects.equals(method, another.method) && Objects.equals(numberOfSignificantValueDigits, another.numberOfSignificantValueDigits) && percents.equals(another.percents) && Objects.equals(keyed, another.keyed); } /** * Computes a hash code from attributes: {@code name}, {@code subAggregations}, {@code field}, {@code format}, {@code missing}, {@code timeZone}, {@code compression}, {@code method}, {@code numberOfSignificantValueDigits}, {@code percents}, {@code keyed}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + name.hashCode(); h += (h << 5) + subAggregations.hashCode(); h += (h << 5) + field.hashCode(); h += (h << 5) + Objects.hashCode(format); h += (h << 5) + Objects.hashCode(missing); h += (h << 5) + Objects.hashCode(timeZone); h += (h << 5) + Objects.hashCode(compression); h += (h << 5) + Objects.hashCode(method); h += (h << 5) + Objects.hashCode(numberOfSignificantValueDigits); h += (h << 5) + percents.hashCode(); h += (h << 5) + Objects.hashCode(keyed); return h; } /** * Prints the immutable value {@code PercentilesAggregation} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("PercentilesAggregation") .omitNullValues() .add("name", name) .add("subAggregations", subAggregations) .add("field", field) .add("format", format) .add("missing", missing) .add("timeZone", timeZone) .add("compression", compression) .add("method", method) .add("numberOfSignificantValueDigits", numberOfSignificantValueDigits) .add("percents", percents) .add("keyed", keyed) .toString(); } private static ImmutablePercentilesAggregation validate(ImmutablePercentilesAggregation instance) { instance.checkMethod(); return instance; } private Object readResolve() throws ObjectStreamException { return validate(this); } /** * Creates a builder for {@link ImmutablePercentilesAggregation ImmutablePercentilesAggregation}. *

   * ImmutablePercentilesAggregation.builder()
   *    .name(String) // required {@link PercentilesAggregation#getName() name}
   *    .addSubAggregation|addAllSubAggregations(com.arakelian.elastic.model.aggs.Aggregation) // {@link PercentilesAggregation#getSubAggregations() subAggregations} elements
   *    .field(String) // required {@link PercentilesAggregation#getField() field}
   *    .format(String | null) // nullable {@link PercentilesAggregation#getFormat() format}
   *    .missing(Object | null) // nullable {@link PercentilesAggregation#getMissing() missing}
   *    .timeZone(String | null) // nullable {@link PercentilesAggregation#getTimeZone() timeZone}
   *    .compression(Double | null) // nullable {@link PercentilesAggregation#getCompression() compression}
   *    .numberOfSignificantValueDigits(Integer | null) // nullable {@link PercentilesAggregation#getNumberOfSignificantValueDigits() numberOfSignificantValueDigits}
   *    .addPercent|addAllPercents(double) // {@link PercentilesAggregation#getPercents() percents} elements
   *    .keyed(Boolean | null) // nullable {@link PercentilesAggregation#isKeyed() keyed}
   *    .build();
   * 
* @return A new ImmutablePercentilesAggregation builder */ public static ImmutablePercentilesAggregation.Builder builder() { return new ImmutablePercentilesAggregation.Builder(); } /** * Builds instances of type {@link ImmutablePercentilesAggregation ImmutablePercentilesAggregation}. * 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 = "PercentilesAggregation", generator = "Immutables") @NotThreadSafe @JsonTypeName("percentiles") public static final class Builder { private static final long INIT_BIT_NAME = 0x1L; private static final long INIT_BIT_FIELD = 0x2L; private static final long OPT_BIT_SUB_AGGREGATIONS = 0x1L; private long initBits = 0x3L; private long optBits; private @javax.annotation.Nullable String name; private ImmutableList.Builder subAggregations = ImmutableList.builder(); private @javax.annotation.Nullable String field; private @javax.annotation.Nullable String format; private @javax.annotation.Nullable Object missing; private @javax.annotation.Nullable String timeZone; private @javax.annotation.Nullable Double compression; private @javax.annotation.Nullable Integer numberOfSignificantValueDigits; private ImmutableList.Builder percents = ImmutableList.builder(); private @javax.annotation.Nullable Boolean keyed; private Builder() { } /** * Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.aggs.metrics.PercentilesAggregation} 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(PercentilesAggregation 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; } /** * Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.aggs.ValuesSourceAggregation} 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(ValuesSourceAggregation instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { if (object instanceof PercentilesAggregation) { PercentilesAggregation instance = (PercentilesAggregation) object; Integer numberOfSignificantValueDigitsValue = instance.getNumberOfSignificantValueDigits(); if (numberOfSignificantValueDigitsValue != null) { numberOfSignificantValueDigits(numberOfSignificantValueDigitsValue); } addAllPercents(instance.getPercents()); Double compressionValue = instance.getCompression(); if (compressionValue != null) { compression(compressionValue); } Boolean keyedValue = instance.isKeyed(); if (keyedValue != null) { keyed(keyedValue); } } if (object instanceof Aggregation) { Aggregation instance = (Aggregation) object; name(instance.getName()); addAllSubAggregations(instance.getSubAggregations()); } if (object instanceof ValuesSourceAggregation) { ValuesSourceAggregation instance = (ValuesSourceAggregation) object; String formatValue = instance.getFormat(); if (formatValue != null) { format(formatValue); } Object missingValue = instance.getMissing(); if (missingValue != null) { missing(missingValue); } String timeZoneValue = instance.getTimeZone(); if (timeZoneValue != null) { timeZone(timeZoneValue); } field(instance.getField()); } } /** * Initializes the value for the {@link PercentilesAggregation#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 PercentilesAggregation#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 PercentilesAggregation#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 PercentilesAggregation#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 elements) { this.subAggregations = ImmutableList.builder(); return addAllSubAggregations(elements); } /** * Adds elements to {@link PercentilesAggregation#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 elements) { this.subAggregations.addAll(elements); optBits |= OPT_BIT_SUB_AGGREGATIONS; return this; } /** * Initializes the value for the {@link PercentilesAggregation#getField() field} attribute. * @param field The value for field * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("field") public final Builder field(String field) { this.field = Objects.requireNonNull(field, "field"); initBits &= ~INIT_BIT_FIELD; return this; } /** * Initializes the value for the {@link PercentilesAggregation#getFormat() format} attribute. * @param format The value for format (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("format") public final Builder format(@Nullable String format) { this.format = format; return this; } /** * Initializes the value for the {@link PercentilesAggregation#getMissing() missing} attribute. * @param missing The value for missing (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("missing") public final Builder missing(@Nullable Object missing) { this.missing = missing; return this; } /** * Initializes the value for the {@link PercentilesAggregation#getTimeZone() timeZone} attribute. * @param timeZone The value for timeZone (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("timeZone") public final Builder timeZone(@Nullable String timeZone) { this.timeZone = timeZone; return this; } /** * Initializes the value for the {@link PercentilesAggregation#getCompression() compression} attribute. * @param compression The value for compression (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("compression") public final Builder compression(@Nullable Double compression) { this.compression = compression; return this; } /** * Initializes the value for the {@link PercentilesAggregation#getNumberOfSignificantValueDigits() numberOfSignificantValueDigits} attribute. * @param numberOfSignificantValueDigits The value for numberOfSignificantValueDigits (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("numberOfSignificantValueDigits") public final Builder numberOfSignificantValueDigits(@Nullable Integer numberOfSignificantValueDigits) { this.numberOfSignificantValueDigits = numberOfSignificantValueDigits; return this; } /** * Adds one element to {@link PercentilesAggregation#getPercents() percents} list. * @param element A percents element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addPercent(double element) { this.percents.add(element); return this; } /** * Adds elements to {@link PercentilesAggregation#getPercents() percents} list. * @param elements An array of percents elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addPercents(double... elements) { this.percents.addAll(Doubles.asList(elements)); return this; } /** * Sets or replaces all elements for {@link PercentilesAggregation#getPercents() percents} list. * @param elements An iterable of percents elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("percents") public final Builder percents(Iterable elements) { this.percents = ImmutableList.builder(); return addAllPercents(elements); } /** * Adds elements to {@link PercentilesAggregation#getPercents() percents} list. * @param elements An iterable of percents elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllPercents(Iterable elements) { this.percents.addAll(elements); return this; } /** * Initializes the value for the {@link PercentilesAggregation#isKeyed() keyed} attribute. * @param keyed The value for keyed (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("keyed") public final Builder keyed(@Nullable Boolean keyed) { this.keyed = keyed; return this; } /** * Builds a new {@link ImmutablePercentilesAggregation ImmutablePercentilesAggregation}. * @return An immutable instance of PercentilesAggregation * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutablePercentilesAggregation build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return ImmutablePercentilesAggregation.validate(new ImmutablePercentilesAggregation(this)); } 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"); if ((initBits & INIT_BIT_FIELD) != 0) attributes.add("field"); return "Cannot build PercentilesAggregation, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy