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