com.arakelian.elastic.model.ImmutableElasticError Maven / Gradle / Ivy
package com.arakelian.elastic.model;
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.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link ElasticError}.
*
* Use the builder to create immutable instances:
* {@code ImmutableElasticError.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableElasticError implements ElasticError {
private final Cause error;
private final int status;
private ImmutableElasticError(ImmutableElasticError.Builder builder) {
this.error = builder.error;
this.status = builder.status;
}
/**
* @return The value of the {@code error} attribute
*/
@JsonProperty("error")
@Override
public Cause getError() {
return error;
}
/**
* @return The value of the {@code status} attribute
*/
@JsonProperty("status")
@Override
public int getStatus() {
return status;
}
/**
* This instance is equal to all instances of {@code ImmutableElasticError} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableElasticError
&& equalTo((ImmutableElasticError) another);
}
private boolean equalTo(ImmutableElasticError another) {
return error.equals(another.error)
&& status == another.status;
}
/**
* Computes a hash code from attributes: {@code error}, {@code status}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + error.hashCode();
h += (h << 5) + status;
return h;
}
/**
* Prints the immutable value {@code ElasticError} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ElasticError")
.omitNullValues()
.add("error", error)
.add("status", status)
.toString();
}
/**
* Creates a builder for {@link ImmutableElasticError ImmutableElasticError}.
* @return A new ImmutableElasticError builder
*/
public static ImmutableElasticError.Builder builder() {
return new ImmutableElasticError.Builder();
}
/**
* Builds instances of type {@link ImmutableElasticError ImmutableElasticError}.
* 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({"status", "error"})
public static final class Builder {
private static final long INIT_BIT_ERROR = 0x1L;
private static final long INIT_BIT_STATUS = 0x2L;
private long initBits = 0x3L;
private @Nullable Cause error;
private int status;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ElasticError} 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(ElasticError instance) {
Objects.requireNonNull(instance, "instance");
error(instance.getError());
status(instance.getStatus());
return this;
}
/**
* Initializes the value for the {@link ElasticError#getError() error} attribute.
* @param error The value for error
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("error")
public final Builder error(Cause error) {
this.error = Objects.requireNonNull(error, "error");
initBits &= ~INIT_BIT_ERROR;
return this;
}
/**
* Initializes the value for the {@link ElasticError#getStatus() status} attribute.
* @param status The value for status
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("status")
public final Builder status(int status) {
this.status = status;
initBits &= ~INIT_BIT_STATUS;
return this;
}
/**
* Builds a new {@link ImmutableElasticError ImmutableElasticError}.
* @return An immutable instance of ElasticError
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableElasticError build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableElasticError(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_ERROR) != 0) attributes.add("error");
if ((initBits & INIT_BIT_STATUS) != 0) attributes.add("status");
return "Cannot build ElasticError, some of required attributes are not set " + attributes;
}
}
}