org.glowroot.central.v09support.ImmutableQuery Maven / Gradle / Ivy
package org.glowroot.central.v09support;
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.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link V09Support.Query}.
*
* Use the builder to create immutable instances:
* {@code ImmutableQuery.builder()}.
*/
@Generated(from = "V09Support.Query", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
final class ImmutableQuery implements V09Support.Query {
private final String agentRollupId;
private final long from;
private final long to;
private ImmutableQuery(String agentRollupId, long from, long to) {
this.agentRollupId = agentRollupId;
this.from = from;
this.to = to;
}
/**
* @return The value of the {@code agentRollupId} attribute
*/
@JsonProperty("agentRollupId")
@Override
public String agentRollupId() {
return agentRollupId;
}
/**
* @return The value of the {@code from} attribute
*/
@JsonProperty("from")
@Override
public long from() {
return from;
}
/**
* @return The value of the {@code to} attribute
*/
@JsonProperty("to")
@Override
public long to() {
return to;
}
/**
* Copy the current immutable object by setting a value for the {@link V09Support.Query#agentRollupId() agentRollupId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for agentRollupId
* @return A modified copy of the {@code this} object
*/
public final ImmutableQuery withAgentRollupId(String value) {
String newValue = Objects.requireNonNull(value, "agentRollupId");
if (this.agentRollupId.equals(newValue)) return this;
return new ImmutableQuery(newValue, this.from, this.to);
}
/**
* Copy the current immutable object by setting a value for the {@link V09Support.Query#from() from} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for from
* @return A modified copy of the {@code this} object
*/
public final ImmutableQuery withFrom(long value) {
if (this.from == value) return this;
return new ImmutableQuery(this.agentRollupId, value, this.to);
}
/**
* Copy the current immutable object by setting a value for the {@link V09Support.Query#to() to} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for to
* @return A modified copy of the {@code this} object
*/
public final ImmutableQuery withTo(long value) {
if (this.to == value) return this;
return new ImmutableQuery(this.agentRollupId, this.from, value);
}
/**
* This instance is equal to all instances of {@code ImmutableQuery} that have 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 ImmutableQuery
&& equalTo((ImmutableQuery) another);
}
private boolean equalTo(ImmutableQuery another) {
return agentRollupId.equals(another.agentRollupId)
&& from == another.from
&& to == another.to;
}
/**
* Computes a hash code from attributes: {@code agentRollupId}, {@code from}, {@code to}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + agentRollupId.hashCode();
h += (h << 5) + Longs.hashCode(from);
h += (h << 5) + Longs.hashCode(to);
return h;
}
/**
* Prints the immutable value {@code Query} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Query")
.omitNullValues()
.add("agentRollupId", agentRollupId)
.add("from", from)
.add("to", to)
.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 = "V09Support.Query", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements V09Support.Query {
@Nullable String agentRollupId;
long from;
boolean fromIsSet;
long to;
boolean toIsSet;
@JsonProperty("agentRollupId")
public void setAgentRollupId(String agentRollupId) {
this.agentRollupId = agentRollupId;
}
@JsonProperty("from")
public void setFrom(long from) {
this.from = from;
this.fromIsSet = true;
}
@JsonProperty("to")
public void setTo(long to) {
this.to = to;
this.toIsSet = true;
}
@Override
public String agentRollupId() { throw new UnsupportedOperationException(); }
@Override
public long from() { throw new UnsupportedOperationException(); }
@Override
public long to() { 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 ImmutableQuery fromJson(Json json) {
ImmutableQuery.Builder builder = ImmutableQuery.builder();
if (json.agentRollupId != null) {
builder.agentRollupId(json.agentRollupId);
}
if (json.fromIsSet) {
builder.from(json.from);
}
if (json.toIsSet) {
builder.to(json.to);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link V09Support.Query} 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 Query instance
*/
public static ImmutableQuery copyOf(V09Support.Query instance) {
if (instance instanceof ImmutableQuery) {
return (ImmutableQuery) instance;
}
return ImmutableQuery.builder()
.copyFrom(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableQuery ImmutableQuery}.
*
* ImmutableQuery.builder()
* .agentRollupId(String) // required {@link V09Support.Query#agentRollupId() agentRollupId}
* .from(long) // required {@link V09Support.Query#from() from}
* .to(long) // required {@link V09Support.Query#to() to}
* .build();
*
* @return A new ImmutableQuery builder
*/
public static ImmutableQuery.Builder builder() {
return new ImmutableQuery.Builder();
}
/**
* Builds instances of type {@link ImmutableQuery ImmutableQuery}.
* 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 = "V09Support.Query", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_AGENT_ROLLUP_ID = 0x1L;
private static final long INIT_BIT_FROM = 0x2L;
private static final long INIT_BIT_TO = 0x4L;
private long initBits = 0x7L;
private @Nullable String agentRollupId;
private long from;
private long to;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Query} 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(V09Support.Query instance) {
Objects.requireNonNull(instance, "instance");
agentRollupId(instance.agentRollupId());
from(instance.from());
to(instance.to());
return this;
}
/**
* Initializes the value for the {@link V09Support.Query#agentRollupId() agentRollupId} attribute.
* @param agentRollupId The value for agentRollupId
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder agentRollupId(String agentRollupId) {
this.agentRollupId = Objects.requireNonNull(agentRollupId, "agentRollupId");
initBits &= ~INIT_BIT_AGENT_ROLLUP_ID;
return this;
}
/**
* Initializes the value for the {@link V09Support.Query#from() from} attribute.
* @param from The value for from
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(long from) {
this.from = from;
initBits &= ~INIT_BIT_FROM;
return this;
}
/**
* Initializes the value for the {@link V09Support.Query#to() to} attribute.
* @param to The value for to
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder to(long to) {
this.to = to;
initBits &= ~INIT_BIT_TO;
return this;
}
/**
* Builds a new {@link ImmutableQuery ImmutableQuery}.
* @return An immutable instance of Query
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableQuery build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableQuery(agentRollupId, from, to);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_AGENT_ROLLUP_ID) != 0) attributes.add("agentRollupId");
if ((initBits & INIT_BIT_FROM) != 0) attributes.add("from");
if ((initBits & INIT_BIT_TO) != 0) attributes.add("to");
return "Cannot build Query, some of required attributes are not set " + attributes;
}
}
}