
org.glowroot.ui.ImmutableGaugeValueRequest 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.ImmutableList;
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 GaugeValueJsonService.GaugeValueRequest}.
*
* Use builder to create immutable instances:
* {@code ImmutableGaugeValueRequest.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "GaugeValueJsonService.GaugeValueRequest"})
@Immutable
final class ImmutableGaugeValueRequest
implements GaugeValueJsonService.GaugeValueRequest {
private final String serverRollup;
private final long from;
private final long to;
private final ImmutableList gaugeNames;
private ImmutableGaugeValueRequest(
String serverRollup,
long from,
long to,
ImmutableList gaugeNames) {
this.serverRollup = serverRollup;
this.from = from;
this.to = to;
this.gaugeNames = gaugeNames;
}
/**
* @return value of {@code serverRollup} attribute
*/
@JsonProperty
@Override
public String serverRollup() {
return serverRollup;
}
/**
* @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 gaugeNames} attribute
*/
@JsonProperty
@Override
public ImmutableList gaugeNames() {
return gaugeNames;
}
/**
* Copy current immutable object by setting value for {@link GaugeValueJsonService.GaugeValueRequest#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 ImmutableGaugeValueRequest withServerRollup(String value) {
if (this.serverRollup == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableGaugeValueRequest(newValue, this.from, this.to, this.gaugeNames);
}
/**
* Copy current immutable object by setting value for {@link GaugeValueJsonService.GaugeValueRequest#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 ImmutableGaugeValueRequest withFrom(long value) {
if (this.from == value) return this;
long newValue = value;
return new ImmutableGaugeValueRequest(this.serverRollup, newValue, this.to, this.gaugeNames);
}
/**
* Copy current immutable object by setting value for {@link GaugeValueJsonService.GaugeValueRequest#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 ImmutableGaugeValueRequest withTo(long value) {
if (this.to == value) return this;
long newValue = value;
return new ImmutableGaugeValueRequest(this.serverRollup, this.from, newValue, this.gaugeNames);
}
/**
* Copy current immutable object with elements that replace content of {@link GaugeValueJsonService.GaugeValueRequest#gaugeNames() gaugeNames}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableGaugeValueRequest withGaugeNames(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableGaugeValueRequest(this.serverRollup, this.from, this.to, newValue);
}
/**
* Copy current immutable object with elements that replace content of {@link GaugeValueJsonService.GaugeValueRequest#gaugeNames() gaugeNames}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of gaugeNames elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableGaugeValueRequest withGaugeNames(Iterable elements) {
if (this.gaugeNames == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableGaugeValueRequest(this.serverRollup, this.from, this.to, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableGaugeValueRequest} 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 ImmutableGaugeValueRequest
&& equalTo((ImmutableGaugeValueRequest) another);
}
private boolean equalTo(ImmutableGaugeValueRequest another) {
return serverRollup.equals(another.serverRollup)
&& from == another.from
&& to == another.to
&& gaugeNames.equals(another.gaugeNames);
}
/**
* Computes hash code from attributes: {@code serverRollup}, {@code from}, {@code to}, {@code gaugeNames}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + serverRollup.hashCode();
h = h * 17 + Longs.hashCode(from);
h = h * 17 + Longs.hashCode(to);
h = h * 17 + gaugeNames.hashCode();
return h;
}
/**
* Prints immutable value {@code GaugeValueRequest...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("GaugeValueRequest")
.add("serverRollup", serverRollup)
.add("from", from)
.add("to", to)
.add("gaugeNames", gaugeNames)
.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 Long from;
@JsonProperty
@Nullable Long to;
@JsonProperty
@Nullable ImmutableList gaugeNames;
}
/**
* @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 ImmutableGaugeValueRequest fromJson(Json json) {
ImmutableGaugeValueRequest.Builder builder = ImmutableGaugeValueRequest.builder();
if (json.serverRollup != null) {
builder.serverRollup(json.serverRollup);
}
if (json.from != null) {
builder.from(json.from);
}
if (json.to != null) {
builder.to(json.to);
}
if (json.gaugeNames != null) {
builder.addAllGaugeNames(json.gaugeNames);
}
return builder.build();
}
/**
* Creates immutable copy of {@link GaugeValueJsonService.GaugeValueRequest}.
* 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 GaugeValueRequest instance
*/
static ImmutableGaugeValueRequest copyOf(GaugeValueJsonService.GaugeValueRequest instance) {
if (instance instanceof ImmutableGaugeValueRequest) {
return (ImmutableGaugeValueRequest) instance;
}
return ImmutableGaugeValueRequest.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableGaugeValueRequest ImmutableGaugeValueRequest}.
* @return new ImmutableGaugeValueRequest builder
*/
static ImmutableGaugeValueRequest.Builder builder() {
return new ImmutableGaugeValueRequest.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableGaugeValueRequest ImmutableGaugeValueRequest}.
* 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_FROM = 0x2L;
private static final long INIT_BIT_TO = 0x4L;
private long initBits = 0x7;
private @Nullable String serverRollup;
private long from;
private long to;
private ImmutableList.Builder gaugeNamesBuilder = ImmutableList.builder();
private Builder() {}
/**
* Fill builder with attribute values from provided {@link GaugeValueJsonService.GaugeValueRequest} 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(GaugeValueJsonService.GaugeValueRequest instance) {
Preconditions.checkNotNull(instance);
serverRollup(instance.serverRollup());
from(instance.from());
to(instance.to());
addAllGaugeNames(instance.gaugeNames());
return this;
}
/**
* Initializes value for {@link GaugeValueJsonService.GaugeValueRequest#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 GaugeValueJsonService.GaugeValueRequest#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 GaugeValueJsonService.GaugeValueRequest#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 GaugeValueJsonService.GaugeValueRequest#gaugeNames() gaugeNames} list.
* @param element gaugeNames element
* @return {@code this} builder for chained invocation
*/
public final Builder addGaugeNames(String element) {
gaugeNamesBuilder.add(element);
return this;
}
/**
* Adds elements to {@link GaugeValueJsonService.GaugeValueRequest#gaugeNames() gaugeNames} list.
* @param elements array of gaugeNames elements
* @return {@code this} builder for chained invocation
*/
public final Builder addGaugeNames(String... elements) {
gaugeNamesBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link GaugeValueJsonService.GaugeValueRequest#gaugeNames() gaugeNames} list.
* @param elements iterable of gaugeNames elements
* @return {@code this} builder for chained invocation
*/
public final Builder gaugeNames(Iterable elements) {
gaugeNamesBuilder = ImmutableList.builder();
return addAllGaugeNames(elements);
}
/**
* Adds elements to {@link GaugeValueJsonService.GaugeValueRequest#gaugeNames() gaugeNames} list.
* @param elements iterable of gaugeNames elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllGaugeNames(Iterable elements) {
gaugeNamesBuilder.addAll(elements);
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutableGaugeValueRequest ImmutableGaugeValueRequest}.
* @return immutable instance of GaugeValueRequest
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableGaugeValueRequest build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableGaugeValueRequest(serverRollup, from, to, gaugeNamesBuilder.build());
}
private boolean serverRollupIsSet() {
return (initBits & INIT_BIT_SERVER_ROLLUP) == 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 (!fromIsSet()) attributes.add("from");
if (!toIsSet()) attributes.add("to");
return "Cannot build GaugeValueRequest, some of required attributes are not set " + attributes;
}
}
}