
org.glowroot.ui.ImmutableQuery 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.Preconditions;
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.Query}.
*
* Use builder to create immutable instances:
* {@code ImmutableQuery.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "TransactionJsonService.Query"})
@Immutable
final class ImmutableQuery implements TransactionJsonService.Query {
private final String queryType;
private final String queryText;
private final double totalNanos;
private final long executionCount;
private final long totalRows;
private ImmutableQuery(
String queryType,
String queryText,
double totalNanos,
long executionCount,
long totalRows) {
this.queryType = queryType;
this.queryText = queryText;
this.totalNanos = totalNanos;
this.executionCount = executionCount;
this.totalRows = totalRows;
}
/**
* @return value of {@code queryType} attribute
*/
@JsonProperty
@Override
public String queryType() {
return queryType;
}
/**
* @return value of {@code queryText} attribute
*/
@JsonProperty
@Override
public String queryText() {
return queryText;
}
/**
* @return value of {@code totalNanos} attribute
*/
@JsonProperty
@Override
public double totalNanos() {
return totalNanos;
}
/**
* @return value of {@code executionCount} attribute
*/
@JsonProperty
@Override
public long executionCount() {
return executionCount;
}
/**
* @return value of {@code totalRows} attribute
*/
@JsonProperty
@Override
public long totalRows() {
return totalRows;
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.Query#queryType() queryType}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for queryType
* @return modified copy of the {@code this} object
*/
public final ImmutableQuery withQueryType(String value) {
if (this.queryType == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableQuery(newValue, this.queryText, this.totalNanos, this.executionCount, this.totalRows);
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.Query#queryText() queryText}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for queryText
* @return modified copy of the {@code this} object
*/
public final ImmutableQuery withQueryText(String value) {
if (this.queryText == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableQuery(this.queryType, newValue, this.totalNanos, this.executionCount, this.totalRows);
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.Query#totalNanos() totalNanos}.
* @param value new value for totalNanos
* @return modified copy of the {@code this} object
*/
public final ImmutableQuery withTotalNanos(double value) {
double newValue = value;
return new ImmutableQuery(this.queryType, this.queryText, newValue, this.executionCount, this.totalRows);
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.Query#executionCount() executionCount}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for executionCount
* @return modified copy of the {@code this} object
*/
public final ImmutableQuery withExecutionCount(long value) {
if (this.executionCount == value) return this;
long newValue = value;
return new ImmutableQuery(this.queryType, this.queryText, this.totalNanos, newValue, this.totalRows);
}
/**
* Copy current immutable object by setting value for {@link TransactionJsonService.Query#totalRows() totalRows}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for totalRows
* @return modified copy of the {@code this} object
*/
public final ImmutableQuery withTotalRows(long value) {
if (this.totalRows == value) return this;
long newValue = value;
return new ImmutableQuery(this.queryType, this.queryText, this.totalNanos, this.executionCount, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableQuery} 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 ImmutableQuery
&& equalTo((ImmutableQuery) another);
}
private boolean equalTo(ImmutableQuery another) {
return queryType.equals(another.queryType)
&& queryText.equals(another.queryText)
&& Double.doubleToLongBits(totalNanos) == Double.doubleToLongBits(another.totalNanos)
&& executionCount == another.executionCount
&& totalRows == another.totalRows;
}
/**
* Computes hash code from attributes: {@code queryType}, {@code queryText}, {@code totalNanos}, {@code executionCount}, {@code totalRows}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + queryType.hashCode();
h = h * 17 + queryText.hashCode();
h = h * 17 + Doubles.hashCode(totalNanos);
h = h * 17 + Longs.hashCode(executionCount);
h = h * 17 + Longs.hashCode(totalRows);
return h;
}
/**
* Prints immutable value {@code Query...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Query")
.add("queryType", queryType)
.add("queryText", queryText)
.add("totalNanos", totalNanos)
.add("executionCount", executionCount)
.add("totalRows", totalRows)
.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 queryType;
@JsonProperty
@Nullable String queryText;
@JsonProperty
@Nullable java.lang.Double totalNanos;
@JsonProperty
@Nullable Long executionCount;
@JsonProperty
@Nullable Long totalRows;
}
/**
* @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 ImmutableQuery fromJson(Json json) {
ImmutableQuery.Builder builder = ImmutableQuery.builder();
if (json.queryType != null) {
builder.queryType(json.queryType);
}
if (json.queryText != null) {
builder.queryText(json.queryText);
}
if (json.totalNanos != null) {
builder.totalNanos(json.totalNanos);
}
if (json.executionCount != null) {
builder.executionCount(json.executionCount);
}
if (json.totalRows != null) {
builder.totalRows(json.totalRows);
}
return builder.build();
}
/**
* Creates immutable copy of {@link TransactionJsonService.Query}.
* 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 Query instance
*/
static ImmutableQuery copyOf(TransactionJsonService.Query instance) {
if (instance instanceof ImmutableQuery) {
return (ImmutableQuery) instance;
}
return ImmutableQuery.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableQuery ImmutableQuery}.
* @return new ImmutableQuery builder
*/
static ImmutableQuery.Builder builder() {
return new ImmutableQuery.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableQuery ImmutableQuery}.
* 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_QUERY_TYPE = 0x1L;
private static final long INIT_BIT_QUERY_TEXT = 0x2L;
private static final long INIT_BIT_TOTAL_NANOS = 0x4L;
private static final long INIT_BIT_EXECUTION_COUNT = 0x8L;
private static final long INIT_BIT_TOTAL_ROWS = 0x10L;
private long initBits = 0x1f;
private @Nullable String queryType;
private @Nullable String queryText;
private double totalNanos;
private long executionCount;
private long totalRows;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link TransactionJsonService.Query} 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(TransactionJsonService.Query instance) {
Preconditions.checkNotNull(instance);
queryType(instance.queryType());
queryText(instance.queryText());
totalNanos(instance.totalNanos());
executionCount(instance.executionCount());
totalRows(instance.totalRows());
return this;
}
/**
* Initializes value for {@link TransactionJsonService.Query#queryType() queryType}.
* @param queryType value for queryType
* @return {@code this} builder for chained invocation
*/
public final Builder queryType(String queryType) {
this.queryType = Preconditions.checkNotNull(queryType);
initBits &= ~INIT_BIT_QUERY_TYPE;
return this;
}
/**
* Initializes value for {@link TransactionJsonService.Query#queryText() queryText}.
* @param queryText value for queryText
* @return {@code this} builder for chained invocation
*/
public final Builder queryText(String queryText) {
this.queryText = Preconditions.checkNotNull(queryText);
initBits &= ~INIT_BIT_QUERY_TEXT;
return this;
}
/**
* Initializes value for {@link TransactionJsonService.Query#totalNanos() totalNanos}.
* @param totalNanos value for totalNanos
* @return {@code this} builder for chained invocation
*/
public final Builder totalNanos(double totalNanos) {
this.totalNanos = totalNanos;
initBits &= ~INIT_BIT_TOTAL_NANOS;
return this;
}
/**
* Initializes value for {@link TransactionJsonService.Query#executionCount() executionCount}.
* @param executionCount value for executionCount
* @return {@code this} builder for chained invocation
*/
public final Builder executionCount(long executionCount) {
this.executionCount = executionCount;
initBits &= ~INIT_BIT_EXECUTION_COUNT;
return this;
}
/**
* Initializes value for {@link TransactionJsonService.Query#totalRows() totalRows}.
* @param totalRows value for totalRows
* @return {@code this} builder for chained invocation
*/
public final Builder totalRows(long totalRows) {
this.totalRows = totalRows;
initBits &= ~INIT_BIT_TOTAL_ROWS;
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutableQuery ImmutableQuery}.
* @return immutable instance of Query
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableQuery build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableQuery(queryType, queryText, totalNanos, executionCount, totalRows);
}
private boolean queryTypeIsSet() {
return (initBits & INIT_BIT_QUERY_TYPE) == 0;
}
private boolean queryTextIsSet() {
return (initBits & INIT_BIT_QUERY_TEXT) == 0;
}
private boolean totalNanosIsSet() {
return (initBits & INIT_BIT_TOTAL_NANOS) == 0;
}
private boolean executionCountIsSet() {
return (initBits & INIT_BIT_EXECUTION_COUNT) == 0;
}
private boolean totalRowsIsSet() {
return (initBits & INIT_BIT_TOTAL_ROWS) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!queryTypeIsSet()) attributes.add("queryType");
if (!queryTextIsSet()) attributes.add("queryText");
if (!totalNanosIsSet()) attributes.add("totalNanos");
if (!executionCountIsSet()) attributes.add("executionCount");
if (!totalRowsIsSet()) attributes.add("totalRows");
return "Cannot build Query, some of required attributes are not set " + attributes;
}
}
}