com.arakelian.elastic.model.search.ImmutableIndexedShape Maven / Gradle / Ivy
package com.arakelian.elastic.model.search;
import com.arakelian.core.feature.Nullable;
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 IndexedShape}.
*
* Use the builder to create immutable instances:
* {@code ImmutableIndexedShape.builder()}.
*/
@Generated(from = "IndexedShape", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableIndexedShape implements IndexedShape {
private final @Nullable String id;
private final String index;
private final @Nullable String path;
private final String type;
private ImmutableIndexedShape(ImmutableIndexedShape.Builder builder) {
this.id = builder.id;
this.path = builder.path;
if (builder.index != null) {
initShim.index(builder.index);
}
if (builder.type != null) {
initShim.type(builder.type);
}
this.index = initShim.getIndex();
this.type = initShim.getType();
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 = "IndexedShape", generator = "Immutables")
private final class InitShim {
private byte indexBuildStage = STAGE_UNINITIALIZED;
private String index;
String getIndex() {
if (indexBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (indexBuildStage == STAGE_UNINITIALIZED) {
indexBuildStage = STAGE_INITIALIZING;
this.index = Objects.requireNonNull(getIndexInitialize(), "index");
indexBuildStage = STAGE_INITIALIZED;
}
return this.index;
}
void index(String index) {
this.index = index;
indexBuildStage = STAGE_INITIALIZED;
}
private byte typeBuildStage = STAGE_UNINITIALIZED;
private String type;
String getType() {
if (typeBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (typeBuildStage == STAGE_UNINITIALIZED) {
typeBuildStage = STAGE_INITIALIZING;
this.type = Objects.requireNonNull(getTypeInitialize(), "type");
typeBuildStage = STAGE_INITIALIZED;
}
return this.type;
}
void type(String type) {
this.type = type;
typeBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (indexBuildStage == STAGE_INITIALIZING) attributes.add("index");
if (typeBuildStage == STAGE_INITIALIZING) attributes.add("type");
return "Cannot build IndexedShape, attribute initializers form cycle " + attributes;
}
}
private String getIndexInitialize() {
return IndexedShape.super.getIndex();
}
private String getTypeInitialize() {
return IndexedShape.super.getType();
}
/**
* Returns the ID of the document that containing the pre-indexed shape.
* @return ID of the document that containing the pre-indexed shape.
*/
@JsonProperty("id")
@Override
public @Nullable String getId() {
return id;
}
/**
* Returns name of the index where the pre-indexed shape is. Defaults to "shapes".
* @return name of the index where the pre-indexed shape is
*/
@JsonProperty("index")
@Override
public String getIndex() {
InitShim shim = this.initShim;
return shim != null
? shim.getIndex()
: this.index;
}
/**
* Returns the field specified as path containing the pre-indexed shape. Defaults to "shape".
* @return the field specified as path containing the pre-indexed shape
*/
@JsonProperty("path")
@Override
public @Nullable String getPath() {
return path;
}
/**
* Returns index type where the pre-indexed shape is.
* @return index type where the pre-indexed shape is.
*/
@JsonProperty("type")
@Override
public String getType() {
InitShim shim = this.initShim;
return shim != null
? shim.getType()
: this.type;
}
/**
* This instance is equal to all instances of {@code ImmutableIndexedShape} 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 ImmutableIndexedShape
&& equalTo((ImmutableIndexedShape) another);
}
private boolean equalTo(ImmutableIndexedShape another) {
return Objects.equals(id, another.id)
&& index.equals(another.index)
&& Objects.equals(path, another.path)
&& type.equals(another.type);
}
/**
* Computes a hash code from attributes: {@code id}, {@code index}, {@code path}, {@code type}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(id);
h += (h << 5) + index.hashCode();
h += (h << 5) + Objects.hashCode(path);
h += (h << 5) + type.hashCode();
return h;
}
/**
* Prints the immutable value {@code IndexedShape} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("IndexedShape")
.omitNullValues()
.add("id", id)
.add("index", index)
.add("path", path)
.add("type", type)
.toString();
}
/**
* Creates a builder for {@link ImmutableIndexedShape ImmutableIndexedShape}.
* @return A new ImmutableIndexedShape builder
*/
public static ImmutableIndexedShape.Builder builder() {
return new ImmutableIndexedShape.Builder();
}
/**
* Builds instances of type {@link ImmutableIndexedShape ImmutableIndexedShape}.
* 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 = "IndexedShape", generator = "Immutables")
@NotThreadSafe
@JsonPropertyOrder({"index", "type", "id", "path"})
public static final class Builder {
private @javax.annotation.Nullable String id;
private @javax.annotation.Nullable String index;
private @javax.annotation.Nullable String path;
private @javax.annotation.Nullable String type;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code IndexedShape} 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(IndexedShape instance) {
Objects.requireNonNull(instance, "instance");
String idValue = instance.getId();
if (idValue != null) {
id(idValue);
}
index(instance.getIndex());
String pathValue = instance.getPath();
if (pathValue != null) {
path(pathValue);
}
type(instance.getType());
return this;
}
/**
* Initializes the value for the {@link IndexedShape#getId() id} attribute.
* @param id The value for id (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("id")
public final Builder id(@Nullable String id) {
this.id = id;
return this;
}
/**
* Initializes the value for the {@link IndexedShape#getIndex() index} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link IndexedShape#getIndex() index}.
* @param index The value for index
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("index")
public final Builder index(String index) {
this.index = Objects.requireNonNull(index, "index");
return this;
}
/**
* Initializes the value for the {@link IndexedShape#getPath() path} attribute.
* @param path The value for path (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("path")
public final Builder path(@Nullable String path) {
this.path = path;
return this;
}
/**
* Initializes the value for the {@link IndexedShape#getType() type} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link IndexedShape#getType() type}.
* @param type The value for type
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("type")
public final Builder type(String type) {
this.type = Objects.requireNonNull(type, "type");
return this;
}
/**
* Builds a new {@link ImmutableIndexedShape ImmutableIndexedShape}.
* @return An immutable instance of IndexedShape
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableIndexedShape build() {
return new ImmutableIndexedShape(this);
}
}
}