com.arakelian.elastic.model.search.ImmutableIdsQuery Maven / Gradle / Ivy
package com.arakelian.elastic.model.search;
import com.arakelian.core.feature.Nullable;
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.ImmutableSortedSet;
import com.google.common.collect.Ordering;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.SortedSet;
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 IdsQuery}.
*
* Use the builder to create immutable instances:
* {@code ImmutableIdsQuery.builder()}.
*/
@Generated(from = "IdsQuery", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableIdsQuery implements IdsQuery {
private final ImmutableSortedSet types;
private final ImmutableSortedSet values;
private final @Nullable Float boost;
private final @Nullable String name;
private final boolean hasStandardDefaults;
private ImmutableIdsQuery(ImmutableIdsQuery.Builder builder) {
this.boost = builder.boost;
this.name = builder.name;
if (builder.typesIsSet()) {
initShim.types(builder.types.build());
}
if (builder.valuesIsSet()) {
initShim.values(builder.values.build());
}
this.types = initShim.getTypes();
this.values = initShim.getValues();
this.hasStandardDefaults = initShim.hasStandardDefaults();
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 = "IdsQuery", generator = "Immutables")
private final class InitShim {
private byte typesBuildStage = STAGE_UNINITIALIZED;
private ImmutableSortedSet types;
ImmutableSortedSet getTypes() {
if (typesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (typesBuildStage == STAGE_UNINITIALIZED) {
typesBuildStage = STAGE_INITIALIZING;
this.types = ImmutableSortedSet.copyOf(
Ordering.natural(),
getTypesInitialize());
typesBuildStage = STAGE_INITIALIZED;
}
return this.types;
}
void types(ImmutableSortedSet types) {
this.types = types;
typesBuildStage = STAGE_INITIALIZED;
}
private byte valuesBuildStage = STAGE_UNINITIALIZED;
private ImmutableSortedSet values;
ImmutableSortedSet getValues() {
if (valuesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (valuesBuildStage == STAGE_UNINITIALIZED) {
valuesBuildStage = STAGE_INITIALIZING;
this.values = ImmutableSortedSet.copyOf(
Ordering.natural(),
getValuesInitialize());
valuesBuildStage = STAGE_INITIALIZED;
}
return this.values;
}
void values(ImmutableSortedSet values) {
this.values = values;
valuesBuildStage = STAGE_INITIALIZED;
}
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 String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (typesBuildStage == STAGE_INITIALIZING) attributes.add("types");
if (valuesBuildStage == STAGE_INITIALIZING) attributes.add("values");
if (hasStandardDefaultsBuildStage == STAGE_INITIALIZING) attributes.add("hasStandardDefaults");
return "Cannot build IdsQuery, attribute initializers form cycle " + attributes;
}
}
private SortedSet getTypesInitialize() {
return IdsQuery.super.getTypes();
}
private SortedSet getValuesInitialize() {
return IdsQuery.super.getValues();
}
private boolean hasStandardDefaultsInitialize() {
return IdsQuery.super.hasStandardDefaults();
}
/**
* @return The value of the {@code types} attribute
*/
@JsonProperty("types")
@Override
public ImmutableSortedSet getTypes() {
InitShim shim = this.initShim;
return shim != null
? shim.getTypes()
: this.types;
}
/**
* @return The value of the {@code values} attribute
*/
@JsonProperty("values")
@Override
public ImmutableSortedSet getValues() {
InitShim shim = this.initShim;
return shim != null
? shim.getValues()
: this.values;
}
/**
* @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;
}
/**
* This instance is equal to all instances of {@code ImmutableIdsQuery} 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 ImmutableIdsQuery
&& equalTo((ImmutableIdsQuery) another);
}
private boolean equalTo(ImmutableIdsQuery another) {
return types.equals(another.types)
&& values.equals(another.values)
&& Objects.equals(boost, another.boost)
&& Objects.equals(name, another.name);
}
/**
* Computes a hash code from attributes: {@code types}, {@code values}, {@code boost}, {@code name}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + types.hashCode();
h += (h << 5) + values.hashCode();
h += (h << 5) + Objects.hashCode(boost);
h += (h << 5) + Objects.hashCode(name);
return h;
}
/**
* Prints the immutable value {@code IdsQuery} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("IdsQuery")
.omitNullValues()
.add("types", types)
.add("values", values)
.add("boost", boost)
.add("name", name)
.toString();
}
/**
* Creates a builder for {@link ImmutableIdsQuery ImmutableIdsQuery}.
* @return A new ImmutableIdsQuery builder
*/
public static ImmutableIdsQuery.Builder builder() {
return new ImmutableIdsQuery.Builder();
}
/**
* Builds instances of type {@link ImmutableIdsQuery ImmutableIdsQuery}.
* 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 = "IdsQuery", generator = "Immutables")
@NotThreadSafe
@JsonTypeName("ids")
public static final class Builder {
private static final long OPT_BIT_TYPES = 0x1L;
private static final long OPT_BIT_VALUES = 0x2L;
private long optBits;
private ImmutableSortedSet.Builder types = ImmutableSortedSet.naturalOrder();
private ImmutableSortedSet.Builder values = ImmutableSortedSet.naturalOrder();
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.IdsQuery} 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(IdsQuery 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 IdsQuery) {
IdsQuery instance = (IdsQuery) object;
addAllTypes(instance.getTypes());
addAllValues(instance.getValues());
}
}
/**
* Adds one element to {@link IdsQuery#getTypes() types} sortedSet.
* @param element A types element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addType(String element) {
this.types.add(element);
optBits |= OPT_BIT_TYPES;
return this;
}
/**
* Adds elements to {@link IdsQuery#getTypes() types} sortedSet.
* @param elements An array of types elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addTypes(String... elements) {
this.types.addAll(Arrays.asList(elements));
optBits |= OPT_BIT_TYPES;
return this;
}
/**
* Sets or replaces all elements for {@link IdsQuery#getTypes() types} sortedSet.
* @param elements An iterable of types elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("types")
public final Builder types(Iterable elements) {
this.types = ImmutableSortedSet.naturalOrder();
return addAllTypes(elements);
}
/**
* Adds elements to {@link IdsQuery#getTypes() types} sortedSet.
* @param elements An iterable of types elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllTypes(Iterable elements) {
this.types.addAll(elements);
optBits |= OPT_BIT_TYPES;
return this;
}
/**
* Adds one element to {@link IdsQuery#getValues() values} sortedSet.
* @param element A values element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addValue(String element) {
this.values.add(element);
optBits |= OPT_BIT_VALUES;
return this;
}
/**
* Adds elements to {@link IdsQuery#getValues() values} sortedSet.
* @param elements An array of values elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addValues(String... elements) {
this.values.addAll(Arrays.asList(elements));
optBits |= OPT_BIT_VALUES;
return this;
}
/**
* Sets or replaces all elements for {@link IdsQuery#getValues() values} sortedSet.
* @param elements An iterable of values elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("values")
public final Builder values(Iterable elements) {
this.values = ImmutableSortedSet.naturalOrder();
return addAllValues(elements);
}
/**
* Adds elements to {@link IdsQuery#getValues() values} sortedSet.
* @param elements An iterable of values elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllValues(Iterable elements) {
this.values.addAll(elements);
optBits |= OPT_BIT_VALUES;
return this;
}
/**
* Initializes the value for the {@link IdsQuery#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 IdsQuery#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 ImmutableIdsQuery ImmutableIdsQuery}.
* @return An immutable instance of IdsQuery
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableIdsQuery build() {
return new ImmutableIdsQuery(this);
}
private boolean typesIsSet() {
return (optBits & OPT_BIT_TYPES) != 0;
}
private boolean valuesIsSet() {
return (optBits & OPT_BIT_VALUES) != 0;
}
}
}