org.glowroot.central.ImmutableSyntheticRunResult Maven / Gradle / Ivy
package org.glowroot.central;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Longs;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link SyntheticMonitorService.SyntheticRunResult}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSyntheticRunResult.builder()}.
*/
@Generated(from = "SyntheticMonitorService.SyntheticRunResult", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
final class ImmutableSyntheticRunResult
implements SyntheticMonitorService.SyntheticRunResult {
private final long captureTime;
private final long durationNanos;
private final java.lang.@Nullable Throwable throwable;
private ImmutableSyntheticRunResult(
long captureTime,
long durationNanos,
java.lang.@Nullable Throwable throwable) {
this.captureTime = captureTime;
this.durationNanos = durationNanos;
this.throwable = throwable;
}
/**
* @return The value of the {@code captureTime} attribute
*/
@JsonProperty("captureTime")
@Override
public long captureTime() {
return captureTime;
}
/**
* @return The value of the {@code durationNanos} attribute
*/
@JsonProperty("durationNanos")
@Override
public long durationNanos() {
return durationNanos;
}
/**
* @return The value of the {@code throwable} attribute
*/
@JsonProperty("throwable")
@Override
public java.lang.@Nullable Throwable throwable() {
return throwable;
}
/**
* Copy the current immutable object by setting a value for the {@link SyntheticMonitorService.SyntheticRunResult#captureTime() captureTime} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for captureTime
* @return A modified copy of the {@code this} object
*/
public final ImmutableSyntheticRunResult withCaptureTime(long value) {
if (this.captureTime == value) return this;
return new ImmutableSyntheticRunResult(value, this.durationNanos, this.throwable);
}
/**
* Copy the current immutable object by setting a value for the {@link SyntheticMonitorService.SyntheticRunResult#durationNanos() durationNanos} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for durationNanos
* @return A modified copy of the {@code this} object
*/
public final ImmutableSyntheticRunResult withDurationNanos(long value) {
if (this.durationNanos == value) return this;
return new ImmutableSyntheticRunResult(this.captureTime, value, this.throwable);
}
/**
* Copy the current immutable object by setting a value for the {@link SyntheticMonitorService.SyntheticRunResult#throwable() throwable} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for throwable (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableSyntheticRunResult withThrowable(java.lang.@Nullable Throwable value) {
if (this.throwable == value) return this;
return new ImmutableSyntheticRunResult(this.captureTime, this.durationNanos, value);
}
/**
* This instance is equal to all instances of {@code ImmutableSyntheticRunResult} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@javax.annotation.Nullable Object another) {
if (this == another) return true;
return another instanceof ImmutableSyntheticRunResult
&& equalTo((ImmutableSyntheticRunResult) another);
}
private boolean equalTo(ImmutableSyntheticRunResult another) {
return captureTime == another.captureTime
&& durationNanos == another.durationNanos
&& Objects.equals(throwable, another.throwable);
}
/**
* Computes a hash code from attributes: {@code captureTime}, {@code durationNanos}, {@code throwable}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Longs.hashCode(captureTime);
h += (h << 5) + Longs.hashCode(durationNanos);
h += (h << 5) + Objects.hashCode(throwable);
return h;
}
/**
* Prints the immutable value {@code SyntheticRunResult} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SyntheticRunResult")
.omitNullValues()
.add("captureTime", captureTime)
.add("durationNanos", durationNanos)
.add("throwable", throwable)
.toString();
}
/**
* Utility type used to correctly read immutable object from JSON representation.
* @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure
*/
@Generated(from = "SyntheticMonitorService.SyntheticRunResult", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements SyntheticMonitorService.SyntheticRunResult {
long captureTime;
boolean captureTimeIsSet;
long durationNanos;
boolean durationNanosIsSet;
@javax.annotation.Nullable java.lang.@Nullable Throwable throwable;
@JsonProperty("captureTime")
public void setCaptureTime(long captureTime) {
this.captureTime = captureTime;
this.captureTimeIsSet = true;
}
@JsonProperty("durationNanos")
public void setDurationNanos(long durationNanos) {
this.durationNanos = durationNanos;
this.durationNanosIsSet = true;
}
@JsonProperty("throwable")
public void setThrowable(java.lang.@Nullable Throwable throwable) {
this.throwable = throwable;
}
@Override
public long captureTime() { throw new UnsupportedOperationException(); }
@Override
public long durationNanos() { throw new UnsupportedOperationException(); }
@Override
public java.lang.@Nullable Throwable throwable() { throw new UnsupportedOperationException(); }
}
/**
* @param json A JSON-bindable data structure
* @return An immutable value type
* @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure
*/
@Deprecated
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
static ImmutableSyntheticRunResult fromJson(Json json) {
ImmutableSyntheticRunResult.Builder builder = ImmutableSyntheticRunResult.builder();
if (json.captureTimeIsSet) {
builder.captureTime(json.captureTime);
}
if (json.durationNanosIsSet) {
builder.durationNanos(json.durationNanos);
}
if (json.throwable != null) {
builder.throwable(json.throwable);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link SyntheticMonitorService.SyntheticRunResult} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance The instance to copy
* @return A copied immutable SyntheticRunResult instance
*/
public static ImmutableSyntheticRunResult copyOf(SyntheticMonitorService.SyntheticRunResult instance) {
if (instance instanceof ImmutableSyntheticRunResult) {
return (ImmutableSyntheticRunResult) instance;
}
return ImmutableSyntheticRunResult.builder()
.copyFrom(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableSyntheticRunResult ImmutableSyntheticRunResult}.
*
* ImmutableSyntheticRunResult.builder()
* .captureTime(long) // required {@link SyntheticMonitorService.SyntheticRunResult#captureTime() captureTime}
* .durationNanos(long) // required {@link SyntheticMonitorService.SyntheticRunResult#durationNanos() durationNanos}
* .throwable(@org.checkerframework.checker.nullness.qual.Nullable Throwable | null) // nullable {@link SyntheticMonitorService.SyntheticRunResult#throwable() throwable}
* .build();
*
* @return A new ImmutableSyntheticRunResult builder
*/
public static ImmutableSyntheticRunResult.Builder builder() {
return new ImmutableSyntheticRunResult.Builder();
}
/**
* Builds instances of type {@link ImmutableSyntheticRunResult ImmutableSyntheticRunResult}.
* Initialize attributes and then invoke the {@link #build()} method to create an
* immutable instance.
* {@code Builder} is not thread-safe and generally should not be stored in a field or collection,
* but instead used immediately to create instances.
*/
@Generated(from = "SyntheticMonitorService.SyntheticRunResult", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_CAPTURE_TIME = 0x1L;
private static final long INIT_BIT_DURATION_NANOS = 0x2L;
private long initBits = 0x3L;
private long captureTime;
private long durationNanos;
private @javax.annotation.Nullable java.lang.@Nullable Throwable throwable;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code SyntheticRunResult} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder copyFrom(SyntheticMonitorService.SyntheticRunResult instance) {
Objects.requireNonNull(instance, "instance");
captureTime(instance.captureTime());
durationNanos(instance.durationNanos());
java.lang.@Nullable Throwable throwableValue = instance.throwable();
if (throwableValue != null) {
throwable(throwableValue);
}
return this;
}
/**
* Initializes the value for the {@link SyntheticMonitorService.SyntheticRunResult#captureTime() captureTime} attribute.
* @param captureTime The value for captureTime
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder captureTime(long captureTime) {
this.captureTime = captureTime;
initBits &= ~INIT_BIT_CAPTURE_TIME;
return this;
}
/**
* Initializes the value for the {@link SyntheticMonitorService.SyntheticRunResult#durationNanos() durationNanos} attribute.
* @param durationNanos The value for durationNanos
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder durationNanos(long durationNanos) {
this.durationNanos = durationNanos;
initBits &= ~INIT_BIT_DURATION_NANOS;
return this;
}
/**
* Initializes the value for the {@link SyntheticMonitorService.SyntheticRunResult#throwable() throwable} attribute.
* @param throwable The value for throwable (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder throwable(java.lang.@Nullable Throwable throwable) {
this.throwable = throwable;
return this;
}
/**
* Builds a new {@link ImmutableSyntheticRunResult ImmutableSyntheticRunResult}.
* @return An immutable instance of SyntheticRunResult
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSyntheticRunResult build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableSyntheticRunResult(captureTime, durationNanos, throwable);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_CAPTURE_TIME) != 0) attributes.add("captureTime");
if ((initBits & INIT_BIT_DURATION_NANOS) != 0) attributes.add("durationNanos");
return "Cannot build SyntheticRunResult, some of required attributes are not set " + attributes;
}
}
}