com.arakelian.elastic.model.search.ImmutableGeoPolygonQuery Maven / Gradle / Ivy
package com.arakelian.elastic.model.search;
import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.model.enums.ValidationMethod;
import com.arakelian.jackson.model.GeoPoint;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
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 GeoPolygonQuery}.
*
* Use the builder to create immutable instances:
* {@code ImmutableGeoPolygonQuery.builder()}.
*/
@Generated(from = "GeoPolygonQuery", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableGeoPolygonQuery implements GeoPolygonQuery {
private final @Nullable Float boost;
private final @Nullable String name;
private final boolean hasStandardDefaults;
private final String fieldName;
private final ImmutableList points;
private final @Nullable ValidationMethod validationMethod;
private ImmutableGeoPolygonQuery(ImmutableGeoPolygonQuery.Builder builder) {
this.boost = builder.boost;
this.name = builder.name;
this.fieldName = builder.fieldName;
this.validationMethod = builder.validationMethod;
if (builder.pointsIsSet()) {
initShim.points(builder.points.build());
}
this.hasStandardDefaults = initShim.hasStandardDefaults();
this.points = initShim.getPoints();
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 = "GeoPolygonQuery", generator = "Immutables")
private final class InitShim {
private byte hasStandardDefaultsBuildStage = STAGE_UNINITIALIZED;
private boolean hasStandardDefaults;
boolean hasStandardDefaults() {
if (hasStandardDefaultsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (hasStandardDefaultsBuildStage == STAGE_UNINITIALIZED) {
hasStandardDefaultsBuildStage = STAGE_INITIALIZING;
this.hasStandardDefaults = hasStandardDefaultsInitialize();
hasStandardDefaultsBuildStage = STAGE_INITIALIZED;
}
return this.hasStandardDefaults;
}
private byte pointsBuildStage = STAGE_UNINITIALIZED;
private ImmutableList points;
ImmutableList getPoints() {
if (pointsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (pointsBuildStage == STAGE_UNINITIALIZED) {
pointsBuildStage = STAGE_INITIALIZING;
this.points = ImmutableList.copyOf(getPointsInitialize());
pointsBuildStage = STAGE_INITIALIZED;
}
return this.points;
}
void points(ImmutableList points) {
this.points = points;
pointsBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (hasStandardDefaultsBuildStage == STAGE_INITIALIZING) attributes.add("hasStandardDefaults");
if (pointsBuildStage == STAGE_INITIALIZING) attributes.add("points");
return "Cannot build GeoPolygonQuery, attribute initializers form cycle " + attributes;
}
}
private boolean hasStandardDefaultsInitialize() {
return GeoPolygonQuery.super.hasStandardDefaults();
}
private List getPointsInitialize() {
return GeoPolygonQuery.super.getPoints();
}
/**
* @return The value of the {@code boost} attribute
*/
@JsonProperty("boost")
@Override
public @Nullable Float getBoost() {
return boost;
}
/**
* Returns the name of the query
* @return name of the query
* @see Named
* Queries
*/
@JsonProperty("_name")
@Override
public @Nullable String getName() {
return name;
}
/**
* @return The computed-at-construction value of the {@code hasStandardDefaults} attribute
*/
@JsonProperty("hasStandardDefaults")
@JsonIgnore
@Override
public boolean hasStandardDefaults() {
InitShim shim = this.initShim;
return shim != null
? shim.hasStandardDefaults()
: this.hasStandardDefaults;
}
/**
* @return The value of the {@code fieldName} attribute
*/
@JsonProperty("field")
@Override
public String getFieldName() {
return fieldName;
}
/**
* @return The value of the {@code points} attribute
*/
@JsonProperty("points")
@Override
public ImmutableList getPoints() {
InitShim shim = this.initShim;
return shim != null
? shim.getPoints()
: this.points;
}
/**
* @return The value of the {@code validationMethod} attribute
*/
@JsonProperty("validation_method")
@Override
public @Nullable ValidationMethod getValidationMethod() {
return validationMethod;
}
/**
* This instance is equal to all instances of {@code ImmutableGeoPolygonQuery} 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 ImmutableGeoPolygonQuery
&& equalTo((ImmutableGeoPolygonQuery) another);
}
private boolean equalTo(ImmutableGeoPolygonQuery another) {
return Objects.equals(boost, another.boost)
&& Objects.equals(name, another.name)
&& fieldName.equals(another.fieldName)
&& points.equals(another.points)
&& Objects.equals(validationMethod, another.validationMethod);
}
/**
* Computes a hash code from attributes: {@code boost}, {@code name}, {@code fieldName}, {@code points}, {@code validationMethod}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(boost);
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + fieldName.hashCode();
h += (h << 5) + points.hashCode();
h += (h << 5) + Objects.hashCode(validationMethod);
return h;
}
/**
* Prints the immutable value {@code GeoPolygonQuery} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("GeoPolygonQuery")
.omitNullValues()
.add("boost", boost)
.add("name", name)
.add("fieldName", fieldName)
.add("points", points)
.add("validationMethod", validationMethod)
.toString();
}
/**
* Creates a builder for {@link ImmutableGeoPolygonQuery ImmutableGeoPolygonQuery}.
*
* ImmutableGeoPolygonQuery.builder()
* .boost(Float | null) // nullable {@link GeoPolygonQuery#getBoost() boost}
* .name(String | null) // nullable {@link GeoPolygonQuery#getName() name}
* .fieldName(String) // required {@link GeoPolygonQuery#getFieldName() fieldName}
* .addPoint|addAllPoints(com.arakelian.jackson.model.GeoPoint) // {@link GeoPolygonQuery#getPoints() points} elements
* .validationMethod(com.arakelian.elastic.model.enums.ValidationMethod | null) // nullable {@link GeoPolygonQuery#getValidationMethod() validationMethod}
* .build();
*
* @return A new ImmutableGeoPolygonQuery builder
*/
public static ImmutableGeoPolygonQuery.Builder builder() {
return new ImmutableGeoPolygonQuery.Builder();
}
/**
* Builds instances of type {@link ImmutableGeoPolygonQuery ImmutableGeoPolygonQuery}.
* 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 = "GeoPolygonQuery", generator = "Immutables")
@NotThreadSafe
@JsonPropertyOrder({"_name", "boost", "field", "points", "validation_method"})
@JsonTypeName("geo_polygon")
public static final class Builder {
private static final long INIT_BIT_FIELD_NAME = 0x1L;
private static final long OPT_BIT_POINTS = 0x1L;
private long initBits = 0x1L;
private long optBits;
private @javax.annotation.Nullable Float boost;
private @javax.annotation.Nullable String name;
private @javax.annotation.Nullable String fieldName;
private ImmutableList.Builder points = ImmutableList.builder();
private @javax.annotation.Nullable ValidationMethod validationMethod;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.search.GeoPolygonQuery} 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(GeoPolygonQuery instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.search.StandardQuery} 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(StandardQuery instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof GeoPolygonQuery) {
GeoPolygonQuery instance = (GeoPolygonQuery) object;
ValidationMethod validationMethodValue = instance.getValidationMethod();
if (validationMethodValue != null) {
validationMethod(validationMethodValue);
}
fieldName(instance.getFieldName());
addAllPoints(instance.getPoints());
}
if (object instanceof StandardQuery) {
StandardQuery instance = (StandardQuery) object;
String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
Float boostValue = instance.getBoost();
if (boostValue != null) {
boost(boostValue);
}
}
}
/**
* Initializes the value for the {@link GeoPolygonQuery#getBoost() boost} attribute.
* @param boost The value for boost (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("boost")
public final Builder boost(@Nullable Float boost) {
this.boost = boost;
return this;
}
/**
* Initializes the value for the {@link GeoPolygonQuery#getName() name} attribute.
* @param name The value for name (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_name")
public final Builder name(@Nullable String name) {
this.name = name;
return this;
}
/**
* Initializes the value for the {@link GeoPolygonQuery#getFieldName() fieldName} attribute.
* @param fieldName The value for fieldName
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("field")
public final Builder fieldName(String fieldName) {
this.fieldName = Objects.requireNonNull(fieldName, "fieldName");
initBits &= ~INIT_BIT_FIELD_NAME;
return this;
}
/**
* Adds one element to {@link GeoPolygonQuery#getPoints() points} list.
* @param element A points element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addPoint(GeoPoint element) {
this.points.add(element);
optBits |= OPT_BIT_POINTS;
return this;
}
/**
* Adds elements to {@link GeoPolygonQuery#getPoints() points} list.
* @param elements An array of points elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addPoints(GeoPoint... elements) {
this.points.add(elements);
optBits |= OPT_BIT_POINTS;
return this;
}
/**
* Sets or replaces all elements for {@link GeoPolygonQuery#getPoints() points} list.
* @param elements An iterable of points elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("points")
public final Builder points(Iterable extends GeoPoint> elements) {
this.points = ImmutableList.builder();
return addAllPoints(elements);
}
/**
* Adds elements to {@link GeoPolygonQuery#getPoints() points} list.
* @param elements An iterable of points elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllPoints(Iterable extends GeoPoint> elements) {
this.points.addAll(elements);
optBits |= OPT_BIT_POINTS;
return this;
}
/**
* Initializes the value for the {@link GeoPolygonQuery#getValidationMethod() validationMethod} attribute.
* @param validationMethod The value for validationMethod (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("validation_method")
public final Builder validationMethod(@Nullable ValidationMethod validationMethod) {
this.validationMethod = validationMethod;
return this;
}
/**
* Builds a new {@link ImmutableGeoPolygonQuery ImmutableGeoPolygonQuery}.
* @return An immutable instance of GeoPolygonQuery
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableGeoPolygonQuery build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableGeoPolygonQuery(this);
}
private boolean pointsIsSet() {
return (optBits & OPT_BIT_POINTS) != 0;
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_FIELD_NAME) != 0) attributes.add("fieldName");
return "Cannot build GeoPolygonQuery, some of required attributes are not set " + attributes;
}
}
}