
org.glowroot.ui.ImmutableTransactionDataRequest Maven / Gradle / Ivy
package org.glowroot.ui;
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.Objects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.ImmutableList;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Doubles;
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 TransactionJsonService.TransactionDataRequest}.
*
* Use builder to create immutable instances:
* {@code ImmutableTransactionDataRequest.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "TransactionJsonService.TransactionDataRequest"})
@Immutable
final class ImmutableTransactionDataRequest
implements TransactionJsonService.TransactionDataRequest {
private final String serverRollup;
private final String transactionType;
private final @Nullable String transactionName;
private final long from;
private final long to;
private final ImmutableList percentile;
private ImmutableTransactionDataRequest(
String serverRollup,
String transactionType,
@Nullable String transactionName,
long from,
long to,
ImmutableList percentile) {
this.serverRollup = serverRollup;
this.transactionType = transactionType;
this.transactionName = transactionName;
this.from = from;
this.to = to;
this.percentile = percentile;
}
/**
* @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 transactionName} attribute
*/
@JsonProperty
@Override
public @Nullable String transactionName() {
return transactionName;
}
/**
* @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 percentile} attribute
*/
@JsonProperty
@Override
public ImmutableList percentile() {
return percentile;
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.TransactionDataRequest#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 ImmutableTransactionDataRequest withServerRollup(String value) {
if (this.serverRollup == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableTransactionDataRequest(newValue, this.transactionType, this.transactionName, this.from, this.to, this.percentile);
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.TransactionDataRequest#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 ImmutableTransactionDataRequest withTransactionType(String value) {
if (this.transactionType == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableTransactionDataRequest(this.serverRollup, newValue, this.transactionName, this.from, this.to, this.percentile);
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.TransactionDataRequest#transactionName() transactionName}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for transactionName, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableTransactionDataRequest withTransactionName(@Nullable String value) {
if (this.transactionName == value) return this;
@Nullable String newValue = value;
return new ImmutableTransactionDataRequest(this.serverRollup, this.transactionType, newValue, this.from, this.to, this.percentile);
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.TransactionDataRequest#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 ImmutableTransactionDataRequest withFrom(long value) {
if (this.from == value) return this;
long newValue = value;
return new ImmutableTransactionDataRequest(
this.serverRollup,
this.transactionType,
this.transactionName,
newValue,
this.to,
this.percentile);
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.TransactionDataRequest#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 ImmutableTransactionDataRequest withTo(long value) {
if (this.to == value) return this;
long newValue = value;
return new ImmutableTransactionDataRequest(
this.serverRollup,
this.transactionType,
this.transactionName,
this.from,
newValue,
this.percentile);
}
/**
* Copy current immutable object with elements that replace content of {@link TransactionJsonService.TransactionDataRequest#percentile() percentile}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableTransactionDataRequest withPercentile(double... elements) {
ImmutableList newValue = ImmutableList.copyOf(Doubles.asList(elements));
return new ImmutableTransactionDataRequest(this.serverRollup, this.transactionType, this.transactionName, this.from, this.to, newValue);
}
/**
* Copy current immutable object with elements that replace content of {@link TransactionJsonService.TransactionDataRequest#percentile() percentile}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of percentile elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableTransactionDataRequest withPercentile(Iterable elements) {
if (this.percentile == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableTransactionDataRequest(this.serverRollup, this.transactionType, this.transactionName, this.from, this.to, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableTransactionDataRequest} 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 ImmutableTransactionDataRequest
&& equalTo((ImmutableTransactionDataRequest) another);
}
private boolean equalTo(ImmutableTransactionDataRequest another) {
return serverRollup.equals(another.serverRollup)
&& transactionType.equals(another.transactionType)
&& Objects.equal(transactionName, another.transactionName)
&& from == another.from
&& to == another.to
&& percentile.equals(another.percentile);
}
/**
* Computes hash code from attributes: {@code serverRollup}, {@code transactionType}, {@code transactionName}, {@code from}, {@code to}, {@code percentile}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + serverRollup.hashCode();
h = h * 17 + transactionType.hashCode();
h = h * 17 + Objects.hashCode(transactionName);
h = h * 17 + Longs.hashCode(from);
h = h * 17 + Longs.hashCode(to);
h = h * 17 + percentile.hashCode();
return h;
}
/**
* Prints immutable value {@code TransactionDataRequest...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("TransactionDataRequest")
.add("serverRollup", serverRollup)
.add("transactionType", transactionType)
.add("transactionName", transactionName)
.add("from", from)
.add("to", to)
.add("percentile", percentile)
.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 String transactionName;
@JsonProperty
@Nullable Long from;
@JsonProperty
@Nullable Long to;
@JsonProperty
@Nullable ImmutableList percentile;
}
/**
* @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 ImmutableTransactionDataRequest fromJson(Json json) {
ImmutableTransactionDataRequest.Builder builder = ImmutableTransactionDataRequest.builder();
if (json.serverRollup != null) {
builder.serverRollup(json.serverRollup);
}
if (json.transactionType != null) {
builder.transactionType(json.transactionType);
}
if (json.transactionName != null) {
builder.transactionName(json.transactionName);
}
if (json.from != null) {
builder.from(json.from);
}
if (json.to != null) {
builder.to(json.to);
}
if (json.percentile != null) {
builder.addAllPercentile(json.percentile);
}
return builder.build();
}
/**
* Creates immutable copy of {@link TransactionJsonService.TransactionDataRequest}.
* 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 TransactionDataRequest instance
*/
static ImmutableTransactionDataRequest copyOf(TransactionJsonService.TransactionDataRequest instance) {
if (instance instanceof ImmutableTransactionDataRequest) {
return (ImmutableTransactionDataRequest) instance;
}
return ImmutableTransactionDataRequest.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableTransactionDataRequest ImmutableTransactionDataRequest}.
* @return new ImmutableTransactionDataRequest builder
*/
static ImmutableTransactionDataRequest.Builder builder() {
return new ImmutableTransactionDataRequest.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableTransactionDataRequest ImmutableTransactionDataRequest}.
* 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_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 long initBits = 0xf;
private @Nullable String serverRollup;
private @Nullable String transactionType;
private @Nullable String transactionName;
private long from;
private long to;
private ImmutableList.Builder percentileBuilder = ImmutableList.builder();
private Builder() {}
/**
* Fill builder with attribute values from provided {@link TransactionJsonService.TransactionDataRequest} instance.
* Regular attribute values will be replaced with ones of an instance.
* Instance's absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance instance to copy values from
* @return {@code this} builder for chained invocation
*/
public final Builder copyFrom(TransactionJsonService.TransactionDataRequest instance) {
Preconditions.checkNotNull(instance);
serverRollup(instance.serverRollup());
transactionType(instance.transactionType());
@Nullable String transactionNameValue = instance.transactionName();
if (transactionNameValue != null) {
transactionName(transactionNameValue);
}
from(instance.from());
to(instance.to());
addAllPercentile(instance.percentile());
return this;
}
/**
* Initializes value for {@link TransactionJsonService.TransactionDataRequest#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 TransactionJsonService.TransactionDataRequest#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 TransactionJsonService.TransactionDataRequest#transactionName() transactionName}.
* @param transactionName value for transactionName, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder transactionName(@Nullable String transactionName) {
this.transactionName = transactionName;
return this;
}
/**
* Initializes value for {@link TransactionJsonService.TransactionDataRequest#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 TransactionJsonService.TransactionDataRequest#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;
}
/**
* Adds one element to {@link TransactionJsonService.TransactionDataRequest#percentile() percentile} list.
* @param element percentile element
* @return {@code this} builder for chained invocation
*/
public final Builder addPercentile(double element) {
percentileBuilder.add(element);
return this;
}
/**
* Adds elements to {@link TransactionJsonService.TransactionDataRequest#percentile() percentile} list.
* @param elements array of percentile elements
* @return {@code this} builder for chained invocation
*/
public final Builder addPercentile(double... elements) {
percentileBuilder.addAll(Doubles.asList(elements));
return this;
}
/**
* Sets or replaces all elements for {@link TransactionJsonService.TransactionDataRequest#percentile() percentile} list.
* @param elements iterable of percentile elements
* @return {@code this} builder for chained invocation
*/
public final Builder percentile(Iterable elements) {
percentileBuilder = ImmutableList.builder();
return addAllPercentile(elements);
}
/**
* Adds elements to {@link TransactionJsonService.TransactionDataRequest#percentile() percentile} list.
* @param elements iterable of percentile elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllPercentile(Iterable elements) {
percentileBuilder.addAll(elements);
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutableTransactionDataRequest ImmutableTransactionDataRequest}.
* @return immutable instance of TransactionDataRequest
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableTransactionDataRequest build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableTransactionDataRequest(serverRollup, transactionType, transactionName, from, to, percentileBuilder.build());
}
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 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");
return "Cannot build TransactionDataRequest, some of required attributes are not set " + attributes;
}
}
}