
org.glowroot.common.live.ImmutableOneThread Maven / Gradle / Ivy
package org.glowroot.common.live;
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.Objects;
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 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 LiveJvmService.OneThread}.
*
* Use builder to create immutable instances:
* {@code ImmutableOneThread.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "LiveJvmService.OneThread"})
@Immutable
public final class ImmutableOneThread implements LiveJvmService.OneThread {
private final String name;
private final String state;
private final @Nullable String lockName;
private final ImmutableList stackTraceElements;
private final @Nullable String transactionType;
private final @Nullable String transactionName;
private final @Nullable Long transactionTotalNanos;
private final @Nullable String traceId;
private ImmutableOneThread(
String name,
String state,
@Nullable String lockName,
ImmutableList stackTraceElements,
@Nullable String transactionType,
@Nullable String transactionName,
@Nullable Long transactionTotalNanos,
@Nullable String traceId) {
this.name = name;
this.state = state;
this.lockName = lockName;
this.stackTraceElements = stackTraceElements;
this.transactionType = transactionType;
this.transactionName = transactionName;
this.transactionTotalNanos = transactionTotalNanos;
this.traceId = traceId;
}
/**
* @return value of {@code name} attribute
*/
@JsonProperty
@Override
public String name() {
return name;
}
/**
* @return value of {@code state} attribute
*/
@JsonProperty
@Override
public String state() {
return state;
}
/**
* @return value of {@code lockName} attribute
*/
@JsonProperty
@Override
public @Nullable String lockName() {
return lockName;
}
/**
* @return value of {@code stackTraceElements} attribute
*/
@JsonProperty
@Override
public ImmutableList stackTraceElements() {
return stackTraceElements;
}
/**
* @return value of {@code transactionType} attribute
*/
@JsonProperty
@Override
public @Nullable String transactionType() {
return transactionType;
}
/**
* @return value of {@code transactionName} attribute
*/
@JsonProperty
@Override
public @Nullable String transactionName() {
return transactionName;
}
/**
* @return value of {@code transactionTotalNanos} attribute
*/
@JsonProperty
@Override
public @Nullable Long transactionTotalNanos() {
return transactionTotalNanos;
}
/**
* @return value of {@code traceId} attribute
*/
@JsonProperty
@Override
public @Nullable String traceId() {
return traceId;
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.OneThread#name() name}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for name
* @return modified copy of the {@code this} object
*/
public final ImmutableOneThread withName(String value) {
if (this.name == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableOneThread(
newValue,
this.state,
this.lockName,
this.stackTraceElements,
this.transactionType,
this.transactionName,
this.transactionTotalNanos,
this.traceId);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.OneThread#state() state}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for state
* @return modified copy of the {@code this} object
*/
public final ImmutableOneThread withState(String value) {
if (this.state == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableOneThread(
this.name,
newValue,
this.lockName,
this.stackTraceElements,
this.transactionType,
this.transactionName,
this.transactionTotalNanos,
this.traceId);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.OneThread#lockName() lockName}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for lockName, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableOneThread withLockName(@Nullable String value) {
if (this.lockName == value) return this;
@Nullable String newValue = value;
return new ImmutableOneThread(
this.name,
this.state,
newValue,
this.stackTraceElements,
this.transactionType,
this.transactionName,
this.transactionTotalNanos,
this.traceId);
}
/**
* Copy current immutable object with elements that replace content of {@link LiveJvmService.OneThread#stackTraceElements() stackTraceElements}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableOneThread withStackTraceElements(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableOneThread(
this.name,
this.state,
this.lockName,
newValue,
this.transactionType,
this.transactionName,
this.transactionTotalNanos,
this.traceId);
}
/**
* Copy current immutable object with elements that replace content of {@link LiveJvmService.OneThread#stackTraceElements() stackTraceElements}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of stackTraceElements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableOneThread withStackTraceElements(Iterable elements) {
if (this.stackTraceElements == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableOneThread(
this.name,
this.state,
this.lockName,
newValue,
this.transactionType,
this.transactionName,
this.transactionTotalNanos,
this.traceId);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.OneThread#transactionType() transactionType}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for transactionType, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableOneThread withTransactionType(@Nullable String value) {
if (this.transactionType == value) return this;
@Nullable String newValue = value;
return new ImmutableOneThread(
this.name,
this.state,
this.lockName,
this.stackTraceElements,
newValue,
this.transactionName,
this.transactionTotalNanos,
this.traceId);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.OneThread#transactionName() transactionName}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for transactionName, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableOneThread withTransactionName(@Nullable String value) {
if (this.transactionName == value) return this;
@Nullable String newValue = value;
return new ImmutableOneThread(
this.name,
this.state,
this.lockName,
this.stackTraceElements,
this.transactionType,
newValue,
this.transactionTotalNanos,
this.traceId);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.OneThread#transactionTotalNanos() transactionTotalNanos}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for transactionTotalNanos, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableOneThread withTransactionTotalNanos(@Nullable Long value) {
if (this.transactionTotalNanos == value) return this;
@Nullable Long newValue = value;
return new ImmutableOneThread(
this.name,
this.state,
this.lockName,
this.stackTraceElements,
this.transactionType,
this.transactionName,
newValue,
this.traceId);
}
/**
* Copy current immutable object by setting value for {@link LiveJvmService.OneThread#traceId() traceId}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for traceId, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableOneThread withTraceId(@Nullable String value) {
if (this.traceId == value) return this;
@Nullable String newValue = value;
return new ImmutableOneThread(
this.name,
this.state,
this.lockName,
this.stackTraceElements,
this.transactionType,
this.transactionName,
this.transactionTotalNanos,
newValue);
}
/**
* This instance is equal to instances of {@code ImmutableOneThread} 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 ImmutableOneThread
&& equalTo((ImmutableOneThread) another);
}
private boolean equalTo(ImmutableOneThread another) {
return name.equals(another.name)
&& state.equals(another.state)
&& Objects.equal(lockName, another.lockName)
&& stackTraceElements.equals(another.stackTraceElements)
&& Objects.equal(transactionType, another.transactionType)
&& Objects.equal(transactionName, another.transactionName)
&& Objects.equal(transactionTotalNanos, another.transactionTotalNanos)
&& Objects.equal(traceId, another.traceId);
}
/**
* Computes hash code from attributes: {@code name}, {@code state}, {@code lockName}, {@code stackTraceElements}, {@code transactionType}, {@code transactionName}, {@code transactionTotalNanos}, {@code traceId}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + name.hashCode();
h = h * 17 + state.hashCode();
h = h * 17 + Objects.hashCode(lockName);
h = h * 17 + stackTraceElements.hashCode();
h = h * 17 + Objects.hashCode(transactionType);
h = h * 17 + Objects.hashCode(transactionName);
h = h * 17 + Objects.hashCode(transactionTotalNanos);
h = h * 17 + Objects.hashCode(traceId);
return h;
}
/**
* Prints immutable value {@code OneThread...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("OneThread")
.add("name", name)
.add("state", state)
.add("lockName", lockName)
.add("stackTraceElements", stackTraceElements)
.add("transactionType", transactionType)
.add("transactionName", transactionName)
.add("transactionTotalNanos", transactionTotalNanos)
.add("traceId", traceId)
.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 String name;
@JsonProperty
@Nullable String state;
@JsonProperty
@Nullable String lockName;
@JsonProperty
@Nullable List stackTraceElements;
@JsonProperty
@Nullable String transactionType;
@JsonProperty
@Nullable String transactionName;
@JsonProperty
@Nullable Long transactionTotalNanos;
@JsonProperty
@Nullable String traceId;
}
/**
* @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 ImmutableOneThread fromJson(Json json) {
ImmutableOneThread.Builder builder = ImmutableOneThread.builder();
if (json.name != null) {
builder.name(json.name);
}
if (json.state != null) {
builder.state(json.state);
}
if (json.lockName != null) {
builder.lockName(json.lockName);
}
if (json.stackTraceElements != null) {
builder.addAllStackTraceElements(json.stackTraceElements);
}
if (json.transactionType != null) {
builder.transactionType(json.transactionType);
}
if (json.transactionName != null) {
builder.transactionName(json.transactionName);
}
if (json.transactionTotalNanos != null) {
builder.transactionTotalNanos(json.transactionTotalNanos);
}
if (json.traceId != null) {
builder.traceId(json.traceId);
}
return builder.build();
}
/**
* Creates immutable copy of {@link LiveJvmService.OneThread}.
* 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 OneThread instance
*/
public static ImmutableOneThread copyOf(LiveJvmService.OneThread instance) {
if (instance instanceof ImmutableOneThread) {
return (ImmutableOneThread) instance;
}
return ImmutableOneThread.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.common.live.ImmutableOneThread ImmutableOneThread}.
* @return new ImmutableOneThread builder
*/
public static ImmutableOneThread.Builder builder() {
return new ImmutableOneThread.Builder();
}
/**
* Builds instances of {@link org.glowroot.common.live.ImmutableOneThread ImmutableOneThread}.
* 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
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private static final long INIT_BIT_STATE = 0x2L;
private long initBits = 0x3;
private @Nullable String name;
private @Nullable String state;
private @Nullable String lockName;
private ImmutableList.Builder stackTraceElementsBuilder = ImmutableList.builder();
private @Nullable String transactionType;
private @Nullable String transactionName;
private @Nullable Long transactionTotalNanos;
private @Nullable String traceId;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link LiveJvmService.OneThread} 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(LiveJvmService.OneThread instance) {
Preconditions.checkNotNull(instance);
name(instance.name());
state(instance.state());
@Nullable String lockNameValue = instance.lockName();
if (lockNameValue != null) {
lockName(lockNameValue);
}
addAllStackTraceElements(instance.stackTraceElements());
@Nullable String transactionTypeValue = instance.transactionType();
if (transactionTypeValue != null) {
transactionType(transactionTypeValue);
}
@Nullable String transactionNameValue = instance.transactionName();
if (transactionNameValue != null) {
transactionName(transactionNameValue);
}
@Nullable Long transactionTotalNanosValue = instance.transactionTotalNanos();
if (transactionTotalNanosValue != null) {
transactionTotalNanos(transactionTotalNanosValue);
}
@Nullable String traceIdValue = instance.traceId();
if (traceIdValue != null) {
traceId(traceIdValue);
}
return this;
}
/**
* Initializes value for {@link LiveJvmService.OneThread#name() name}.
* @param name value for name
* @return {@code this} builder for chained invocation
*/
public final Builder name(String name) {
this.name = Preconditions.checkNotNull(name);
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes value for {@link LiveJvmService.OneThread#state() state}.
* @param state value for state
* @return {@code this} builder for chained invocation
*/
public final Builder state(String state) {
this.state = Preconditions.checkNotNull(state);
initBits &= ~INIT_BIT_STATE;
return this;
}
/**
* Initializes value for {@link LiveJvmService.OneThread#lockName() lockName}.
* @param lockName value for lockName, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder lockName(@Nullable String lockName) {
this.lockName = lockName;
return this;
}
/**
* Adds one element to {@link LiveJvmService.OneThread#stackTraceElements() stackTraceElements} list.
* @param element stackTraceElements element
* @return {@code this} builder for chained invocation
*/
public final Builder addStackTraceElements(String element) {
stackTraceElementsBuilder.add(element);
return this;
}
/**
* Adds elements to {@link LiveJvmService.OneThread#stackTraceElements() stackTraceElements} list.
* @param elements array of stackTraceElements elements
* @return {@code this} builder for chained invocation
*/
public final Builder addStackTraceElements(String... elements) {
stackTraceElementsBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link LiveJvmService.OneThread#stackTraceElements() stackTraceElements} list.
* @param elements iterable of stackTraceElements elements
* @return {@code this} builder for chained invocation
*/
public final Builder stackTraceElements(Iterable elements) {
stackTraceElementsBuilder = ImmutableList.builder();
return addAllStackTraceElements(elements);
}
/**
* Adds elements to {@link LiveJvmService.OneThread#stackTraceElements() stackTraceElements} list.
* @param elements iterable of stackTraceElements elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllStackTraceElements(Iterable elements) {
stackTraceElementsBuilder.addAll(elements);
return this;
}
/**
* Initializes value for {@link LiveJvmService.OneThread#transactionType() transactionType}.
* @param transactionType value for transactionType, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder transactionType(@Nullable String transactionType) {
this.transactionType = transactionType;
return this;
}
/**
* Initializes value for {@link LiveJvmService.OneThread#transactionName() transactionName}.
* @param transactionName value for transactionName, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder transactionName(@Nullable String transactionName) {
this.transactionName = transactionName;
return this;
}
/**
* Initializes value for {@link LiveJvmService.OneThread#transactionTotalNanos() transactionTotalNanos}.
* @param transactionTotalNanos value for transactionTotalNanos, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder transactionTotalNanos(@Nullable Long transactionTotalNanos) {
this.transactionTotalNanos = transactionTotalNanos;
return this;
}
/**
* Initializes value for {@link LiveJvmService.OneThread#traceId() traceId}.
* @param traceId value for traceId, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder traceId(@Nullable String traceId) {
this.traceId = traceId;
return this;
}
/**
* Builds new {@link org.glowroot.common.live.ImmutableOneThread ImmutableOneThread}.
* @return immutable instance of OneThread
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableOneThread build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableOneThread(
name,
state,
lockName,
stackTraceElementsBuilder.build(),
transactionType,
transactionName,
transactionTotalNanos,
traceId);
}
private boolean nameIsSet() {
return (initBits & INIT_BIT_NAME) == 0;
}
private boolean stateIsSet() {
return (initBits & INIT_BIT_STATE) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!nameIsSet()) attributes.add("name");
if (!stateIsSet()) attributes.add("state");
return "Cannot build OneThread, some of required attributes are not set " + attributes;
}
}
}