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

com.arakelian.elastic.model.aggs.bucket.ImmutableGeoDistanceAggregation 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.enums.DistanceType;
import com.arakelian.elastic.model.enums.Unit;
import com.arakelian.jackson.model.GeoPoint;
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 GeoDistanceAggregation}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableGeoDistanceAggregation.builder()}. */ @Generated(from = "GeoDistanceAggregation", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableGeoDistanceAggregation implements GeoDistanceAggregation { private final @Nullable DistanceType distanceType; private final @Nullable GeoPoint origin; private final ImmutableList ranges; private final @Nullable Unit unit; private final @Nullable Boolean keyed; private final String name; private final ImmutableList subAggregations; private final boolean empty; private ImmutableGeoDistanceAggregation(ImmutableGeoDistanceAggregation.Builder builder) { this.distanceType = builder.distanceType; this.origin = builder.origin; this.unit = builder.unit; this.keyed = builder.keyed; this.name = builder.name; if (builder.rangesIsSet()) { initShim.ranges(builder.ranges.build()); } if (builder.subAggregationsIsSet()) { initShim.subAggregations(builder.subAggregations.build()); } this.ranges = initShim.getRanges(); 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 = "GeoDistanceAggregation", generator = "Immutables") private final class InitShim { private byte rangesBuildStage = STAGE_UNINITIALIZED; private ImmutableList ranges; ImmutableList getRanges() { if (rangesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (rangesBuildStage == STAGE_UNINITIALIZED) { rangesBuildStage = STAGE_INITIALIZING; this.ranges = ImmutableList.copyOf(getRangesInitialize()); rangesBuildStage = STAGE_INITIALIZED; } return this.ranges; } void ranges(ImmutableList ranges) { this.ranges = ranges; rangesBuildStage = 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 (rangesBuildStage == STAGE_INITIALIZING) attributes.add("ranges"); if (subAggregationsBuildStage == STAGE_INITIALIZING) attributes.add("subAggregations"); if (emptyBuildStage == STAGE_INITIALIZING) attributes.add("empty"); return "Cannot build GeoDistanceAggregation, attribute initializers form cycle " + attributes; } } private List getRangesInitialize() { return GeoDistanceAggregation.super.getRanges(); } private List getSubAggregationsInitialize() { return GeoDistanceAggregation.super.getSubAggregations(); } private boolean isEmptyInitialize() { return GeoDistanceAggregation.super.isEmpty(); } /** * @return The value of the {@code distanceType} attribute */ @JsonProperty("distanceType") @Override public @Nullable DistanceType getDistanceType() { return distanceType; } /** * @return The value of the {@code origin} attribute */ @JsonProperty("origin") @Override public @Nullable GeoPoint getOrigin() { return origin; } /** * @return The value of the {@code ranges} attribute */ @JsonProperty("ranges") @Override public ImmutableList getRanges() { InitShim shim = this.initShim; return shim != null ? shim.getRanges() : this.ranges; } /** * @return The value of the {@code unit} attribute */ @JsonProperty("unit") @Override public @Nullable Unit getUnit() { return unit; } /** * @return The value of the {@code keyed} attribute */ @JsonProperty("keyed") @Override public @Nullable Boolean isKeyed() { return keyed; } /** * 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 ImmutableGeoDistanceAggregation} 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 ImmutableGeoDistanceAggregation && equalTo((ImmutableGeoDistanceAggregation) another); } private boolean equalTo(ImmutableGeoDistanceAggregation another) { return Objects.equals(distanceType, another.distanceType) && Objects.equals(origin, another.origin) && ranges.equals(another.ranges) && Objects.equals(unit, another.unit) && Objects.equals(keyed, another.keyed) && name.equals(another.name) && subAggregations.equals(another.subAggregations); } /** * Computes a hash code from attributes: {@code distanceType}, {@code origin}, {@code ranges}, {@code unit}, {@code keyed}, {@code name}, {@code subAggregations}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + Objects.hashCode(distanceType); h += (h << 5) + Objects.hashCode(origin); h += (h << 5) + ranges.hashCode(); h += (h << 5) + Objects.hashCode(unit); h += (h << 5) + Objects.hashCode(keyed); h += (h << 5) + name.hashCode(); h += (h << 5) + subAggregations.hashCode(); return h; } /** * Prints the immutable value {@code GeoDistanceAggregation} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("GeoDistanceAggregation") .omitNullValues() .add("distanceType", distanceType) .add("origin", origin) .add("ranges", ranges) .add("unit", unit) .add("keyed", keyed) .add("name", name) .add("subAggregations", subAggregations) .toString(); } /** * Creates a builder for {@link ImmutableGeoDistanceAggregation ImmutableGeoDistanceAggregation}. * @return A new ImmutableGeoDistanceAggregation builder */ public static ImmutableGeoDistanceAggregation.Builder builder() { return new ImmutableGeoDistanceAggregation.Builder(); } /** * Builds instances of type {@link ImmutableGeoDistanceAggregation ImmutableGeoDistanceAggregation}. * 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 = "GeoDistanceAggregation", generator = "Immutables") @NotThreadSafe @JsonTypeName("geo_distance") public static final class Builder { private static final long INIT_BIT_NAME = 0x1L; private static final long OPT_BIT_RANGES = 0x1L; private static final long OPT_BIT_SUB_AGGREGATIONS = 0x2L; private long initBits = 0x1L; private long optBits; private @javax.annotation.Nullable DistanceType distanceType; private @javax.annotation.Nullable GeoPoint origin; private ImmutableList.Builder ranges = ImmutableList.builder(); private @javax.annotation.Nullable Unit unit; private @javax.annotation.Nullable Boolean keyed; 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.GeoDistanceAggregation} 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(GeoDistanceAggregation 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 GeoDistanceAggregation) { GeoDistanceAggregation instance = (GeoDistanceAggregation) object; Unit unitValue = instance.getUnit(); if (unitValue != null) { unit(unitValue); } addAllRanges(instance.getRanges()); Boolean keyedValue = instance.isKeyed(); if (keyedValue != null) { keyed(keyedValue); } DistanceType distanceTypeValue = instance.getDistanceType(); if (distanceTypeValue != null) { distanceType(distanceTypeValue); } GeoPoint originValue = instance.getOrigin(); if (originValue != null) { origin(originValue); } } } /** * Initializes the value for the {@link GeoDistanceAggregation#getDistanceType() distanceType} attribute. * @param distanceType The value for distanceType (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("distanceType") public final Builder distanceType(@Nullable DistanceType distanceType) { this.distanceType = distanceType; return this; } /** * Initializes the value for the {@link GeoDistanceAggregation#getOrigin() origin} attribute. * @param origin The value for origin (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("origin") public final Builder origin(@Nullable GeoPoint origin) { this.origin = origin; return this; } /** * Adds one element to {@link GeoDistanceAggregation#getRanges() ranges} list. * @param element A ranges element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addRange(Range element) { this.ranges.add(element); optBits |= OPT_BIT_RANGES; return this; } /** * Adds elements to {@link GeoDistanceAggregation#getRanges() ranges} list. * @param elements An array of ranges elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addRanges(Range... elements) { this.ranges.add(elements); optBits |= OPT_BIT_RANGES; return this; } /** * Sets or replaces all elements for {@link GeoDistanceAggregation#getRanges() ranges} list. * @param elements An iterable of ranges elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("ranges") public final Builder ranges(Iterable elements) { this.ranges = ImmutableList.builder(); return addAllRanges(elements); } /** * Adds elements to {@link GeoDistanceAggregation#getRanges() ranges} list. * @param elements An iterable of ranges elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllRanges(Iterable elements) { this.ranges.addAll(elements); optBits |= OPT_BIT_RANGES; return this; } /** * Initializes the value for the {@link GeoDistanceAggregation#getUnit() unit} attribute. * @param unit The value for unit (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("unit") public final Builder unit(@Nullable Unit unit) { this.unit = unit; return this; } /** * Initializes the value for the {@link GeoDistanceAggregation#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; } /** * Initializes the value for the {@link GeoDistanceAggregation#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 GeoDistanceAggregation#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 GeoDistanceAggregation#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 GeoDistanceAggregation#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 GeoDistanceAggregation#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; } /** * Builds a new {@link ImmutableGeoDistanceAggregation ImmutableGeoDistanceAggregation}. * @return An immutable instance of GeoDistanceAggregation * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableGeoDistanceAggregation build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableGeoDistanceAggregation(this); } private boolean rangesIsSet() { return (optBits & OPT_BIT_RANGES) != 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 GeoDistanceAggregation, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy