com.arakelian.elastic.model.search.ImmutableGeoDistanceQuery Maven / Gradle / Ivy
package com.arakelian.elastic.model.search;
import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.model.enums.DistanceType;
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.JsonTypeName;
import com.google.common.base.MoreObjects;
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 GeoDistanceQuery}.
*
* Use the builder to create immutable instances:
* {@code ImmutableGeoDistanceQuery.builder()}.
*/
@Generated(from = "GeoDistanceQuery", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableGeoDistanceQuery implements GeoDistanceQuery {
private final String distance;
private final @Nullable DistanceType distanceType;
private final String fieldName;
private final GeoPoint point;
private final @Nullable ValidationMethod validationMethod;
private final @Nullable Float boost;
private final @Nullable String name;
private final boolean hasStandardDefaults;
private ImmutableGeoDistanceQuery(ImmutableGeoDistanceQuery.Builder builder) {
this.distance = builder.distance;
this.distanceType = builder.distanceType;
this.fieldName = builder.fieldName;
this.point = builder.point;
this.validationMethod = builder.validationMethod;
this.boost = builder.boost;
this.name = builder.name;
this.hasStandardDefaults = GeoDistanceQuery.super.hasStandardDefaults();
}
/**
* @return The value of the {@code distance} attribute
*/
@JsonProperty("distance")
@Override
public String getDistance() {
return distance;
}
/**
* @return The value of the {@code distanceType} attribute
*/
@JsonProperty("distance_type")
@Override
public @Nullable DistanceType getDistanceType() {
return distanceType;
}
/**
* @return The value of the {@code fieldName} attribute
*/
@JsonProperty("field")
@Override
public String getFieldName() {
return fieldName;
}
/**
* @return The value of the {@code point} attribute
*/
@JsonProperty("point")
@Override
public GeoPoint getPoint() {
return point;
}
/**
* @return The value of the {@code validationMethod} attribute
*/
@JsonProperty("validation_method")
@Override
public @Nullable ValidationMethod getValidationMethod() {
return validationMethod;
}
/**
* @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() {
return hasStandardDefaults;
}
/**
* This instance is equal to all instances of {@code ImmutableGeoDistanceQuery} 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 ImmutableGeoDistanceQuery
&& equalTo((ImmutableGeoDistanceQuery) another);
}
private boolean equalTo(ImmutableGeoDistanceQuery another) {
return distance.equals(another.distance)
&& Objects.equals(distanceType, another.distanceType)
&& fieldName.equals(another.fieldName)
&& point.equals(another.point)
&& Objects.equals(validationMethod, another.validationMethod)
&& Objects.equals(boost, another.boost)
&& Objects.equals(name, another.name);
}
/**
* Computes a hash code from attributes: {@code distance}, {@code distanceType}, {@code fieldName}, {@code point}, {@code validationMethod}, {@code boost}, {@code name}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + distance.hashCode();
h += (h << 5) + Objects.hashCode(distanceType);
h += (h << 5) + fieldName.hashCode();
h += (h << 5) + point.hashCode();
h += (h << 5) + Objects.hashCode(validationMethod);
h += (h << 5) + Objects.hashCode(boost);
h += (h << 5) + Objects.hashCode(name);
return h;
}
/**
* Prints the immutable value {@code GeoDistanceQuery} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("GeoDistanceQuery")
.omitNullValues()
.add("distance", distance)
.add("distanceType", distanceType)
.add("fieldName", fieldName)
.add("point", point)
.add("validationMethod", validationMethod)
.add("boost", boost)
.add("name", name)
.toString();
}
/**
* Creates a builder for {@link ImmutableGeoDistanceQuery ImmutableGeoDistanceQuery}.
* @return A new ImmutableGeoDistanceQuery builder
*/
public static ImmutableGeoDistanceQuery.Builder builder() {
return new ImmutableGeoDistanceQuery.Builder();
}
/**
* Builds instances of type {@link ImmutableGeoDistanceQuery ImmutableGeoDistanceQuery}.
* 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 = "GeoDistanceQuery", generator = "Immutables")
@NotThreadSafe
@JsonTypeName("geo_distance")
public static final class Builder {
private static final long INIT_BIT_DISTANCE = 0x1L;
private static final long INIT_BIT_FIELD_NAME = 0x2L;
private static final long INIT_BIT_POINT = 0x4L;
private long initBits = 0x7L;
private @javax.annotation.Nullable String distance;
private @javax.annotation.Nullable DistanceType distanceType;
private @javax.annotation.Nullable String fieldName;
private @javax.annotation.Nullable GeoPoint point;
private @javax.annotation.Nullable ValidationMethod validationMethod;
private @javax.annotation.Nullable Float boost;
private @javax.annotation.Nullable String name;
private Builder() {
}
/**
* 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;
}
/**
* Fill a builder with attribute values from the provided {@code com.arakelian.elastic.model.search.GeoDistanceQuery} 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(GeoDistanceQuery instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
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);
}
}
if (object instanceof GeoDistanceQuery) {
GeoDistanceQuery instance = (GeoDistanceQuery) object;
fieldName(instance.getFieldName());
distance(instance.getDistance());
ValidationMethod validationMethodValue = instance.getValidationMethod();
if (validationMethodValue != null) {
validationMethod(validationMethodValue);
}
point(instance.getPoint());
DistanceType distanceTypeValue = instance.getDistanceType();
if (distanceTypeValue != null) {
distanceType(distanceTypeValue);
}
}
}
/**
* Initializes the value for the {@link GeoDistanceQuery#getDistance() distance} attribute.
* @param distance The value for distance
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("distance")
public final Builder distance(String distance) {
this.distance = Objects.requireNonNull(distance, "distance");
initBits &= ~INIT_BIT_DISTANCE;
return this;
}
/**
* Initializes the value for the {@link GeoDistanceQuery#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("distance_type")
public final Builder distanceType(@Nullable DistanceType distanceType) {
this.distanceType = distanceType;
return this;
}
/**
* Initializes the value for the {@link GeoDistanceQuery#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;
}
/**
* Initializes the value for the {@link GeoDistanceQuery#getPoint() point} attribute.
* @param point The value for point
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("point")
public final Builder point(GeoPoint point) {
this.point = Objects.requireNonNull(point, "point");
initBits &= ~INIT_BIT_POINT;
return this;
}
/**
* Initializes the value for the {@link GeoDistanceQuery#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;
}
/**
* Initializes the value for the {@link GeoDistanceQuery#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 GeoDistanceQuery#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;
}
/**
* Builds a new {@link ImmutableGeoDistanceQuery ImmutableGeoDistanceQuery}.
* @return An immutable instance of GeoDistanceQuery
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableGeoDistanceQuery build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableGeoDistanceQuery(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_DISTANCE) != 0) attributes.add("distance");
if ((initBits & INIT_BIT_FIELD_NAME) != 0) attributes.add("fieldName");
if ((initBits & INIT_BIT_POINT) != 0) attributes.add("point");
return "Cannot build GeoDistanceQuery, some of required attributes are not set " + attributes;
}
}
}