
org.glowroot.ui.ImmutablePercentileMergedAggregate Maven / Gradle / Ivy
package org.glowroot.ui;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.agent.shaded.google.common.base.MoreObjects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.ImmutableList;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Doubles;
import org.glowroot.agent.shaded.google.common.primitives.Longs;
import java.util.List;
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 TransactionJsonService.PercentileMergedAggregate}.
*
* Use builder to create immutable instances:
* {@code ImmutablePercentileMergedAggregate.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "TransactionJsonService.PercentileMergedAggregate"})
@Immutable
final class ImmutablePercentileMergedAggregate
implements TransactionJsonService.PercentileMergedAggregate {
private final long transactionCount;
private final double totalNanos;
private final ImmutableList percentileValues;
private ImmutablePercentileMergedAggregate(
long transactionCount,
double totalNanos,
ImmutableList percentileValues) {
this.transactionCount = transactionCount;
this.totalNanos = totalNanos;
this.percentileValues = percentileValues;
}
/**
* @return value of {@code transactionCount} attribute
*/
@JsonProperty
@Override
public long transactionCount() {
return transactionCount;
}
/**
* @return value of {@code totalNanos} attribute
*/
@JsonProperty
@Override
public double totalNanos() {
return totalNanos;
}
/**
* @return value of {@code percentileValues} attribute
*/
@JsonProperty
@Override
public ImmutableList percentileValues() {
return percentileValues;
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.PercentileMergedAggregate#transactionCount() transactionCount}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for transactionCount
* @return modified copy of the {@code this} object
*/
public final ImmutablePercentileMergedAggregate withTransactionCount(long value) {
if (this.transactionCount == value) return this;
long newValue = value;
return new ImmutablePercentileMergedAggregate(newValue, this.totalNanos, this.percentileValues);
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.PercentileMergedAggregate#totalNanos() totalNanos}.
* @param value new value for totalNanos
* @return modified copy of the {@code this} object
*/
public final ImmutablePercentileMergedAggregate withTotalNanos(double value) {
double newValue = value;
return new ImmutablePercentileMergedAggregate(this.transactionCount, newValue, this.percentileValues);
}
/**
* Copy current immutable object with elements that replace content of {@link TransactionJsonService.PercentileMergedAggregate#percentileValues() percentileValues}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutablePercentileMergedAggregate withPercentileValues(AggregateMerging.PercentileValue... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePercentileMergedAggregate(this.transactionCount, this.totalNanos, newValue);
}
/**
* Copy current immutable object with elements that replace content of {@link TransactionJsonService.PercentileMergedAggregate#percentileValues() percentileValues}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of percentileValues elements to set
* @return modified copy of {@code this} object
*/
public final ImmutablePercentileMergedAggregate withPercentileValues(Iterable extends AggregateMerging.PercentileValue> elements) {
if (this.percentileValues == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePercentileMergedAggregate(this.transactionCount, this.totalNanos, newValue);
}
/**
* This instance is equal to instances of {@code ImmutablePercentileMergedAggregate} with 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 ImmutablePercentileMergedAggregate
&& equalTo((ImmutablePercentileMergedAggregate) another);
}
private boolean equalTo(ImmutablePercentileMergedAggregate another) {
return transactionCount == another.transactionCount
&& Double.doubleToLongBits(totalNanos) == Double.doubleToLongBits(another.totalNanos)
&& percentileValues.equals(another.percentileValues);
}
/**
* Computes hash code from attributes: {@code transactionCount}, {@code totalNanos}, {@code percentileValues}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Longs.hashCode(transactionCount);
h = h * 17 + Doubles.hashCode(totalNanos);
h = h * 17 + percentileValues.hashCode();
return h;
}
/**
* Prints immutable value {@code PercentileMergedAggregate...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("PercentileMergedAggregate")
.add("transactionCount", transactionCount)
.add("totalNanos", totalNanos)
.add("percentileValues", percentileValues)
.toString();
}
/**
* Simple representation of this value type suitable Jackson binding
* @deprecated Do not use this type directly, it exists only for Jackson-binding infrastructure
*/
@Deprecated
static final class Json {
@JsonProperty
@Nullable Long transactionCount;
@JsonProperty
@Nullable java.lang.Double totalNanos;
@JsonProperty
@Nullable ImmutableList percentileValues;
}
/**
* @param json JSON-bindable data structure
* @return immutable value type
* @deprecated Do not use this method directly, it exists only for Jackson-binding infrastructure
*/
@Deprecated
@JsonCreator
static ImmutablePercentileMergedAggregate fromJson(Json json) {
ImmutablePercentileMergedAggregate.Builder builder = ImmutablePercentileMergedAggregate.builder();
if (json.transactionCount != null) {
builder.transactionCount(json.transactionCount);
}
if (json.totalNanos != null) {
builder.totalNanos(json.totalNanos);
}
if (json.percentileValues != null) {
builder.addAllPercentileValues(json.percentileValues);
}
return builder.build();
}
/**
* Creates immutable copy of {@link TransactionJsonService.PercentileMergedAggregate}.
* Uses accessors to get values to initialize immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance instance to copy
* @return copied immutable PercentileMergedAggregate instance
*/
static ImmutablePercentileMergedAggregate copyOf(TransactionJsonService.PercentileMergedAggregate instance) {
if (instance instanceof ImmutablePercentileMergedAggregate) {
return (ImmutablePercentileMergedAggregate) instance;
}
return ImmutablePercentileMergedAggregate.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutablePercentileMergedAggregate ImmutablePercentileMergedAggregate}.
* @return new ImmutablePercentileMergedAggregate builder
*/
static ImmutablePercentileMergedAggregate.Builder builder() {
return new ImmutablePercentileMergedAggregate.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutablePercentileMergedAggregate ImmutablePercentileMergedAggregate}.
* Initialize attributes and then invoke {@link #build()} method to create
* immutable instance.
* {@code Builder} is not thread safe and generally should not be stored in field or collection,
* but used immediately to create instances.
*/
@NotThreadSafe
static final class Builder {
private static final long INIT_BIT_TRANSACTION_COUNT = 0x1L;
private static final long INIT_BIT_TOTAL_NANOS = 0x2L;
private long initBits = 0x3;
private long transactionCount;
private double totalNanos;
private ImmutableList.Builder percentileValuesBuilder = ImmutableList.builder();
private Builder() {}
/**
* Fill builder with attribute values from provided {@link TransactionJsonService.PercentileMergedAggregate} instance.
* Regular attribute values will be replaced with ones of an instance.
* Instance's absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance instance to copy values from
* @return {@code this} builder for chained invocation
*/
public final Builder copyFrom(TransactionJsonService.PercentileMergedAggregate instance) {
Preconditions.checkNotNull(instance);
transactionCount(instance.transactionCount());
totalNanos(instance.totalNanos());
addAllPercentileValues(instance.percentileValues());
return this;
}
/**
* Initializes value for {@link TransactionJsonService.PercentileMergedAggregate#transactionCount() transactionCount}.
* @param transactionCount value for transactionCount
* @return {@code this} builder for chained invocation
*/
public final Builder transactionCount(long transactionCount) {
this.transactionCount = transactionCount;
initBits &= ~INIT_BIT_TRANSACTION_COUNT;
return this;
}
/**
* Initializes value for {@link TransactionJsonService.PercentileMergedAggregate#totalNanos() totalNanos}.
* @param totalNanos value for totalNanos
* @return {@code this} builder for chained invocation
*/
public final Builder totalNanos(double totalNanos) {
this.totalNanos = totalNanos;
initBits &= ~INIT_BIT_TOTAL_NANOS;
return this;
}
/**
* Adds one element to {@link TransactionJsonService.PercentileMergedAggregate#percentileValues() percentileValues} list.
* @param element percentileValues element
* @return {@code this} builder for chained invocation
*/
public final Builder addPercentileValues(AggregateMerging.PercentileValue element) {
percentileValuesBuilder.add(element);
return this;
}
/**
* Adds elements to {@link TransactionJsonService.PercentileMergedAggregate#percentileValues() percentileValues} list.
* @param elements array of percentileValues elements
* @return {@code this} builder for chained invocation
*/
public final Builder addPercentileValues(AggregateMerging.PercentileValue... elements) {
percentileValuesBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link TransactionJsonService.PercentileMergedAggregate#percentileValues() percentileValues} list.
* @param elements iterable of percentileValues elements
* @return {@code this} builder for chained invocation
*/
public final Builder percentileValues(Iterable extends AggregateMerging.PercentileValue> elements) {
percentileValuesBuilder = ImmutableList.builder();
return addAllPercentileValues(elements);
}
/**
* Adds elements to {@link TransactionJsonService.PercentileMergedAggregate#percentileValues() percentileValues} list.
* @param elements iterable of percentileValues elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllPercentileValues(Iterable extends AggregateMerging.PercentileValue> elements) {
percentileValuesBuilder.addAll(elements);
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutablePercentileMergedAggregate ImmutablePercentileMergedAggregate}.
* @return immutable instance of PercentileMergedAggregate
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutablePercentileMergedAggregate build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutablePercentileMergedAggregate(transactionCount, totalNanos, percentileValuesBuilder.build());
}
private boolean transactionCountIsSet() {
return (initBits & INIT_BIT_TRANSACTION_COUNT) == 0;
}
private boolean totalNanosIsSet() {
return (initBits & INIT_BIT_TOTAL_NANOS) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!transactionCountIsSet()) attributes.add("transactionCount");
if (!totalNanosIsSet()) attributes.add("totalNanos");
return "Cannot build PercentileMergedAggregate, some of required attributes are not set " + attributes;
}
}
}