com.arakelian.elastic.model.ImmutableBulkIndexerStats Maven / Gradle / Ivy
package com.arakelian.elastic.model;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Longs;
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 BulkIndexerStats}.
*
* Use the builder to create immutable instances:
* {@code ImmutableBulkIndexerStats.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableBulkIndexerStats implements BulkIndexerStats {
private final int failed;
private final int retries;
private final int submitted;
private final int successful;
private transient final int total;
private final long totalBytes;
private ImmutableBulkIndexerStats(ImmutableBulkIndexerStats.Builder builder) {
this.failed = builder.failed;
this.retries = builder.retries;
this.submitted = builder.submitted;
this.successful = builder.successful;
this.totalBytes = builder.totalBytes;
this.total = BulkIndexerStats.super.getTotal();
}
/**
* @return The value of the {@code failed} attribute
*/
@Override
public int getFailed() {
return failed;
}
/**
* @return The value of the {@code retries} attribute
*/
@Override
public int getRetries() {
return retries;
}
/**
* @return The value of the {@code submitted} attribute
*/
@Override
public int getSubmitted() {
return submitted;
}
/**
* @return The value of the {@code successful} attribute
*/
@Override
public int getSuccessful() {
return successful;
}
/**
* @return The computed-at-construction value of the {@code total} attribute
*/
@Override
public int getTotal() {
return total;
}
/**
* @return The value of the {@code totalBytes} attribute
*/
@Override
public long getTotalBytes() {
return totalBytes;
}
/**
* This instance is equal to all instances of {@code ImmutableBulkIndexerStats} 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 ImmutableBulkIndexerStats
&& equalTo((ImmutableBulkIndexerStats) another);
}
private boolean equalTo(ImmutableBulkIndexerStats another) {
return failed == another.failed
&& retries == another.retries
&& submitted == another.submitted
&& successful == another.successful
&& total == another.total
&& totalBytes == another.totalBytes;
}
/**
* Computes a hash code from attributes: {@code failed}, {@code retries}, {@code submitted}, {@code successful}, {@code total}, {@code totalBytes}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + failed;
h += (h << 5) + retries;
h += (h << 5) + submitted;
h += (h << 5) + successful;
h += (h << 5) + total;
h += (h << 5) + Longs.hashCode(totalBytes);
return h;
}
/**
* Prints the immutable value {@code BulkIndexerStats} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("BulkIndexerStats")
.omitNullValues()
.add("failed", failed)
.add("retries", retries)
.add("submitted", submitted)
.add("successful", successful)
.add("total", total)
.add("totalBytes", totalBytes)
.toString();
}
/**
* Creates a builder for {@link ImmutableBulkIndexerStats ImmutableBulkIndexerStats}.
* @return A new ImmutableBulkIndexerStats builder
*/
public static ImmutableBulkIndexerStats.Builder builder() {
return new ImmutableBulkIndexerStats.Builder();
}
/**
* Builds instances of type {@link ImmutableBulkIndexerStats ImmutableBulkIndexerStats}.
* 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 static final long INIT_BIT_FAILED = 0x1L;
private static final long INIT_BIT_RETRIES = 0x2L;
private static final long INIT_BIT_SUBMITTED = 0x4L;
private static final long INIT_BIT_SUCCESSFUL = 0x8L;
private static final long INIT_BIT_TOTAL_BYTES = 0x10L;
private long initBits = 0x1fL;
private int failed;
private int retries;
private int submitted;
private int successful;
private long totalBytes;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code BulkIndexerStats} 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(BulkIndexerStats instance) {
Objects.requireNonNull(instance, "instance");
failed(instance.getFailed());
retries(instance.getRetries());
submitted(instance.getSubmitted());
successful(instance.getSuccessful());
totalBytes(instance.getTotalBytes());
return this;
}
/**
* Initializes the value for the {@link BulkIndexerStats#getFailed() failed} attribute.
* @param failed The value for failed
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder failed(int failed) {
this.failed = failed;
initBits &= ~INIT_BIT_FAILED;
return this;
}
/**
* Initializes the value for the {@link BulkIndexerStats#getRetries() retries} attribute.
* @param retries The value for retries
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder retries(int retries) {
this.retries = retries;
initBits &= ~INIT_BIT_RETRIES;
return this;
}
/**
* Initializes the value for the {@link BulkIndexerStats#getSubmitted() submitted} attribute.
* @param submitted The value for submitted
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder submitted(int submitted) {
this.submitted = submitted;
initBits &= ~INIT_BIT_SUBMITTED;
return this;
}
/**
* Initializes the value for the {@link BulkIndexerStats#getSuccessful() successful} attribute.
* @param successful The value for successful
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder successful(int successful) {
this.successful = successful;
initBits &= ~INIT_BIT_SUCCESSFUL;
return this;
}
/**
* Initializes the value for the {@link BulkIndexerStats#getTotalBytes() totalBytes} attribute.
* @param totalBytes The value for totalBytes
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder totalBytes(long totalBytes) {
this.totalBytes = totalBytes;
initBits &= ~INIT_BIT_TOTAL_BYTES;
return this;
}
/**
* Builds a new {@link ImmutableBulkIndexerStats ImmutableBulkIndexerStats}.
* @return An immutable instance of BulkIndexerStats
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableBulkIndexerStats build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableBulkIndexerStats(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_FAILED) != 0) attributes.add("failed");
if ((initBits & INIT_BIT_RETRIES) != 0) attributes.add("retries");
if ((initBits & INIT_BIT_SUBMITTED) != 0) attributes.add("submitted");
if ((initBits & INIT_BIT_SUCCESSFUL) != 0) attributes.add("successful");
if ((initBits & INIT_BIT_TOTAL_BYTES) != 0) attributes.add("totalBytes");
return "Cannot build BulkIndexerStats, some of required attributes are not set " + attributes;
}
}
}