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

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

package com.arakelian.elastic.model;

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.common.collect.ImmutableList;
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 Cause}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableCause.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableCause implements Cause { private final @Nullable Cause causedBy; private final @Nullable String index; private final @Nullable String indexUuid; private final String reason; private final @Nullable String resourceId; private final @Nullable String resourceType; private final @Nullable ImmutableList rootCause; private final @Nullable String shard; private final @Nullable String stackTrace; private final String type; private ImmutableCause(ImmutableCause.Builder builder) { this.causedBy = builder.causedBy; this.index = builder.index; this.indexUuid = builder.indexUuid; this.reason = builder.reason; this.resourceId = builder.resourceId; this.resourceType = builder.resourceType; this.rootCause = builder.rootCause == null ? null : builder.rootCause.build(); this.shard = builder.shard; this.stackTrace = builder.stackTrace; this.type = builder.type; } /** * @return The value of the {@code causedBy} attribute */ @JsonProperty("caused_by") @Override public @Nullable Cause getCausedBy() { return causedBy; } /** * @return The value of the {@code index} attribute */ @JsonProperty("index") @Override public @Nullable String getIndex() { return index; } /** * @return The value of the {@code indexUuid} attribute */ @JsonProperty("index_uuid") @Override public @Nullable String getIndexUuid() { return indexUuid; } /** * @return The value of the {@code reason} attribute */ @JsonProperty("reason") @Override public String getReason() { return reason; } /** * @return The value of the {@code resourceId} attribute */ @JsonProperty("resource.id") @Override public @Nullable String getResourceId() { return resourceId; } /** * @return The value of the {@code resourceType} attribute */ @JsonProperty("resource.type") @Override public @Nullable String getResourceType() { return resourceType; } /** * @return The value of the {@code rootCause} attribute */ @JsonProperty("root_cause") @Override public @Nullable ImmutableList getRootCause() { return rootCause; } /** * @return The value of the {@code shard} attribute */ @JsonProperty("shard") @Override public @Nullable String getShard() { return shard; } /** * @return The value of the {@code stackTrace} attribute */ @JsonProperty("stack_trace") @Override public @Nullable String getStackTrace() { return stackTrace; } /** * Returns the type of exception thrown by Elastic. * Examples include: *

    *
  • version_conflict_engine_exception (status: 409). When using internal versioning, this * exception is thrown if the _version provided does not match version in the index; when using * external versioning, this exception indicates that there is a newer version in index * already.
  • *
  • strict_dynamic_mapping_exception (status:400). Indicates that the source document * contained fields which are not part of the _index/_type mapping.
  • *
* @return the type of exception thrown by Elastic. */ @JsonProperty("type") @Override public String getType() { return type; } /** * This instance is equal to all instances of {@code ImmutableCause} 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 ImmutableCause && equalTo((ImmutableCause) another); } private boolean equalTo(ImmutableCause another) { return Objects.equals(causedBy, another.causedBy) && Objects.equals(index, another.index) && Objects.equals(indexUuid, another.indexUuid) && reason.equals(another.reason) && Objects.equals(resourceId, another.resourceId) && Objects.equals(resourceType, another.resourceType) && Objects.equals(rootCause, another.rootCause) && Objects.equals(shard, another.shard) && Objects.equals(stackTrace, another.stackTrace) && type.equals(another.type); } /** * Computes a hash code from attributes: {@code causedBy}, {@code index}, {@code indexUuid}, {@code reason}, {@code resourceId}, {@code resourceType}, {@code rootCause}, {@code shard}, {@code stackTrace}, {@code type}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + Objects.hashCode(causedBy); h += (h << 5) + Objects.hashCode(index); h += (h << 5) + Objects.hashCode(indexUuid); h += (h << 5) + reason.hashCode(); h += (h << 5) + Objects.hashCode(resourceId); h += (h << 5) + Objects.hashCode(resourceType); h += (h << 5) + Objects.hashCode(rootCause); h += (h << 5) + Objects.hashCode(shard); h += (h << 5) + Objects.hashCode(stackTrace); h += (h << 5) + type.hashCode(); return h; } /** * Prints the immutable value {@code Cause} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("Cause") .omitNullValues() .add("causedBy", causedBy) .add("index", index) .add("indexUuid", indexUuid) .add("reason", reason) .add("resourceId", resourceId) .add("resourceType", resourceType) .add("rootCause", rootCause) .add("shard", shard) .add("stackTrace", stackTrace) .add("type", type) .toString(); } /** * Creates a builder for {@link ImmutableCause ImmutableCause}. * @return A new ImmutableCause builder */ public static ImmutableCause.Builder builder() { return new ImmutableCause.Builder(); } /** * Builds instances of type {@link ImmutableCause ImmutableCause}. * 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 @JsonPropertyOrder({"type", "reason", "caused_by", "resource.type", "resource.id", "shard", "index", "index_uiud", "root_cause", "stack_trace"}) public static final class Builder { private static final long INIT_BIT_REASON = 0x1L; private static final long INIT_BIT_TYPE = 0x2L; private long initBits = 0x3L; private @javax.annotation.Nullable Cause causedBy; private @javax.annotation.Nullable String index; private @javax.annotation.Nullable String indexUuid; private @javax.annotation.Nullable String reason; private @javax.annotation.Nullable String resourceId; private @javax.annotation.Nullable String resourceType; private ImmutableList.Builder rootCause = null; private @javax.annotation.Nullable String shard; private @javax.annotation.Nullable String stackTrace; private @javax.annotation.Nullable String type; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Cause} 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(Cause instance) { Objects.requireNonNull(instance, "instance"); Cause causedByValue = instance.getCausedBy(); if (causedByValue != null) { causedBy(causedByValue); } String indexValue = instance.getIndex(); if (indexValue != null) { index(indexValue); } String indexUuidValue = instance.getIndexUuid(); if (indexUuidValue != null) { indexUuid(indexUuidValue); } reason(instance.getReason()); String resourceIdValue = instance.getResourceId(); if (resourceIdValue != null) { resourceId(resourceIdValue); } String resourceTypeValue = instance.getResourceType(); if (resourceTypeValue != null) { resourceType(resourceTypeValue); } List rootCauseValue = instance.getRootCause(); if (rootCauseValue != null) { addAllRootCause(rootCauseValue); } String shardValue = instance.getShard(); if (shardValue != null) { shard(shardValue); } String stackTraceValue = instance.getStackTrace(); if (stackTraceValue != null) { stackTrace(stackTraceValue); } type(instance.getType()); return this; } /** * Initializes the value for the {@link Cause#getCausedBy() causedBy} attribute. * @param causedBy The value for causedBy (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("caused_by") public final Builder causedBy(@Nullable Cause causedBy) { this.causedBy = causedBy; return this; } /** * Initializes the value for the {@link Cause#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 String index) { this.index = index; return this; } /** * Initializes the value for the {@link Cause#getIndexUuid() indexUuid} attribute. * @param indexUuid The value for indexUuid (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("index_uuid") public final Builder indexUuid(@Nullable String indexUuid) { this.indexUuid = indexUuid; return this; } /** * Initializes the value for the {@link Cause#getReason() reason} attribute. * @param reason The value for reason * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("reason") public final Builder reason(String reason) { this.reason = Objects.requireNonNull(reason, "reason"); initBits &= ~INIT_BIT_REASON; return this; } /** * Initializes the value for the {@link Cause#getResourceId() resourceId} attribute. * @param resourceId The value for resourceId (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("resource.id") public final Builder resourceId(@Nullable String resourceId) { this.resourceId = resourceId; return this; } /** * Initializes the value for the {@link Cause#getResourceType() resourceType} attribute. * @param resourceType The value for resourceType (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("resource.type") public final Builder resourceType(@Nullable String resourceType) { this.resourceType = resourceType; return this; } /** * Adds one element to {@link Cause#getRootCause() rootCause} list. * @param element A rootCause element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addRootCause(Cause element) { if (this.rootCause == null) { this.rootCause = ImmutableList.builder(); } this.rootCause.add(element); return this; } /** * Adds elements to {@link Cause#getRootCause() rootCause} list. * @param elements An array of rootCause elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addRootCause(Cause... elements) { if (this.rootCause == null) { this.rootCause = ImmutableList.builder(); } this.rootCause.add(elements); return this; } /** * Sets or replaces all elements for {@link Cause#getRootCause() rootCause} list. * @param elements An iterable of rootCause elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("root_cause") public final Builder rootCause(@Nullable Iterable elements) { if (elements == null) { this.rootCause = null; return this; } this.rootCause = ImmutableList.builder(); return addAllRootCause(elements); } /** * Adds elements to {@link Cause#getRootCause() rootCause} list. * @param elements An iterable of rootCause elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllRootCause(Iterable elements) { Objects.requireNonNull(elements, "rootCause element"); if (this.rootCause == null) { this.rootCause = ImmutableList.builder(); } this.rootCause.addAll(elements); return this; } /** * Initializes the value for the {@link Cause#getShard() shard} attribute. * @param shard The value for shard (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("shard") public final Builder shard(@Nullable String shard) { this.shard = shard; return this; } /** * Initializes the value for the {@link Cause#getStackTrace() stackTrace} attribute. * @param stackTrace The value for stackTrace (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("stack_trace") public final Builder stackTrace(@Nullable String stackTrace) { this.stackTrace = stackTrace; return this; } /** * Initializes the value for the {@link Cause#getType() type} attribute. * @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"); initBits &= ~INIT_BIT_TYPE; return this; } /** * Builds a new {@link ImmutableCause ImmutableCause}. * @return An immutable instance of Cause * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableCause build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableCause(this); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_REASON) != 0) attributes.add("reason"); if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type"); return "Cannot build Cause, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy