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

com.arakelian.elastic.model.ImmutableItem Maven / Gradle / Ivy

package com.arakelian.elastic.model;

import com.arakelian.core.feature.Nullable;
import com.arakelian.elastic.bulk.BulkOperation;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Booleans;
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.Generated;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;

/**
 * Immutable implementation of {@link BulkResponse.Item}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableItem.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableItem extends BulkResponse.Item { private transient final BulkResponse.BulkOperationResponse get; private transient final BulkOperation.Action action; private final @Nullable BulkResponse.BulkOperationResponse create; private final @Nullable BulkResponse.BulkOperationResponse delete; private final @Nullable BulkResponse.BulkOperationResponse index; private final @Nullable BulkResponse.BulkOperationResponse update; private transient final boolean successful; private ImmutableItem(ImmutableItem.Builder builder) { this.create = builder.create; this.delete = builder.delete; this.index = builder.index; this.update = builder.update; this.get = initShim.get(); this.action = initShim.getAction(); this.successful = initShim.isSuccessful(); 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(); private final class InitShim { private byte getBuildStage = STAGE_UNINITIALIZED; private BulkResponse.BulkOperationResponse get; BulkResponse.BulkOperationResponse get() { if (getBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (getBuildStage == STAGE_UNINITIALIZED) { getBuildStage = STAGE_INITIALIZING; this.get = Objects.requireNonNull(ImmutableItem.super.get(), "get"); getBuildStage = STAGE_INITIALIZED; } return this.get; } private byte actionBuildStage = STAGE_UNINITIALIZED; private BulkOperation.Action action; BulkOperation.Action getAction() { if (actionBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (actionBuildStage == STAGE_UNINITIALIZED) { actionBuildStage = STAGE_INITIALIZING; this.action = Objects.requireNonNull(ImmutableItem.super.getAction(), "action"); actionBuildStage = STAGE_INITIALIZED; } return this.action; } private byte successfulBuildStage = STAGE_UNINITIALIZED; private boolean successful; boolean isSuccessful() { if (successfulBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (successfulBuildStage == STAGE_UNINITIALIZED) { successfulBuildStage = STAGE_INITIALIZING; this.successful = ImmutableItem.super.isSuccessful(); successfulBuildStage = STAGE_INITIALIZED; } return this.successful; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (getBuildStage == STAGE_INITIALIZING) attributes.add("get"); if (actionBuildStage == STAGE_INITIALIZING) attributes.add("action"); if (successfulBuildStage == STAGE_INITIALIZING) attributes.add("successful"); return "Cannot build Item, attribute initializers form cycle " + attributes; } } /** * @return The computed-at-construction value of the {@code get} attribute */ @JsonProperty("get") @Override public BulkResponse.BulkOperationResponse get() { InitShim shim = this.initShim; return shim != null ? shim.get() : this.get; } /** * @return The computed-at-construction value of the {@code action} attribute */ @JsonProperty("action") @Override public BulkOperation.Action getAction() { InitShim shim = this.initShim; return shim != null ? shim.getAction() : this.action; } /** * @return The value of the {@code create} attribute */ @JsonProperty("create") @Override public @Nullable BulkResponse.BulkOperationResponse getCreate() { return create; } /** * @return The value of the {@code delete} attribute */ @JsonProperty("delete") @Override public @Nullable BulkResponse.BulkOperationResponse getDelete() { return delete; } /** * @return The value of the {@code index} attribute */ @JsonProperty("index") @Override public @Nullable BulkResponse.BulkOperationResponse getIndex() { return index; } /** * @return The value of the {@code update} attribute */ @JsonProperty("update") @Override public @Nullable BulkResponse.BulkOperationResponse getUpdate() { return update; } /** * @return The computed-at-construction value of the {@code successful} attribute */ @JsonProperty("successful") @Override public boolean isSuccessful() { InitShim shim = this.initShim; return shim != null ? shim.isSuccessful() : this.successful; } /** * This instance is equal to all instances of {@code ImmutableItem} 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 ImmutableItem && equalTo((ImmutableItem) another); } private boolean equalTo(ImmutableItem another) { return get.equals(another.get) && action.equals(another.action) && Objects.equals(create, another.create) && Objects.equals(delete, another.delete) && Objects.equals(index, another.index) && Objects.equals(update, another.update) && successful == another.successful; } /** * Computes a hash code from attributes: {@code get}, {@code action}, {@code create}, {@code delete}, {@code index}, {@code update}, {@code successful}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + get.hashCode(); h += (h << 5) + action.hashCode(); h += (h << 5) + Objects.hashCode(create); h += (h << 5) + Objects.hashCode(delete); h += (h << 5) + Objects.hashCode(index); h += (h << 5) + Objects.hashCode(update); h += (h << 5) + Booleans.hashCode(successful); return h; } /** * Prints the immutable value {@code Item} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Item") .omitNullValues() .add("get", get) .add("action", action) .add("create", create) .add("delete", delete) .add("index", index) .add("update", update) .add("successful", successful) .toString(); } private static ImmutableItem validate(ImmutableItem instance) { instance.checkItem(); return instance; } /** * Creates a builder for {@link ImmutableItem ImmutableItem}. * @return A new ImmutableItem builder */ public static ImmutableItem.Builder builder() { return new ImmutableItem.Builder(); } /** * Builds instances of type {@link ImmutableItem ImmutableItem}. * 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. */ @NotThreadSafe public static final class Builder { private @javax.annotation.Nullable BulkResponse.BulkOperationResponse create; private @javax.annotation.Nullable BulkResponse.BulkOperationResponse delete; private @javax.annotation.Nullable BulkResponse.BulkOperationResponse index; private @javax.annotation.Nullable BulkResponse.BulkOperationResponse update; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Item} 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(BulkResponse.Item instance) { Objects.requireNonNull(instance, "instance"); BulkResponse.BulkOperationResponse createValue = instance.getCreate(); if (createValue != null) { create(createValue); } BulkResponse.BulkOperationResponse deleteValue = instance.getDelete(); if (deleteValue != null) { delete(deleteValue); } BulkResponse.BulkOperationResponse indexValue = instance.getIndex(); if (indexValue != null) { index(indexValue); } BulkResponse.BulkOperationResponse updateValue = instance.getUpdate(); if (updateValue != null) { update(updateValue); } return this; } /** * Initializes the value for the {@link BulkResponse.Item#getCreate() create} attribute. * @param create The value for create (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("create") public final Builder create(@Nullable BulkResponse.BulkOperationResponse create) { this.create = create; return this; } /** * Initializes the value for the {@link BulkResponse.Item#getDelete() delete} attribute. * @param delete The value for delete (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("delete") public final Builder delete(@Nullable BulkResponse.BulkOperationResponse delete) { this.delete = delete; return this; } /** * Initializes the value for the {@link BulkResponse.Item#getIndex() index} attribute. * @param index The value for index (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("index") public final Builder index(@Nullable BulkResponse.BulkOperationResponse index) { this.index = index; return this; } /** * Initializes the value for the {@link BulkResponse.Item#getUpdate() update} attribute. * @param update The value for update (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("update") public final Builder update(@Nullable BulkResponse.BulkOperationResponse update) { this.update = update; return this; } /** * Builds a new {@link ImmutableItem ImmutableItem}. * @return An immutable instance of Item * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableItem build() { return ImmutableItem.validate(new ImmutableItem(this)); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy