
org.glowroot.common.live.ImmutableTracePoint 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.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Booleans;
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 LiveTraceRepository.TracePoint}.
*
* Use builder to create immutable instances:
* {@code ImmutableTracePoint.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "LiveTraceRepository.TracePoint"})
@Immutable
public final class ImmutableTracePoint implements LiveTraceRepository.TracePoint {
private final String serverId;
private final String traceId;
private final long captureTime;
private final long durationNanos;
private final boolean error;
private ImmutableTracePoint(
String serverId,
String traceId,
long captureTime,
long durationNanos,
boolean error) {
this.serverId = serverId;
this.traceId = traceId;
this.captureTime = captureTime;
this.durationNanos = durationNanos;
this.error = error;
}
/**
* @return value of {@code serverId} attribute
*/
@JsonProperty
@Override
public String serverId() {
return serverId;
}
/**
* @return value of {@code traceId} attribute
*/
@JsonProperty
@Override
public String traceId() {
return traceId;
}
/**
* @return value of {@code captureTime} attribute
*/
@JsonProperty
@Override
public long captureTime() {
return captureTime;
}
/**
* @return value of {@code durationNanos} attribute
*/
@JsonProperty
@Override
public long durationNanos() {
return durationNanos;
}
/**
* @return value of {@code error} attribute
*/
@JsonProperty
@Override
public boolean error() {
return error;
}
/**
* Copy current immutable object by setting value for {@link LiveTraceRepository.TracePoint#serverId() serverId}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for serverId
* @return modified copy of the {@code this} object
*/
public final ImmutableTracePoint withServerId(String value) {
if (this.serverId == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableTracePoint(newValue, this.traceId, this.captureTime, this.durationNanos, this.error);
}
/**
* Copy current immutable object by setting value for {@link LiveTraceRepository.TracePoint#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
* @return modified copy of the {@code this} object
*/
public final ImmutableTracePoint withTraceId(String value) {
if (this.traceId == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableTracePoint(this.serverId, newValue, this.captureTime, this.durationNanos, this.error);
}
/**
* Copy current immutable object by setting value for {@link LiveTraceRepository.TracePoint#captureTime() captureTime}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for captureTime
* @return modified copy of the {@code this} object
*/
public final ImmutableTracePoint withCaptureTime(long value) {
if (this.captureTime == value) return this;
long newValue = value;
return new ImmutableTracePoint(this.serverId, this.traceId, newValue, this.durationNanos, this.error);
}
/**
* Copy current immutable object by setting value for {@link LiveTraceRepository.TracePoint#durationNanos() durationNanos}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for durationNanos
* @return modified copy of the {@code this} object
*/
public final ImmutableTracePoint withDurationNanos(long value) {
if (this.durationNanos == value) return this;
long newValue = value;
return new ImmutableTracePoint(this.serverId, this.traceId, this.captureTime, newValue, this.error);
}
/**
* Copy current immutable object by setting value for {@link LiveTraceRepository.TracePoint#error() error}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for error
* @return modified copy of the {@code this} object
*/
public final ImmutableTracePoint withError(boolean value) {
if (this.error == value) return this;
boolean newValue = value;
return new ImmutableTracePoint(this.serverId, this.traceId, this.captureTime, this.durationNanos, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableTracePoint} 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 ImmutableTracePoint
&& equalTo((ImmutableTracePoint) another);
}
private boolean equalTo(ImmutableTracePoint another) {
return serverId.equals(another.serverId)
&& traceId.equals(another.traceId)
&& captureTime == another.captureTime
&& durationNanos == another.durationNanos
&& error == another.error;
}
/**
* Computes hash code from attributes: {@code serverId}, {@code traceId}, {@code captureTime}, {@code durationNanos}, {@code error}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + serverId.hashCode();
h = h * 17 + traceId.hashCode();
h = h * 17 + Longs.hashCode(captureTime);
h = h * 17 + Longs.hashCode(durationNanos);
h = h * 17 + Booleans.hashCode(error);
return h;
}
/**
* Prints immutable value {@code TracePoint...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("TracePoint")
.add("serverId", serverId)
.add("traceId", traceId)
.add("captureTime", captureTime)
.add("durationNanos", durationNanos)
.add("error", error)
.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 serverId;
@JsonProperty
@Nullable String traceId;
@JsonProperty
@Nullable Long captureTime;
@JsonProperty
@Nullable Long durationNanos;
@JsonProperty
@Nullable Boolean error;
}
/**
* @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 ImmutableTracePoint fromJson(Json json) {
ImmutableTracePoint.Builder builder = ImmutableTracePoint.builder();
if (json.serverId != null) {
builder.serverId(json.serverId);
}
if (json.traceId != null) {
builder.traceId(json.traceId);
}
if (json.captureTime != null) {
builder.captureTime(json.captureTime);
}
if (json.durationNanos != null) {
builder.durationNanos(json.durationNanos);
}
if (json.error != null) {
builder.error(json.error);
}
return builder.build();
}
/**
* Creates immutable copy of {@link LiveTraceRepository.TracePoint}.
* 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 TracePoint instance
*/
public static ImmutableTracePoint copyOf(LiveTraceRepository.TracePoint instance) {
if (instance instanceof ImmutableTracePoint) {
return (ImmutableTracePoint) instance;
}
return ImmutableTracePoint.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.common.live.ImmutableTracePoint ImmutableTracePoint}.
* @return new ImmutableTracePoint builder
*/
public static ImmutableTracePoint.Builder builder() {
return new ImmutableTracePoint.Builder();
}
/**
* Builds instances of {@link org.glowroot.common.live.ImmutableTracePoint ImmutableTracePoint}.
* 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_SERVER_ID = 0x1L;
private static final long INIT_BIT_TRACE_ID = 0x2L;
private static final long INIT_BIT_CAPTURE_TIME = 0x4L;
private static final long INIT_BIT_DURATION_NANOS = 0x8L;
private static final long INIT_BIT_ERROR = 0x10L;
private long initBits = 0x1f;
private @Nullable String serverId;
private @Nullable String traceId;
private long captureTime;
private long durationNanos;
private boolean error;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link LiveTraceRepository.TracePoint} 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(LiveTraceRepository.TracePoint instance) {
Preconditions.checkNotNull(instance);
serverId(instance.serverId());
traceId(instance.traceId());
captureTime(instance.captureTime());
durationNanos(instance.durationNanos());
error(instance.error());
return this;
}
/**
* Initializes value for {@link LiveTraceRepository.TracePoint#serverId() serverId}.
* @param serverId value for serverId
* @return {@code this} builder for chained invocation
*/
public final Builder serverId(String serverId) {
this.serverId = Preconditions.checkNotNull(serverId);
initBits &= ~INIT_BIT_SERVER_ID;
return this;
}
/**
* Initializes value for {@link LiveTraceRepository.TracePoint#traceId() traceId}.
* @param traceId value for traceId
* @return {@code this} builder for chained invocation
*/
public final Builder traceId(String traceId) {
this.traceId = Preconditions.checkNotNull(traceId);
initBits &= ~INIT_BIT_TRACE_ID;
return this;
}
/**
* Initializes value for {@link LiveTraceRepository.TracePoint#captureTime() captureTime}.
* @param captureTime value for captureTime
* @return {@code this} builder for chained invocation
*/
public final Builder captureTime(long captureTime) {
this.captureTime = captureTime;
initBits &= ~INIT_BIT_CAPTURE_TIME;
return this;
}
/**
* Initializes value for {@link LiveTraceRepository.TracePoint#durationNanos() durationNanos}.
* @param durationNanos value for durationNanos
* @return {@code this} builder for chained invocation
*/
public final Builder durationNanos(long durationNanos) {
this.durationNanos = durationNanos;
initBits &= ~INIT_BIT_DURATION_NANOS;
return this;
}
/**
* Initializes value for {@link LiveTraceRepository.TracePoint#error() error}.
* @param error value for error
* @return {@code this} builder for chained invocation
*/
public final Builder error(boolean error) {
this.error = error;
initBits &= ~INIT_BIT_ERROR;
return this;
}
/**
* Builds new {@link org.glowroot.common.live.ImmutableTracePoint ImmutableTracePoint}.
* @return immutable instance of TracePoint
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableTracePoint build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableTracePoint(serverId, traceId, captureTime, durationNanos, error);
}
private boolean serverIdIsSet() {
return (initBits & INIT_BIT_SERVER_ID) == 0;
}
private boolean traceIdIsSet() {
return (initBits & INIT_BIT_TRACE_ID) == 0;
}
private boolean captureTimeIsSet() {
return (initBits & INIT_BIT_CAPTURE_TIME) == 0;
}
private boolean durationNanosIsSet() {
return (initBits & INIT_BIT_DURATION_NANOS) == 0;
}
private boolean errorIsSet() {
return (initBits & INIT_BIT_ERROR) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!serverIdIsSet()) attributes.add("serverId");
if (!traceIdIsSet()) attributes.add("traceId");
if (!captureTimeIsSet()) attributes.add("captureTime");
if (!durationNanosIsSet()) attributes.add("durationNanos");
if (!errorIsSet()) attributes.add("error");
return "Cannot build TracePoint, some of required attributes are not set " + attributes;
}
}
}