
org.glowroot.agent.model.ImmutableGcSnapshot Maven / Gradle / Ivy
package org.glowroot.agent.model;
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.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 GcActivityComponent.GcSnapshot}.
*
* Use builder to create immutable instances:
* {@code ImmutableGcSnapshot.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "GcActivityComponent.GcSnapshot"})
@Immutable
final class ImmutableGcSnapshot implements GcActivityComponent.GcSnapshot {
private final long collectionCount;
private final long collectionTime;
private ImmutableGcSnapshot(long collectionCount, long collectionTime) {
this.collectionCount = collectionCount;
this.collectionTime = collectionTime;
}
/**
* @return value of {@code collectionCount} attribute
*/
@JsonProperty
@Override
public long collectionCount() {
return collectionCount;
}
/**
* @return value of {@code collectionTime} attribute
*/
@JsonProperty
@Override
public long collectionTime() {
return collectionTime;
}
/**
* Copy current immutable object by setting value for {@link GcActivityComponent.GcSnapshot#collectionCount() collectionCount}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for collectionCount
* @return modified copy of the {@code this} object
*/
public final ImmutableGcSnapshot withCollectionCount(long value) {
if (this.collectionCount == value) return this;
long newValue = value;
return new ImmutableGcSnapshot(newValue, this.collectionTime);
}
/**
* Copy current immutable object by setting value for {@link GcActivityComponent.GcSnapshot#collectionTime() collectionTime}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for collectionTime
* @return modified copy of the {@code this} object
*/
public final ImmutableGcSnapshot withCollectionTime(long value) {
if (this.collectionTime == value) return this;
long newValue = value;
return new ImmutableGcSnapshot(this.collectionCount, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableGcSnapshot} 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 ImmutableGcSnapshot
&& equalTo((ImmutableGcSnapshot) another);
}
private boolean equalTo(ImmutableGcSnapshot another) {
return collectionCount == another.collectionCount
&& collectionTime == another.collectionTime;
}
/**
* Computes hash code from attributes: {@code collectionCount}, {@code collectionTime}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Longs.hashCode(collectionCount);
h = h * 17 + Longs.hashCode(collectionTime);
return h;
}
/**
* Prints immutable value {@code GcSnapshot...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("GcSnapshot")
.add("collectionCount", collectionCount)
.add("collectionTime", collectionTime)
.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 collectionCount;
@JsonProperty
@Nullable Long collectionTime;
}
/**
* @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 ImmutableGcSnapshot fromJson(Json json) {
ImmutableGcSnapshot.Builder builder = ImmutableGcSnapshot.builder();
if (json.collectionCount != null) {
builder.collectionCount(json.collectionCount);
}
if (json.collectionTime != null) {
builder.collectionTime(json.collectionTime);
}
return builder.build();
}
/**
* Creates immutable copy of {@link GcActivityComponent.GcSnapshot}.
* 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 GcSnapshot instance
*/
static ImmutableGcSnapshot copyOf(GcActivityComponent.GcSnapshot instance) {
if (instance instanceof ImmutableGcSnapshot) {
return (ImmutableGcSnapshot) instance;
}
return ImmutableGcSnapshot.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.agent.model.ImmutableGcSnapshot ImmutableGcSnapshot}.
* @return new ImmutableGcSnapshot builder
*/
static ImmutableGcSnapshot.Builder builder() {
return new ImmutableGcSnapshot.Builder();
}
/**
* Builds instances of {@link org.glowroot.agent.model.ImmutableGcSnapshot ImmutableGcSnapshot}.
* 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_COLLECTION_COUNT = 0x1L;
private static final long INIT_BIT_COLLECTION_TIME = 0x2L;
private long initBits = 0x3;
private long collectionCount;
private long collectionTime;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link GcActivityComponent.GcSnapshot} 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(GcActivityComponent.GcSnapshot instance) {
Preconditions.checkNotNull(instance);
collectionCount(instance.collectionCount());
collectionTime(instance.collectionTime());
return this;
}
/**
* Initializes value for {@link GcActivityComponent.GcSnapshot#collectionCount() collectionCount}.
* @param collectionCount value for collectionCount
* @return {@code this} builder for chained invocation
*/
public final Builder collectionCount(long collectionCount) {
this.collectionCount = collectionCount;
initBits &= ~INIT_BIT_COLLECTION_COUNT;
return this;
}
/**
* Initializes value for {@link GcActivityComponent.GcSnapshot#collectionTime() collectionTime}.
* @param collectionTime value for collectionTime
* @return {@code this} builder for chained invocation
*/
public final Builder collectionTime(long collectionTime) {
this.collectionTime = collectionTime;
initBits &= ~INIT_BIT_COLLECTION_TIME;
return this;
}
/**
* Builds new {@link org.glowroot.agent.model.ImmutableGcSnapshot ImmutableGcSnapshot}.
* @return immutable instance of GcSnapshot
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableGcSnapshot build()
throws IllegalStateException {
checkRequiredAttributes(); return new ImmutableGcSnapshot(collectionCount, collectionTime);
}
private boolean collectionCountIsSet() {
return (initBits & INIT_BIT_COLLECTION_COUNT) == 0;
}
private boolean collectionTimeIsSet() {
return (initBits & INIT_BIT_COLLECTION_TIME) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!collectionCountIsSet()) attributes.add("collectionCount");
if (!collectionTimeIsSet()) attributes.add("collectionTime");
return "Cannot build GcSnapshot, some of required attributes are not set " + attributes;
}
}
}