
org.glowroot.ui.ImmutableTimerMergedAggregate 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.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;
import org.glowroot.storage.repo.MutableTimer;
/**
* Immutable implementation of {@link AggregateMerging.TimerMergedAggregate}.
*
* Use builder to create immutable instances:
* {@code ImmutableTimerMergedAggregate.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "AggregateMerging.TimerMergedAggregate"})
@Immutable
final class ImmutableTimerMergedAggregate
implements AggregateMerging.TimerMergedAggregate {
private final long transactionCount;
private final ImmutableList rootTimers;
private ImmutableTimerMergedAggregate(
long transactionCount,
ImmutableList rootTimers) {
this.transactionCount = transactionCount;
this.rootTimers = rootTimers;
}
/**
* @return value of {@code transactionCount} attribute
*/
@JsonProperty
@Override
public long transactionCount() {
return transactionCount;
}
/**
* @return value of {@code rootTimers} attribute
*/
@JsonProperty
@Override
public ImmutableList rootTimers() {
return rootTimers;
}
/**
* Copy current immutable object by setting value for {@link AggregateMerging.TimerMergedAggregate#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 ImmutableTimerMergedAggregate withTransactionCount(long value) {
if (this.transactionCount == value) return this;
long newValue = value;
return new ImmutableTimerMergedAggregate(newValue, this.rootTimers);
}
/**
* Copy current immutable object with elements that replace content of {@link AggregateMerging.TimerMergedAggregate#rootTimers() rootTimers}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableTimerMergedAggregate withRootTimers(MutableTimer... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableTimerMergedAggregate(this.transactionCount, newValue);
}
/**
* Copy current immutable object with elements that replace content of {@link AggregateMerging.TimerMergedAggregate#rootTimers() rootTimers}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of rootTimers elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableTimerMergedAggregate withRootTimers(Iterable extends MutableTimer> elements) {
if (this.rootTimers == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableTimerMergedAggregate(this.transactionCount, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableTimerMergedAggregate} 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 ImmutableTimerMergedAggregate
&& equalTo((ImmutableTimerMergedAggregate) another);
}
private boolean equalTo(ImmutableTimerMergedAggregate another) {
return transactionCount == another.transactionCount
&& rootTimers.equals(another.rootTimers);
}
/**
* Computes hash code from attributes: {@code transactionCount}, {@code rootTimers}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Longs.hashCode(transactionCount);
h = h * 17 + rootTimers.hashCode();
return h;
}
/**
* Prints immutable value {@code TimerMergedAggregate...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("TimerMergedAggregate")
.add("transactionCount", transactionCount)
.add("rootTimers", rootTimers)
.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 List rootTimers;
}
/**
* @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 ImmutableTimerMergedAggregate fromJson(Json json) {
ImmutableTimerMergedAggregate.Builder builder = ImmutableTimerMergedAggregate.builder();
if (json.transactionCount != null) {
builder.transactionCount(json.transactionCount);
}
if (json.rootTimers != null) {
builder.addAllRootTimers(json.rootTimers);
}
return builder.build();
}
/**
* Creates immutable copy of {@link AggregateMerging.TimerMergedAggregate}.
* 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 TimerMergedAggregate instance
*/
static ImmutableTimerMergedAggregate copyOf(AggregateMerging.TimerMergedAggregate instance) {
if (instance instanceof ImmutableTimerMergedAggregate) {
return (ImmutableTimerMergedAggregate) instance;
}
return ImmutableTimerMergedAggregate.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableTimerMergedAggregate ImmutableTimerMergedAggregate}.
* @return new ImmutableTimerMergedAggregate builder
*/
static ImmutableTimerMergedAggregate.Builder builder() {
return new ImmutableTimerMergedAggregate.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableTimerMergedAggregate ImmutableTimerMergedAggregate}.
* 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 long initBits = 0x1;
private long transactionCount;
private ImmutableList.Builder rootTimersBuilder = ImmutableList.builder();
private Builder() {}
/**
* Fill builder with attribute values from provided {@link AggregateMerging.TimerMergedAggregate} 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(AggregateMerging.TimerMergedAggregate instance) {
Preconditions.checkNotNull(instance);
transactionCount(instance.transactionCount());
addAllRootTimers(instance.rootTimers());
return this;
}
/**
* Initializes value for {@link AggregateMerging.TimerMergedAggregate#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;
}
/**
* Adds one element to {@link AggregateMerging.TimerMergedAggregate#rootTimers() rootTimers} list.
* @param element rootTimers element
* @return {@code this} builder for chained invocation
*/
public final Builder addRootTimers(MutableTimer element) {
rootTimersBuilder.add(element);
return this;
}
/**
* Adds elements to {@link AggregateMerging.TimerMergedAggregate#rootTimers() rootTimers} list.
* @param elements array of rootTimers elements
* @return {@code this} builder for chained invocation
*/
public final Builder addRootTimers(MutableTimer... elements) {
rootTimersBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link AggregateMerging.TimerMergedAggregate#rootTimers() rootTimers} list.
* @param elements iterable of rootTimers elements
* @return {@code this} builder for chained invocation
*/
public final Builder rootTimers(Iterable extends MutableTimer> elements) {
rootTimersBuilder = ImmutableList.builder();
return addAllRootTimers(elements);
}
/**
* Adds elements to {@link AggregateMerging.TimerMergedAggregate#rootTimers() rootTimers} list.
* @param elements iterable of rootTimers elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllRootTimers(Iterable extends MutableTimer> elements) {
rootTimersBuilder.addAll(elements);
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutableTimerMergedAggregate ImmutableTimerMergedAggregate}.
* @return immutable instance of TimerMergedAggregate
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableTimerMergedAggregate build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableTimerMergedAggregate(transactionCount, rootTimersBuilder.build());
}
private boolean transactionCountIsSet() {
return (initBits & INIT_BIT_TRANSACTION_COUNT) == 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");
return "Cannot build TimerMergedAggregate, some of required attributes are not set " + attributes;
}
}
}