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

com.arakelian.elastic.model.search.ImmutableSort Maven / Gradle / Ivy

package com.arakelian.elastic.model.search;

import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.model.Field;
import com.arakelian.elastic.model.enums.SortMode;
import com.arakelian.elastic.model.enums.SortOrder;
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.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 Sort}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableSort.builder()}. */ @Generated(from = "Sort", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableSort implements Sort { private final String fieldName; private final @Nullable SortMode mode; private final SortOrder order; private final @Nullable Field.Type unmappedType; private final boolean defaults; private ImmutableSort(ImmutableSort.Builder builder) { this.fieldName = builder.fieldName; this.mode = builder.mode; this.unmappedType = builder.unmappedType; if (builder.order != null) { initShim.order(builder.order); } this.order = initShim.getOrder(); this.defaults = initShim.isDefaults(); 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 = "Sort", generator = "Immutables") private final class InitShim { private byte orderBuildStage = STAGE_UNINITIALIZED; private SortOrder order; SortOrder getOrder() { if (orderBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (orderBuildStage == STAGE_UNINITIALIZED) { orderBuildStage = STAGE_INITIALIZING; this.order = Objects.requireNonNull(getOrderInitialize(), "order"); orderBuildStage = STAGE_INITIALIZED; } return this.order; } void order(SortOrder order) { this.order = order; orderBuildStage = STAGE_INITIALIZED; } private byte defaultsBuildStage = STAGE_UNINITIALIZED; private boolean defaults; boolean isDefaults() { if (defaultsBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (defaultsBuildStage == STAGE_UNINITIALIZED) { defaultsBuildStage = STAGE_INITIALIZING; this.defaults = isDefaultsInitialize(); defaultsBuildStage = STAGE_INITIALIZED; } return this.defaults; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (orderBuildStage == STAGE_INITIALIZING) attributes.add("order"); if (defaultsBuildStage == STAGE_INITIALIZING) attributes.add("defaults"); return "Cannot build Sort, attribute initializers form cycle " + attributes; } } private SortOrder getOrderInitialize() { return Sort.super.getOrder(); } private boolean isDefaultsInitialize() { return Sort.super.isDefaults(); } /** * @return The value of the {@code fieldName} attribute */ @JsonProperty("field") @Override public String getFieldName() { return fieldName; } /** * @return The value of the {@code mode} attribute */ @JsonProperty("mode") @Override public @Nullable SortMode getMode() { return mode; } /** * @return The value of the {@code order} attribute */ @JsonProperty("order") @Override public SortOrder getOrder() { InitShim shim = this.initShim; return shim != null ? shim.getOrder() : this.order; } /** * Returns the field type to emit when there is no mapping associated with a field. * Counterintuitively, this can happen when the Elastic index is empty. * @return the field type to emit when there is no mapping associated with a field. */ @JsonProperty("unmapped_type") @Override public @Nullable Field.Type getUnmappedType() { return unmappedType; } /** * @return The computed-at-construction value of the {@code defaults} attribute */ @JsonProperty("defaults") @JsonIgnore @Override public boolean isDefaults() { InitShim shim = this.initShim; return shim != null ? shim.isDefaults() : this.defaults; } /** * This instance is equal to all instances of {@code ImmutableSort} 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 ImmutableSort && equalTo((ImmutableSort) another); } private boolean equalTo(ImmutableSort another) { return fieldName.equals(another.fieldName) && Objects.equals(mode, another.mode) && order.equals(another.order) && Objects.equals(unmappedType, another.unmappedType); } /** * Computes a hash code from attributes: {@code fieldName}, {@code mode}, {@code order}, {@code unmappedType}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + fieldName.hashCode(); h += (h << 5) + Objects.hashCode(mode); h += (h << 5) + order.hashCode(); h += (h << 5) + Objects.hashCode(unmappedType); return h; } /** * Prints the immutable value {@code Sort} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Sort") .omitNullValues() .add("fieldName", fieldName) .add("mode", mode) .add("order", order) .add("unmappedType", unmappedType) .toString(); } /** * Creates a builder for {@link ImmutableSort ImmutableSort}. * @return A new ImmutableSort builder */ public static ImmutableSort.Builder builder() { return new ImmutableSort.Builder(); } /** * Builds instances of type {@link ImmutableSort ImmutableSort}. * 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 = "Sort", generator = "Immutables") @NotThreadSafe @JsonPropertyOrder({"field", "order", "unmapped_type", "mode"}) public static final class Builder { private static final long INIT_BIT_FIELD_NAME = 0x1L; private long initBits = 0x1L; private @javax.annotation.Nullable String fieldName; private @javax.annotation.Nullable SortMode mode; private @javax.annotation.Nullable SortOrder order; private @javax.annotation.Nullable Field.Type unmappedType; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Sort} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Sort instance) { Objects.requireNonNull(instance, "instance"); fieldName(instance.getFieldName()); SortMode modeValue = instance.getMode(); if (modeValue != null) { mode(modeValue); } order(instance.getOrder()); Field.Type unmappedTypeValue = instance.getUnmappedType(); if (unmappedTypeValue != null) { unmappedType(unmappedTypeValue); } return this; } /** * Initializes the value for the {@link Sort#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 Sort#getMode() mode} attribute. * @param mode The value for mode (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("mode") public final Builder mode(@Nullable SortMode mode) { this.mode = mode; return this; } /** * Initializes the value for the {@link Sort#getOrder() order} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link Sort#getOrder() order}. * @param order The value for order * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("order") public final Builder order(SortOrder order) { this.order = Objects.requireNonNull(order, "order"); return this; } /** * Initializes the value for the {@link Sort#getUnmappedType() unmappedType} attribute. * @param unmappedType The value for unmappedType (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("unmapped_type") public final Builder unmappedType(@Nullable Field.Type unmappedType) { this.unmappedType = unmappedType; return this; } /** * Builds a new {@link ImmutableSort ImmutableSort}. * @return An immutable instance of Sort * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableSort build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableSort(this); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_FIELD_NAME) != 0) attributes.add("fieldName"); return "Cannot build Sort, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy