com.arakelian.elastic.model.search.ImmutableSearchResponse Maven / Gradle / Ivy
package com.arakelian.elastic.model.search;
import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.model.Shards;
import com.arakelian.jackson.MapPath;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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 SearchResponse}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSearchResponse.builder()}.
*/
@Generated(from = "SearchResponse", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableSearchResponse implements SearchResponse {
private final ImmutableMap aggregations;
private final @Nullable MapPath error;
private final SearchHits hits;
private final @Nullable Integer numberOfReducePhases;
private final ImmutableMap properties;
private final @Nullable String scrollId;
private final @Nullable Shards shards;
private final @Nullable Integer took;
private final boolean hasError;
private final @Nullable Boolean terminatedEarly;
private final @Nullable Boolean timedOut;
private ImmutableSearchResponse(ImmutableSearchResponse.Builder builder) {
this.error = builder.error;
this.numberOfReducePhases = builder.numberOfReducePhases;
this.scrollId = builder.scrollId;
this.shards = builder.shards;
this.took = builder.took;
this.terminatedEarly = builder.terminatedEarly;
this.timedOut = builder.timedOut;
if (builder.aggregationsIsSet()) {
initShim.aggregations(builder.aggregations.build());
}
if (builder.hits != null) {
initShim.hits(builder.hits);
}
if (builder.propertiesIsSet()) {
initShim.properties(builder.properties.build());
}
this.aggregations = initShim.getAggregations();
this.hits = initShim.getHits();
this.properties = initShim.getProperties();
this.hasError = initShim.hasError();
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 = "SearchResponse", generator = "Immutables")
private final class InitShim {
private byte aggregationsBuildStage = STAGE_UNINITIALIZED;
private ImmutableMap aggregations;
ImmutableMap getAggregations() {
if (aggregationsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (aggregationsBuildStage == STAGE_UNINITIALIZED) {
aggregationsBuildStage = STAGE_INITIALIZING;
this.aggregations = ImmutableMap.copyOf(getAggregationsInitialize());
aggregationsBuildStage = STAGE_INITIALIZED;
}
return this.aggregations;
}
void aggregations(ImmutableMap aggregations) {
this.aggregations = aggregations;
aggregationsBuildStage = STAGE_INITIALIZED;
}
private byte hitsBuildStage = STAGE_UNINITIALIZED;
private SearchHits hits;
SearchHits getHits() {
if (hitsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (hitsBuildStage == STAGE_UNINITIALIZED) {
hitsBuildStage = STAGE_INITIALIZING;
this.hits = Objects.requireNonNull(getHitsInitialize(), "hits");
hitsBuildStage = STAGE_INITIALIZED;
}
return this.hits;
}
void hits(SearchHits hits) {
this.hits = hits;
hitsBuildStage = STAGE_INITIALIZED;
}
private byte propertiesBuildStage = STAGE_UNINITIALIZED;
private ImmutableMap properties;
ImmutableMap getProperties() {
if (propertiesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (propertiesBuildStage == STAGE_UNINITIALIZED) {
propertiesBuildStage = STAGE_INITIALIZING;
this.properties = ImmutableMap.copyOf(getPropertiesInitialize());
propertiesBuildStage = STAGE_INITIALIZED;
}
return this.properties;
}
void properties(ImmutableMap properties) {
this.properties = properties;
propertiesBuildStage = STAGE_INITIALIZED;
}
private byte hasErrorBuildStage = STAGE_UNINITIALIZED;
private boolean hasError;
boolean hasError() {
if (hasErrorBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (hasErrorBuildStage == STAGE_UNINITIALIZED) {
hasErrorBuildStage = STAGE_INITIALIZING;
this.hasError = hasErrorInitialize();
hasErrorBuildStage = STAGE_INITIALIZED;
}
return this.hasError;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (aggregationsBuildStage == STAGE_INITIALIZING) attributes.add("aggregations");
if (hitsBuildStage == STAGE_INITIALIZING) attributes.add("hits");
if (propertiesBuildStage == STAGE_INITIALIZING) attributes.add("properties");
if (hasErrorBuildStage == STAGE_INITIALIZING) attributes.add("hasError");
return "Cannot build SearchResponse, attribute initializers form cycle " + attributes;
}
}
private Map getAggregationsInitialize() {
return SearchResponse.super.getAggregations();
}
private SearchHits getHitsInitialize() {
return SearchResponse.super.getHits();
}
private Map getPropertiesInitialize() {
return SearchResponse.super.getProperties();
}
private boolean hasErrorInitialize() {
return SearchResponse.super.hasError();
}
/**
* @return The value of the {@code aggregations} attribute
*/
@JsonProperty("aggregations")
@Override
public ImmutableMap getAggregations() {
InitShim shim = this.initShim;
return shim != null
? shim.getAggregations()
: this.aggregations;
}
/**
* @return The value of the {@code error} attribute
*/
@JsonProperty("error")
@Override
public @Nullable MapPath getError() {
return error;
}
/**
* @return The value of the {@code hits} attribute
*/
@JsonProperty("hits")
@Override
public SearchHits getHits() {
InitShim shim = this.initShim;
return shim != null
? shim.getHits()
: this.hits;
}
/**
* @return The value of the {@code numberOfReducePhases} attribute
*/
@JsonProperty("num_reduce_phases")
@Override
public @Nullable Integer getNumberOfReducePhases() {
return numberOfReducePhases;
}
/**
* @return The value of the {@code properties} attribute
*/
@JsonProperty("properties")
@JsonAnyGetter
@Override
public ImmutableMap getProperties() {
InitShim shim = this.initShim;
return shim != null
? shim.getProperties()
: this.properties;
}
/**
* @return The value of the {@code scrollId} attribute
*/
@JsonProperty("_scroll_id")
@Override
public @Nullable String getScrollId() {
return scrollId;
}
/**
* @return The value of the {@code shards} attribute
*/
@JsonProperty("_shards")
@Override
public @Nullable Shards getShards() {
return shards;
}
/**
* @return The value of the {@code took} attribute
*/
@JsonProperty("took")
@Override
public @Nullable Integer getTook() {
return took;
}
/**
* @return The computed-at-construction value of the {@code hasError} attribute
*/
@JsonProperty("hasError")
@JsonIgnore
@Override
public boolean hasError() {
InitShim shim = this.initShim;
return shim != null
? shim.hasError()
: this.hasError;
}
/**
* @return The value of the {@code terminatedEarly} attribute
*/
@JsonProperty("terminated_early")
@Override
public @Nullable Boolean isTerminatedEarly() {
return terminatedEarly;
}
/**
* @return The value of the {@code timedOut} attribute
*/
@JsonProperty("timed_out")
@Override
public @Nullable Boolean isTimedOut() {
return timedOut;
}
/**
* This instance is equal to all instances of {@code ImmutableSearchResponse} 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 ImmutableSearchResponse
&& equalTo((ImmutableSearchResponse) another);
}
private boolean equalTo(ImmutableSearchResponse another) {
return properties.equals(another.properties)
&& Objects.equals(scrollId, another.scrollId)
&& Objects.equals(took, another.took)
&& Objects.equals(terminatedEarly, another.terminatedEarly)
&& Objects.equals(timedOut, another.timedOut);
}
/**
* Computes a hash code from attributes: {@code properties}, {@code scrollId}, {@code took}, {@code terminatedEarly}, {@code timedOut}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + properties.hashCode();
h += (h << 5) + Objects.hashCode(scrollId);
h += (h << 5) + Objects.hashCode(took);
h += (h << 5) + Objects.hashCode(terminatedEarly);
h += (h << 5) + Objects.hashCode(timedOut);
return h;
}
/**
* Prints the immutable value {@code SearchResponse} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SearchResponse")
.omitNullValues()
.add("properties", properties)
.add("scrollId", scrollId)
.add("took", took)
.add("terminatedEarly", terminatedEarly)
.add("timedOut", timedOut)
.toString();
}
/**
* Creates a builder for {@link ImmutableSearchResponse ImmutableSearchResponse}.
* @return A new ImmutableSearchResponse builder
*/
public static ImmutableSearchResponse.Builder builder() {
return new ImmutableSearchResponse.Builder();
}
/**
* Builds instances of type {@link ImmutableSearchResponse ImmutableSearchResponse}.
* 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 = "SearchResponse", generator = "Immutables")
@NotThreadSafe
@JsonPropertyOrder({"error", "_scroll_id", "took", "timed_out", "num_reduce_phases", "terminated_early", "_shards", "hits"})
public static final class Builder {
private static final long OPT_BIT_AGGREGATIONS = 0x1L;
private static final long OPT_BIT_PROPERTIES = 0x2L;
private long optBits;
private ImmutableMap.Builder aggregations = ImmutableMap.builder();
private @javax.annotation.Nullable MapPath error;
private @javax.annotation.Nullable SearchHits hits;
private @javax.annotation.Nullable Integer numberOfReducePhases;
private ImmutableMap.Builder properties = ImmutableMap.builder();
private @javax.annotation.Nullable String scrollId;
private @javax.annotation.Nullable Shards shards;
private @javax.annotation.Nullable Integer took;
private @javax.annotation.Nullable Boolean terminatedEarly;
private @javax.annotation.Nullable Boolean timedOut;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code SearchResponse} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(SearchResponse instance) {
Objects.requireNonNull(instance, "instance");
putAllAggregations(instance.getAggregations());
MapPath errorValue = instance.getError();
if (errorValue != null) {
error(errorValue);
}
hits(instance.getHits());
Integer numberOfReducePhasesValue = instance.getNumberOfReducePhases();
if (numberOfReducePhasesValue != null) {
numberOfReducePhases(numberOfReducePhasesValue);
}
putAllProperties(instance.getProperties());
String scrollIdValue = instance.getScrollId();
if (scrollIdValue != null) {
scrollId(scrollIdValue);
}
Shards shardsValue = instance.getShards();
if (shardsValue != null) {
shards(shardsValue);
}
Integer tookValue = instance.getTook();
if (tookValue != null) {
took(tookValue);
}
Boolean terminatedEarlyValue = instance.isTerminatedEarly();
if (terminatedEarlyValue != null) {
terminatedEarly(terminatedEarlyValue);
}
Boolean timedOutValue = instance.isTimedOut();
if (timedOutValue != null) {
timedOut(timedOutValue);
}
return this;
}
/**
* Put one entry to the {@link SearchResponse#getAggregations() aggregations} map.
* @param key The key in the aggregations map
* @param value The associated value in the aggregations map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAggregation(String key, MapPath value) {
this.aggregations.put(key, value);
optBits |= OPT_BIT_AGGREGATIONS;
return this;
}
/**
* Put one entry to the {@link SearchResponse#getAggregations() aggregations} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAggregation(Map.Entry entry) {
this.aggregations.put(entry);
optBits |= OPT_BIT_AGGREGATIONS;
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link SearchResponse#getAggregations() aggregations} map. Nulls are not permitted
* @param entries The entries that will be added to the aggregations map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("aggregations")
public final Builder aggregations(Map entries) {
this.aggregations = ImmutableMap.builder();
optBits |= OPT_BIT_AGGREGATIONS;
return putAllAggregations(entries);
}
/**
* Put all mappings from the specified map as entries to {@link SearchResponse#getAggregations() aggregations} map. Nulls are not permitted
* @param entries The entries that will be added to the aggregations map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllAggregations(Map entries) {
this.aggregations.putAll(entries);
optBits |= OPT_BIT_AGGREGATIONS;
return this;
}
/**
* Initializes the value for the {@link SearchResponse#getError() error} attribute.
* @param error The value for error (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("error")
public final Builder error(@Nullable MapPath error) {
this.error = error;
return this;
}
/**
* Initializes the value for the {@link SearchResponse#getHits() hits} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link SearchResponse#getHits() hits}.
* @param hits The value for hits
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("hits")
public final Builder hits(SearchHits hits) {
this.hits = Objects.requireNonNull(hits, "hits");
return this;
}
/**
* Initializes the value for the {@link SearchResponse#getNumberOfReducePhases() numberOfReducePhases} attribute.
* @param numberOfReducePhases The value for numberOfReducePhases (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("num_reduce_phases")
public final Builder numberOfReducePhases(@Nullable Integer numberOfReducePhases) {
this.numberOfReducePhases = numberOfReducePhases;
return this;
}
/**
* Put one entry to the {@link SearchResponse#getProperties() properties} map.
* @param key The key in the properties map
* @param value The associated value in the properties map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonAnySetter
public final Builder putProperty(String key, Object value) {
this.properties.put(key, value);
optBits |= OPT_BIT_PROPERTIES;
return this;
}
/**
* Put one entry to the {@link SearchResponse#getProperties() properties} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putProperty(Map.Entry entry) {
this.properties.put(entry);
optBits |= OPT_BIT_PROPERTIES;
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link SearchResponse#getProperties() properties} map. Nulls are not permitted
* @param entries The entries that will be added to the properties map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("properties")
public final Builder properties(Map entries) {
this.properties = ImmutableMap.builder();
optBits |= OPT_BIT_PROPERTIES;
return putAllProperties(entries);
}
/**
* Put all mappings from the specified map as entries to {@link SearchResponse#getProperties() properties} map. Nulls are not permitted
* @param entries The entries that will be added to the properties map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllProperties(Map entries) {
this.properties.putAll(entries);
optBits |= OPT_BIT_PROPERTIES;
return this;
}
/**
* Initializes the value for the {@link SearchResponse#getScrollId() scrollId} attribute.
* @param scrollId The value for scrollId (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_scroll_id")
public final Builder scrollId(@Nullable String scrollId) {
this.scrollId = scrollId;
return this;
}
/**
* Initializes the value for the {@link SearchResponse#getShards() shards} attribute.
* @param shards The value for shards (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("_shards")
public final Builder shards(@Nullable Shards shards) {
this.shards = shards;
return this;
}
/**
* Initializes the value for the {@link SearchResponse#getTook() took} attribute.
* @param took The value for took (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("took")
public final Builder took(@Nullable Integer took) {
this.took = took;
return this;
}
/**
* Initializes the value for the {@link SearchResponse#isTerminatedEarly() terminatedEarly} attribute.
* @param terminatedEarly The value for terminatedEarly (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("terminated_early")
public final Builder terminatedEarly(@Nullable Boolean terminatedEarly) {
this.terminatedEarly = terminatedEarly;
return this;
}
/**
* Initializes the value for the {@link SearchResponse#isTimedOut() timedOut} attribute.
* @param timedOut The value for timedOut (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("timed_out")
public final Builder timedOut(@Nullable Boolean timedOut) {
this.timedOut = timedOut;
return this;
}
/**
* Builds a new {@link ImmutableSearchResponse ImmutableSearchResponse}.
* @return An immutable instance of SearchResponse
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSearchResponse build() {
return new ImmutableSearchResponse(this);
}
private boolean aggregationsIsSet() {
return (optBits & OPT_BIT_AGGREGATIONS) != 0;
}
private boolean propertiesIsSet() {
return (optBits & OPT_BIT_PROPERTIES) != 0;
}
}
}