
org.glowroot.ui.ImmutableThreadInfoAggregate 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.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Doubles;
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 AggregateMerging.ThreadInfoAggregate}.
*
* Use builder to create immutable instances:
* {@code ImmutableThreadInfoAggregate.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "AggregateMerging.ThreadInfoAggregate"})
@Immutable
final class ImmutableThreadInfoAggregate extends AggregateMerging.ThreadInfoAggregate {
private final double totalCpuNanos;
private final double totalBlockedNanos;
private final double totalWaitedNanos;
private final double totalAllocatedBytes;
private ImmutableThreadInfoAggregate(double totalCpuNanos, double totalBlockedNanos, double totalWaitedNanos, double totalAllocatedBytes) {
this.totalCpuNanos = totalCpuNanos;
this.totalBlockedNanos = totalBlockedNanos;
this.totalWaitedNanos = totalWaitedNanos;
this.totalAllocatedBytes = totalAllocatedBytes;
}
/**
* @return value of {@code totalCpuNanos} attribute
*/
@JsonProperty
@Override
double totalCpuNanos() {
return totalCpuNanos;
}
/**
* @return value of {@code totalBlockedNanos} attribute
*/
@JsonProperty
@Override
double totalBlockedNanos() {
return totalBlockedNanos;
}
/**
* @return value of {@code totalWaitedNanos} attribute
*/
@JsonProperty
@Override
double totalWaitedNanos() {
return totalWaitedNanos;
}
/**
* @return value of {@code totalAllocatedBytes} attribute
*/
@JsonProperty
@Override
double totalAllocatedBytes() {
return totalAllocatedBytes;
}
/**
* Copy current immutable object by setting value for {@link AggregateMerging.ThreadInfoAggregate#totalCpuNanos() totalCpuNanos}.
* @param value new value for totalCpuNanos
* @return modified copy of the {@code this} object
*/
public final ImmutableThreadInfoAggregate withTotalCpuNanos(double value) {
double newValue = value;
return new ImmutableThreadInfoAggregate(newValue, this.totalBlockedNanos, this.totalWaitedNanos, this.totalAllocatedBytes);
}
/**
* Copy current immutable object by setting value for {@link AggregateMerging.ThreadInfoAggregate#totalBlockedNanos() totalBlockedNanos}.
* @param value new value for totalBlockedNanos
* @return modified copy of the {@code this} object
*/
public final ImmutableThreadInfoAggregate withTotalBlockedNanos(double value) {
double newValue = value;
return new ImmutableThreadInfoAggregate(this.totalCpuNanos, newValue, this.totalWaitedNanos, this.totalAllocatedBytes);
}
/**
* Copy current immutable object by setting value for {@link AggregateMerging.ThreadInfoAggregate#totalWaitedNanos() totalWaitedNanos}.
* @param value new value for totalWaitedNanos
* @return modified copy of the {@code this} object
*/
public final ImmutableThreadInfoAggregate withTotalWaitedNanos(double value) {
double newValue = value;
return new ImmutableThreadInfoAggregate(this.totalCpuNanos, this.totalBlockedNanos, newValue, this.totalAllocatedBytes);
}
/**
* Copy current immutable object by setting value for {@link AggregateMerging.ThreadInfoAggregate#totalAllocatedBytes() totalAllocatedBytes}.
* @param value new value for totalAllocatedBytes
* @return modified copy of the {@code this} object
*/
public final ImmutableThreadInfoAggregate withTotalAllocatedBytes(double value) {
double newValue = value;
return new ImmutableThreadInfoAggregate(this.totalCpuNanos, this.totalBlockedNanos, this.totalWaitedNanos, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableThreadInfoAggregate} 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 ImmutableThreadInfoAggregate
&& equalTo((ImmutableThreadInfoAggregate) another);
}
private boolean equalTo(ImmutableThreadInfoAggregate another) {
return Double.doubleToLongBits(totalCpuNanos) == Double.doubleToLongBits(another.totalCpuNanos)
&& Double.doubleToLongBits(totalBlockedNanos) == Double.doubleToLongBits(another.totalBlockedNanos)
&& Double.doubleToLongBits(totalWaitedNanos) == Double.doubleToLongBits(another.totalWaitedNanos)
&& Double.doubleToLongBits(totalAllocatedBytes) == Double.doubleToLongBits(another.totalAllocatedBytes);
}
/**
* Computes hash code from attributes: {@code totalCpuNanos}, {@code totalBlockedNanos}, {@code totalWaitedNanos}, {@code totalAllocatedBytes}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Doubles.hashCode(totalCpuNanos);
h = h * 17 + Doubles.hashCode(totalBlockedNanos);
h = h * 17 + Doubles.hashCode(totalWaitedNanos);
h = h * 17 + Doubles.hashCode(totalAllocatedBytes);
return h;
}
/**
* Prints immutable value {@code ThreadInfoAggregate...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ThreadInfoAggregate")
.add("totalCpuNanos", totalCpuNanos)
.add("totalBlockedNanos", totalBlockedNanos)
.add("totalWaitedNanos", totalWaitedNanos)
.add("totalAllocatedBytes", totalAllocatedBytes)
.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 java.lang.Double totalCpuNanos;
@JsonProperty
@Nullable java.lang.Double totalBlockedNanos;
@JsonProperty
@Nullable java.lang.Double totalWaitedNanos;
@JsonProperty
@Nullable java.lang.Double totalAllocatedBytes;
}
/**
* @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 ImmutableThreadInfoAggregate fromJson(Json json) {
ImmutableThreadInfoAggregate.Builder builder = ImmutableThreadInfoAggregate.builder();
if (json.totalCpuNanos != null) {
builder.totalCpuNanos(json.totalCpuNanos);
}
if (json.totalBlockedNanos != null) {
builder.totalBlockedNanos(json.totalBlockedNanos);
}
if (json.totalWaitedNanos != null) {
builder.totalWaitedNanos(json.totalWaitedNanos);
}
if (json.totalAllocatedBytes != null) {
builder.totalAllocatedBytes(json.totalAllocatedBytes);
}
return builder.build();
}
/**
* Creates immutable copy of {@link AggregateMerging.ThreadInfoAggregate}.
* 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 ThreadInfoAggregate instance
*/
static ImmutableThreadInfoAggregate copyOf(AggregateMerging.ThreadInfoAggregate instance) {
if (instance instanceof ImmutableThreadInfoAggregate) {
return (ImmutableThreadInfoAggregate) instance;
}
return ImmutableThreadInfoAggregate.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableThreadInfoAggregate ImmutableThreadInfoAggregate}.
* @return new ImmutableThreadInfoAggregate builder
*/
static ImmutableThreadInfoAggregate.Builder builder() {
return new ImmutableThreadInfoAggregate.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableThreadInfoAggregate ImmutableThreadInfoAggregate}.
* 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_TOTAL_CPU_NANOS = 0x1L;
private static final long INIT_BIT_TOTAL_BLOCKED_NANOS = 0x2L;
private static final long INIT_BIT_TOTAL_WAITED_NANOS = 0x4L;
private static final long INIT_BIT_TOTAL_ALLOCATED_BYTES = 0x8L;
private long initBits = 0xf;
private double totalCpuNanos;
private double totalBlockedNanos;
private double totalWaitedNanos;
private double totalAllocatedBytes;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link AggregateMerging.ThreadInfoAggregate} instance.
* Regular attribute values will be replaced with ones of an instance.
* Instance's absent optional values will not replace present values.
* @param instance instance to copy values from
* @return {@code this} builder for chained invocation
*/
public final Builder copyFrom(AggregateMerging.ThreadInfoAggregate instance) {
Preconditions.checkNotNull(instance);
totalCpuNanos(instance.totalCpuNanos());
totalBlockedNanos(instance.totalBlockedNanos());
totalWaitedNanos(instance.totalWaitedNanos());
totalAllocatedBytes(instance.totalAllocatedBytes());
return this;
}
/**
* Initializes value for {@link AggregateMerging.ThreadInfoAggregate#totalCpuNanos() totalCpuNanos}.
* @param totalCpuNanos value for totalCpuNanos
* @return {@code this} builder for chained invocation
*/
public final Builder totalCpuNanos(double totalCpuNanos) {
this.totalCpuNanos = totalCpuNanos;
initBits &= ~INIT_BIT_TOTAL_CPU_NANOS;
return this;
}
/**
* Initializes value for {@link AggregateMerging.ThreadInfoAggregate#totalBlockedNanos() totalBlockedNanos}.
* @param totalBlockedNanos value for totalBlockedNanos
* @return {@code this} builder for chained invocation
*/
public final Builder totalBlockedNanos(double totalBlockedNanos) {
this.totalBlockedNanos = totalBlockedNanos;
initBits &= ~INIT_BIT_TOTAL_BLOCKED_NANOS;
return this;
}
/**
* Initializes value for {@link AggregateMerging.ThreadInfoAggregate#totalWaitedNanos() totalWaitedNanos}.
* @param totalWaitedNanos value for totalWaitedNanos
* @return {@code this} builder for chained invocation
*/
public final Builder totalWaitedNanos(double totalWaitedNanos) {
this.totalWaitedNanos = totalWaitedNanos;
initBits &= ~INIT_BIT_TOTAL_WAITED_NANOS;
return this;
}
/**
* Initializes value for {@link AggregateMerging.ThreadInfoAggregate#totalAllocatedBytes() totalAllocatedBytes}.
* @param totalAllocatedBytes value for totalAllocatedBytes
* @return {@code this} builder for chained invocation
*/
public final Builder totalAllocatedBytes(double totalAllocatedBytes) {
this.totalAllocatedBytes = totalAllocatedBytes;
initBits &= ~INIT_BIT_TOTAL_ALLOCATED_BYTES;
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutableThreadInfoAggregate ImmutableThreadInfoAggregate}.
* @return immutable instance of ThreadInfoAggregate
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableThreadInfoAggregate build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableThreadInfoAggregate(totalCpuNanos, totalBlockedNanos, totalWaitedNanos, totalAllocatedBytes);
}
private boolean totalCpuNanosIsSet() {
return (initBits & INIT_BIT_TOTAL_CPU_NANOS) == 0;
}
private boolean totalBlockedNanosIsSet() {
return (initBits & INIT_BIT_TOTAL_BLOCKED_NANOS) == 0;
}
private boolean totalWaitedNanosIsSet() {
return (initBits & INIT_BIT_TOTAL_WAITED_NANOS) == 0;
}
private boolean totalAllocatedBytesIsSet() {
return (initBits & INIT_BIT_TOTAL_ALLOCATED_BYTES) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!totalCpuNanosIsSet()) attributes.add("totalCpuNanos");
if (!totalBlockedNanosIsSet()) attributes.add("totalBlockedNanos");
if (!totalWaitedNanosIsSet()) attributes.add("totalWaitedNanos");
if (!totalAllocatedBytesIsSet()) attributes.add("totalAllocatedBytes");
return "Cannot build ThreadInfoAggregate, some of required attributes are not set " + attributes;
}
}
}