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