
org.glowroot.storage.repo.ImmutableTransactionSummaryQuery 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 AggregateRepository.TransactionSummaryQuery}.
*
* Use builder to create immutable instances:
* {@code ImmutableTransactionSummaryQuery.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "AggregateRepository.TransactionSummaryQuery"})
@Immutable
public final class ImmutableTransactionSummaryQuery
implements AggregateRepository.TransactionSummaryQuery {
private final String serverRollup;
private final String transactionType;
private final long from;
private final long to;
private final AggregateRepository.TransactionSummarySortOrder sortOrder;
private final int limit;
private ImmutableTransactionSummaryQuery(
String serverRollup,
String transactionType,
long from,
long to,
AggregateRepository.TransactionSummarySortOrder sortOrder,
int limit) {
this.serverRollup = serverRollup;
this.transactionType = transactionType;
this.from = from;
this.to = to;
this.sortOrder = sortOrder;
this.limit = limit;
}
/**
* @return value of {@code serverRollup} attribute
*/
@JsonProperty
@Override
public String serverRollup() {
return serverRollup;
}
/**
* @return value of {@code transactionType} attribute
*/
@JsonProperty
@Override
public String transactionType() {
return transactionType;
}
/**
* @return value of {@code from} attribute
*/
@JsonProperty
@Override
public long from() {
return from;
}
/**
* @return value of {@code to} attribute
*/
@JsonProperty
@Override
public long to() {
return to;
}
/**
* @return value of {@code sortOrder} attribute
*/
@JsonProperty
@Override
public AggregateRepository.TransactionSummarySortOrder sortOrder() {
return sortOrder;
}
/**
* @return value of {@code limit} attribute
*/
@JsonProperty
@Override
public int limit() {
return limit;
}
/**
* Copy current immutable object by setting value for {@link AggregateRepository.TransactionSummaryQuery#serverRollup() serverRollup}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for serverRollup
* @return modified copy of the {@code this} object
*/
public final ImmutableTransactionSummaryQuery withServerRollup(String value) {
if (this.serverRollup == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableTransactionSummaryQuery(newValue, this.transactionType, this.from, this.to, this.sortOrder, this.limit);
}
/**
* Copy current immutable object by setting value for {@link AggregateRepository.TransactionSummaryQuery#transactionType() transactionType}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for transactionType
* @return modified copy of the {@code this} object
*/
public final ImmutableTransactionSummaryQuery withTransactionType(String value) {
if (this.transactionType == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableTransactionSummaryQuery(this.serverRollup, newValue, this.from, this.to, this.sortOrder, this.limit);
}
/**
* Copy current immutable object by setting value for {@link AggregateRepository.TransactionSummaryQuery#from() from}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for from
* @return modified copy of the {@code this} object
*/
public final ImmutableTransactionSummaryQuery withFrom(long value) {
if (this.from == value) return this;
long newValue = value;
return new ImmutableTransactionSummaryQuery(this.serverRollup, this.transactionType, newValue, this.to, this.sortOrder, this.limit);
}
/**
* Copy current immutable object by setting value for {@link AggregateRepository.TransactionSummaryQuery#to() to}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for to
* @return modified copy of the {@code this} object
*/
public final ImmutableTransactionSummaryQuery withTo(long value) {
if (this.to == value) return this;
long newValue = value;
return new ImmutableTransactionSummaryQuery(this.serverRollup, this.transactionType, this.from, newValue, this.sortOrder, this.limit);
}
/**
* Copy current immutable object by setting value for {@link AggregateRepository.TransactionSummaryQuery#sortOrder() sortOrder}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for sortOrder
* @return modified copy of the {@code this} object
*/
public final ImmutableTransactionSummaryQuery withSortOrder(AggregateRepository.TransactionSummarySortOrder value) {
if (this.sortOrder == value) return this;
AggregateRepository.TransactionSummarySortOrder newValue = Preconditions.checkNotNull(value);
return new ImmutableTransactionSummaryQuery(this.serverRollup, this.transactionType, this.from, this.to, newValue, this.limit);
}
/**
* Copy current immutable object by setting value for {@link AggregateRepository.TransactionSummaryQuery#limit() limit}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for limit
* @return modified copy of the {@code this} object
*/
public final ImmutableTransactionSummaryQuery withLimit(int value) {
if (this.limit == value) return this;
int newValue = value;
return new ImmutableTransactionSummaryQuery(this.serverRollup, this.transactionType, this.from, this.to, this.sortOrder, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableTransactionSummaryQuery} 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 ImmutableTransactionSummaryQuery
&& equalTo((ImmutableTransactionSummaryQuery) another);
}
private boolean equalTo(ImmutableTransactionSummaryQuery another) {
return serverRollup.equals(another.serverRollup)
&& transactionType.equals(another.transactionType)
&& from == another.from
&& to == another.to
&& sortOrder.equals(another.sortOrder)
&& limit == another.limit;
}
/**
* Computes hash code from attributes: {@code serverRollup}, {@code transactionType}, {@code from}, {@code to}, {@code sortOrder}, {@code limit}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + serverRollup.hashCode();
h = h * 17 + transactionType.hashCode();
h = h * 17 + Longs.hashCode(from);
h = h * 17 + Longs.hashCode(to);
h = h * 17 + sortOrder.hashCode();
h = h * 17 + limit;
return h;
}
/**
* Prints immutable value {@code TransactionSummaryQuery...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("TransactionSummaryQuery")
.add("serverRollup", serverRollup)
.add("transactionType", transactionType)
.add("from", from)
.add("to", to)
.add("sortOrder", sortOrder)
.add("limit", limit)
.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 serverRollup;
@JsonProperty
@Nullable String transactionType;
@JsonProperty
@Nullable Long from;
@JsonProperty
@Nullable Long to;
@JsonProperty
@Nullable AggregateRepository.TransactionSummarySortOrder sortOrder;
@JsonProperty
@Nullable Integer limit;
}
/**
* @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 ImmutableTransactionSummaryQuery fromJson(Json json) {
ImmutableTransactionSummaryQuery.Builder builder = ImmutableTransactionSummaryQuery.builder();
if (json.serverRollup != null) {
builder.serverRollup(json.serverRollup);
}
if (json.transactionType != null) {
builder.transactionType(json.transactionType);
}
if (json.from != null) {
builder.from(json.from);
}
if (json.to != null) {
builder.to(json.to);
}
if (json.sortOrder != null) {
builder.sortOrder(json.sortOrder);
}
if (json.limit != null) {
builder.limit(json.limit);
}
return builder.build();
}
/**
* Creates immutable copy of {@link AggregateRepository.TransactionSummaryQuery}.
* 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 TransactionSummaryQuery instance
*/
public static ImmutableTransactionSummaryQuery copyOf(AggregateRepository.TransactionSummaryQuery instance) {
if (instance instanceof ImmutableTransactionSummaryQuery) {
return (ImmutableTransactionSummaryQuery) instance;
}
return ImmutableTransactionSummaryQuery.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.storage.repo.ImmutableTransactionSummaryQuery ImmutableTransactionSummaryQuery}.
* @return new ImmutableTransactionSummaryQuery builder
*/
public static ImmutableTransactionSummaryQuery.Builder builder() {
return new ImmutableTransactionSummaryQuery.Builder();
}
/**
* Builds instances of {@link org.glowroot.storage.repo.ImmutableTransactionSummaryQuery ImmutableTransactionSummaryQuery}.
* 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_ROLLUP = 0x1L;
private static final long INIT_BIT_TRANSACTION_TYPE = 0x2L;
private static final long INIT_BIT_FROM = 0x4L;
private static final long INIT_BIT_TO = 0x8L;
private static final long INIT_BIT_SORT_ORDER = 0x10L;
private static final long INIT_BIT_LIMIT = 0x20L;
private long initBits = 0x3f;
private @Nullable String serverRollup;
private @Nullable String transactionType;
private long from;
private long to;
private @Nullable AggregateRepository.TransactionSummarySortOrder sortOrder;
private int limit;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link AggregateRepository.TransactionSummaryQuery} 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(AggregateRepository.TransactionSummaryQuery instance) {
Preconditions.checkNotNull(instance);
serverRollup(instance.serverRollup());
transactionType(instance.transactionType());
from(instance.from());
to(instance.to());
sortOrder(instance.sortOrder());
limit(instance.limit());
return this;
}
/**
* Initializes value for {@link AggregateRepository.TransactionSummaryQuery#serverRollup() serverRollup}.
* @param serverRollup value for serverRollup
* @return {@code this} builder for chained invocation
*/
public final Builder serverRollup(String serverRollup) {
this.serverRollup = Preconditions.checkNotNull(serverRollup);
initBits &= ~INIT_BIT_SERVER_ROLLUP;
return this;
}
/**
* Initializes value for {@link AggregateRepository.TransactionSummaryQuery#transactionType() transactionType}.
* @param transactionType value for transactionType
* @return {@code this} builder for chained invocation
*/
public final Builder transactionType(String transactionType) {
this.transactionType = Preconditions.checkNotNull(transactionType);
initBits &= ~INIT_BIT_TRANSACTION_TYPE;
return this;
}
/**
* Initializes value for {@link AggregateRepository.TransactionSummaryQuery#from() from}.
* @param from value for from
* @return {@code this} builder for chained invocation
*/
public final Builder from(long from) {
this.from = from;
initBits &= ~INIT_BIT_FROM;
return this;
}
/**
* Initializes value for {@link AggregateRepository.TransactionSummaryQuery#to() to}.
* @param to value for to
* @return {@code this} builder for chained invocation
*/
public final Builder to(long to) {
this.to = to;
initBits &= ~INIT_BIT_TO;
return this;
}
/**
* Initializes value for {@link AggregateRepository.TransactionSummaryQuery#sortOrder() sortOrder}.
* @param sortOrder value for sortOrder
* @return {@code this} builder for chained invocation
*/
public final Builder sortOrder(AggregateRepository.TransactionSummarySortOrder sortOrder) {
this.sortOrder = Preconditions.checkNotNull(sortOrder);
initBits &= ~INIT_BIT_SORT_ORDER;
return this;
}
/**
* Initializes value for {@link AggregateRepository.TransactionSummaryQuery#limit() limit}.
* @param limit value for limit
* @return {@code this} builder for chained invocation
*/
public final Builder limit(int limit) {
this.limit = limit;
initBits &= ~INIT_BIT_LIMIT;
return this;
}
/**
* Builds new {@link org.glowroot.storage.repo.ImmutableTransactionSummaryQuery ImmutableTransactionSummaryQuery}.
* @return immutable instance of TransactionSummaryQuery
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableTransactionSummaryQuery build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableTransactionSummaryQuery(serverRollup, transactionType, from, to, sortOrder, limit);
}
private boolean serverRollupIsSet() {
return (initBits & INIT_BIT_SERVER_ROLLUP) == 0;
}
private boolean transactionTypeIsSet() {
return (initBits & INIT_BIT_TRANSACTION_TYPE) == 0;
}
private boolean fromIsSet() {
return (initBits & INIT_BIT_FROM) == 0;
}
private boolean toIsSet() {
return (initBits & INIT_BIT_TO) == 0;
}
private boolean sortOrderIsSet() {
return (initBits & INIT_BIT_SORT_ORDER) == 0;
}
private boolean limitIsSet() {
return (initBits & INIT_BIT_LIMIT) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!serverRollupIsSet()) attributes.add("serverRollup");
if (!transactionTypeIsSet()) attributes.add("transactionType");
if (!fromIsSet()) attributes.add("from");
if (!toIsSet()) attributes.add("to");
if (!sortOrderIsSet()) attributes.add("sortOrder");
if (!limitIsSet()) attributes.add("limit");
return "Cannot build TransactionSummaryQuery, some of required attributes are not set " + attributes;
}
}
}