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

com.arakelian.elastic.model.aggs.metrics.ImmutableStatsAggregation 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.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 StatsAggregation}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableStatsAggregation.builder()}. */ @Generated(from = "StatsAggregation", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableStatsAggregation implements StatsAggregation { 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 ImmutableStatsAggregation(ImmutableStatsAggregation.Builder builder) { this.name = builder.name; this.field = builder.field; this.format = builder.format; this.missing = builder.missing; this.timeZone = builder.timeZone; if (builder.subAggregationsIsSet()) { initShim.subAggregations(builder.subAggregations.build()); } 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 = "StatsAggregation", 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 String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (subAggregationsBuildStage == STAGE_INITIALIZING) attributes.add("subAggregations"); if (emptyBuildStage == STAGE_INITIALIZING) attributes.add("empty"); return "Cannot build StatsAggregation, attribute initializers form cycle " + attributes; } } private List getSubAggregationsInitialize() { return StatsAggregation.super.getSubAggregations(); } private boolean isEmptyInitialize() { return StatsAggregation.super.isEmpty(); } /** * 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; } /** * This instance is equal to all instances of {@code ImmutableStatsAggregation} 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 ImmutableStatsAggregation && equalTo((ImmutableStatsAggregation) another); } private boolean equalTo(ImmutableStatsAggregation 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); } /** * Computes a hash code from attributes: {@code name}, {@code subAggregations}, {@code field}, {@code format}, {@code missing}, {@code timeZone}. * @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); return h; } /** * Prints the immutable value {@code StatsAggregation} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("StatsAggregation") .omitNullValues() .add("name", name) .add("subAggregations", subAggregations) .add("field", field) .add("format", format) .add("missing", missing) .add("timeZone", timeZone) .toString(); } /** * Creates a builder for {@link ImmutableStatsAggregation ImmutableStatsAggregation}. *

   * ImmutableStatsAggregation.builder()
   *    .name(String) // required {@link StatsAggregation#getName() name}
   *    .addSubAggregation|addAllSubAggregations(com.arakelian.elastic.model.aggs.Aggregation) // {@link StatsAggregation#getSubAggregations() subAggregations} elements
   *    .field(String) // required {@link StatsAggregation#getField() field}
   *    .format(String | null) // nullable {@link StatsAggregation#getFormat() format}
   *    .missing(Object | null) // nullable {@link StatsAggregation#getMissing() missing}
   *    .timeZone(String | null) // nullable {@link StatsAggregation#getTimeZone() timeZone}
   *    .build();
   * 
* @return A new ImmutableStatsAggregation builder */ public static ImmutableStatsAggregation.Builder builder() { return new ImmutableStatsAggregation.Builder(); } /** * Builds instances of type {@link ImmutableStatsAggregation ImmutableStatsAggregation}. * 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 = "StatsAggregation", generator = "Immutables") @NotThreadSafe @JsonTypeName("stats") 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 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.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; } /** * Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.aggs.metrics.StatsAggregation} 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(StatsAggregation 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 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 StatsAggregation#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 StatsAggregation#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 StatsAggregation#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 StatsAggregation#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 StatsAggregation#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 StatsAggregation#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 StatsAggregation#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 StatsAggregation#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 StatsAggregation#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; } /** * Builds a new {@link ImmutableStatsAggregation ImmutableStatsAggregation}. * @return An immutable instance of StatsAggregation * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableStatsAggregation build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableStatsAggregation(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 StatsAggregation, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy