
org.glowroot.ui.ImmutableStorageConfigDto 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.Ints;
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 ConfigJsonService.StorageConfigDto}.
*
* Use builder to create immutable instances:
* {@code ImmutableStorageConfigDto.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ConfigJsonService.StorageConfigDto"})
@Immutable
final class ImmutableStorageConfigDto extends ConfigJsonService.StorageConfigDto {
private final ImmutableList rollupExpirationHours;
private final int traceExpirationHours;
private final ImmutableList rollupCappedDatabaseSizesMb;
private final int traceCappedDatabaseSizeMb;
private final String version;
private ImmutableStorageConfigDto(
ImmutableList rollupExpirationHours,
int traceExpirationHours,
ImmutableList rollupCappedDatabaseSizesMb,
int traceCappedDatabaseSizeMb,
String version) {
this.rollupExpirationHours = rollupExpirationHours;
this.traceExpirationHours = traceExpirationHours;
this.rollupCappedDatabaseSizesMb = rollupCappedDatabaseSizesMb;
this.traceCappedDatabaseSizeMb = traceCappedDatabaseSizeMb;
this.version = version;
}
/**
* @return value of {@code rollupExpirationHours} attribute
*/
@JsonProperty
@Override
ImmutableList rollupExpirationHours() {
return rollupExpirationHours;
}
/**
* @return value of {@code traceExpirationHours} attribute
*/
@JsonProperty
@Override
int traceExpirationHours() {
return traceExpirationHours;
}
/**
* @return value of {@code rollupCappedDatabaseSizesMb} attribute
*/
@JsonProperty
@Override
ImmutableList rollupCappedDatabaseSizesMb() {
return rollupCappedDatabaseSizesMb;
}
/**
* @return value of {@code traceCappedDatabaseSizeMb} attribute
*/
@JsonProperty
@Override
int traceCappedDatabaseSizeMb() {
return traceCappedDatabaseSizeMb;
}
/**
* @return value of {@code version} attribute
*/
@JsonProperty
@Override
String version() {
return version;
}
/**
* Copy current immutable object with elements that replace content of {@link ConfigJsonService.StorageConfigDto#rollupExpirationHours() rollupExpirationHours}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableStorageConfigDto withRollupExpirationHours(int... elements) {
ImmutableList newValue = ImmutableList.copyOf(Ints.asList(elements));
return new ImmutableStorageConfigDto(
newValue,
this.traceExpirationHours,
this.rollupCappedDatabaseSizesMb,
this.traceCappedDatabaseSizeMb,
this.version);
}
/**
* Copy current immutable object with elements that replace content of {@link ConfigJsonService.StorageConfigDto#rollupExpirationHours() rollupExpirationHours}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of rollupExpirationHours elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableStorageConfigDto withRollupExpirationHours(Iterable elements) {
if (this.rollupExpirationHours == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableStorageConfigDto(
newValue,
this.traceExpirationHours,
this.rollupCappedDatabaseSizesMb,
this.traceCappedDatabaseSizeMb,
this.version);
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.StorageConfigDto#traceExpirationHours() traceExpirationHours}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for traceExpirationHours
* @return modified copy of the {@code this} object
*/
public final ImmutableStorageConfigDto withTraceExpirationHours(int value) {
if (this.traceExpirationHours == value) return this;
int newValue = value;
return new ImmutableStorageConfigDto(
this.rollupExpirationHours,
newValue,
this.rollupCappedDatabaseSizesMb,
this.traceCappedDatabaseSizeMb,
this.version);
}
/**
* Copy current immutable object with elements that replace content of {@link ConfigJsonService.StorageConfigDto#rollupCappedDatabaseSizesMb() rollupCappedDatabaseSizesMb}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableStorageConfigDto withRollupCappedDatabaseSizesMb(int... elements) {
ImmutableList newValue = ImmutableList.copyOf(Ints.asList(elements));
return new ImmutableStorageConfigDto(
this.rollupExpirationHours,
this.traceExpirationHours,
newValue,
this.traceCappedDatabaseSizeMb,
this.version);
}
/**
* Copy current immutable object with elements that replace content of {@link ConfigJsonService.StorageConfigDto#rollupCappedDatabaseSizesMb() rollupCappedDatabaseSizesMb}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of rollupCappedDatabaseSizesMb elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableStorageConfigDto withRollupCappedDatabaseSizesMb(Iterable elements) {
if (this.rollupCappedDatabaseSizesMb == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableStorageConfigDto(
this.rollupExpirationHours,
this.traceExpirationHours,
newValue,
this.traceCappedDatabaseSizeMb,
this.version);
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.StorageConfigDto#traceCappedDatabaseSizeMb() traceCappedDatabaseSizeMb}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for traceCappedDatabaseSizeMb
* @return modified copy of the {@code this} object
*/
public final ImmutableStorageConfigDto withTraceCappedDatabaseSizeMb(int value) {
if (this.traceCappedDatabaseSizeMb == value) return this;
int newValue = value;
return new ImmutableStorageConfigDto(
this.rollupExpirationHours,
this.traceExpirationHours,
this.rollupCappedDatabaseSizesMb,
newValue,
this.version);
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.StorageConfigDto#version() version}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for version
* @return modified copy of the {@code this} object
*/
public final ImmutableStorageConfigDto withVersion(String value) {
if (this.version == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableStorageConfigDto(
this.rollupExpirationHours,
this.traceExpirationHours,
this.rollupCappedDatabaseSizesMb,
this.traceCappedDatabaseSizeMb,
newValue);
}
/**
* This instance is equal to instances of {@code ImmutableStorageConfigDto} 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 ImmutableStorageConfigDto
&& equalTo((ImmutableStorageConfigDto) another);
}
private boolean equalTo(ImmutableStorageConfigDto another) {
return rollupExpirationHours.equals(another.rollupExpirationHours)
&& traceExpirationHours == another.traceExpirationHours
&& rollupCappedDatabaseSizesMb.equals(another.rollupCappedDatabaseSizesMb)
&& traceCappedDatabaseSizeMb == another.traceCappedDatabaseSizeMb
&& version.equals(another.version);
}
/**
* Computes hash code from attributes: {@code rollupExpirationHours}, {@code traceExpirationHours}, {@code rollupCappedDatabaseSizesMb}, {@code traceCappedDatabaseSizeMb}, {@code version}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + rollupExpirationHours.hashCode();
h = h * 17 + traceExpirationHours;
h = h * 17 + rollupCappedDatabaseSizesMb.hashCode();
h = h * 17 + traceCappedDatabaseSizeMb;
h = h * 17 + version.hashCode();
return h;
}
/**
* Prints immutable value {@code StorageConfigDto...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("StorageConfigDto")
.add("rollupExpirationHours", rollupExpirationHours)
.add("traceExpirationHours", traceExpirationHours)
.add("rollupCappedDatabaseSizesMb", rollupCappedDatabaseSizesMb)
.add("traceCappedDatabaseSizeMb", traceCappedDatabaseSizeMb)
.add("version", version)
.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 ImmutableList rollupExpirationHours;
@JsonProperty
@Nullable Integer traceExpirationHours;
@JsonProperty
@Nullable ImmutableList rollupCappedDatabaseSizesMb;
@JsonProperty
@Nullable Integer traceCappedDatabaseSizeMb;
@JsonProperty
@Nullable String version;
}
/**
* @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 ImmutableStorageConfigDto fromJson(Json json) {
ImmutableStorageConfigDto.Builder builder = ImmutableStorageConfigDto.builder();
if (json.rollupExpirationHours != null) {
builder.addAllRollupExpirationHours(json.rollupExpirationHours);
}
if (json.traceExpirationHours != null) {
builder.traceExpirationHours(json.traceExpirationHours);
}
if (json.rollupCappedDatabaseSizesMb != null) {
builder.addAllRollupCappedDatabaseSizesMb(json.rollupCappedDatabaseSizesMb);
}
if (json.traceCappedDatabaseSizeMb != null) {
builder.traceCappedDatabaseSizeMb(json.traceCappedDatabaseSizeMb);
}
if (json.version != null) {
builder.version(json.version);
}
return builder.build();
}
/**
* Creates immutable copy of {@link ConfigJsonService.StorageConfigDto}.
* 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 StorageConfigDto instance
*/
static ImmutableStorageConfigDto copyOf(ConfigJsonService.StorageConfigDto instance) {
if (instance instanceof ImmutableStorageConfigDto) {
return (ImmutableStorageConfigDto) instance;
}
return ImmutableStorageConfigDto.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableStorageConfigDto ImmutableStorageConfigDto}.
* @return new ImmutableStorageConfigDto builder
*/
static ImmutableStorageConfigDto.Builder builder() {
return new ImmutableStorageConfigDto.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableStorageConfigDto ImmutableStorageConfigDto}.
* 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_TRACE_EXPIRATION_HOURS = 0x1L;
private static final long INIT_BIT_TRACE_CAPPED_DATABASE_SIZE_MB = 0x2L;
private static final long INIT_BIT_VERSION = 0x4L;
private long initBits = 0x7;
private ImmutableList.Builder rollupExpirationHoursBuilder = ImmutableList.builder();
private int traceExpirationHours;
private ImmutableList.Builder rollupCappedDatabaseSizesMbBuilder = ImmutableList.builder();
private int traceCappedDatabaseSizeMb;
private @Nullable String version;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link ConfigJsonService.StorageConfigDto} 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(ConfigJsonService.StorageConfigDto instance) {
Preconditions.checkNotNull(instance);
addAllRollupExpirationHours(instance.rollupExpirationHours());
traceExpirationHours(instance.traceExpirationHours());
addAllRollupCappedDatabaseSizesMb(instance.rollupCappedDatabaseSizesMb());
traceCappedDatabaseSizeMb(instance.traceCappedDatabaseSizeMb());
version(instance.version());
return this;
}
/**
* Adds one element to {@link ConfigJsonService.StorageConfigDto#rollupExpirationHours() rollupExpirationHours} list.
* @param element rollupExpirationHours element
* @return {@code this} builder for chained invocation
*/
public final Builder addRollupExpirationHours(int element) {
rollupExpirationHoursBuilder.add(element);
return this;
}
/**
* Adds elements to {@link ConfigJsonService.StorageConfigDto#rollupExpirationHours() rollupExpirationHours} list.
* @param elements array of rollupExpirationHours elements
* @return {@code this} builder for chained invocation
*/
public final Builder addRollupExpirationHours(int... elements) {
rollupExpirationHoursBuilder.addAll(Ints.asList(elements));
return this;
}
/**
* Sets or replaces all elements for {@link ConfigJsonService.StorageConfigDto#rollupExpirationHours() rollupExpirationHours} list.
* @param elements iterable of rollupExpirationHours elements
* @return {@code this} builder for chained invocation
*/
public final Builder rollupExpirationHours(Iterable elements) {
rollupExpirationHoursBuilder = ImmutableList.builder();
return addAllRollupExpirationHours(elements);
}
/**
* Adds elements to {@link ConfigJsonService.StorageConfigDto#rollupExpirationHours() rollupExpirationHours} list.
* @param elements iterable of rollupExpirationHours elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllRollupExpirationHours(Iterable elements) {
rollupExpirationHoursBuilder.addAll(elements);
return this;
}
/**
* Initializes value for {@link ConfigJsonService.StorageConfigDto#traceExpirationHours() traceExpirationHours}.
* @param traceExpirationHours value for traceExpirationHours
* @return {@code this} builder for chained invocation
*/
public final Builder traceExpirationHours(int traceExpirationHours) {
this.traceExpirationHours = traceExpirationHours;
initBits &= ~INIT_BIT_TRACE_EXPIRATION_HOURS;
return this;
}
/**
* Adds one element to {@link ConfigJsonService.StorageConfigDto#rollupCappedDatabaseSizesMb() rollupCappedDatabaseSizesMb} list.
* @param element rollupCappedDatabaseSizesMb element
* @return {@code this} builder for chained invocation
*/
public final Builder addRollupCappedDatabaseSizesMb(int element) {
rollupCappedDatabaseSizesMbBuilder.add(element);
return this;
}
/**
* Adds elements to {@link ConfigJsonService.StorageConfigDto#rollupCappedDatabaseSizesMb() rollupCappedDatabaseSizesMb} list.
* @param elements array of rollupCappedDatabaseSizesMb elements
* @return {@code this} builder for chained invocation
*/
public final Builder addRollupCappedDatabaseSizesMb(int... elements) {
rollupCappedDatabaseSizesMbBuilder.addAll(Ints.asList(elements));
return this;
}
/**
* Sets or replaces all elements for {@link ConfigJsonService.StorageConfigDto#rollupCappedDatabaseSizesMb() rollupCappedDatabaseSizesMb} list.
* @param elements iterable of rollupCappedDatabaseSizesMb elements
* @return {@code this} builder for chained invocation
*/
public final Builder rollupCappedDatabaseSizesMb(Iterable elements) {
rollupCappedDatabaseSizesMbBuilder = ImmutableList.builder();
return addAllRollupCappedDatabaseSizesMb(elements);
}
/**
* Adds elements to {@link ConfigJsonService.StorageConfigDto#rollupCappedDatabaseSizesMb() rollupCappedDatabaseSizesMb} list.
* @param elements iterable of rollupCappedDatabaseSizesMb elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllRollupCappedDatabaseSizesMb(Iterable elements) {
rollupCappedDatabaseSizesMbBuilder.addAll(elements);
return this;
}
/**
* Initializes value for {@link ConfigJsonService.StorageConfigDto#traceCappedDatabaseSizeMb() traceCappedDatabaseSizeMb}.
* @param traceCappedDatabaseSizeMb value for traceCappedDatabaseSizeMb
* @return {@code this} builder for chained invocation
*/
public final Builder traceCappedDatabaseSizeMb(int traceCappedDatabaseSizeMb) {
this.traceCappedDatabaseSizeMb = traceCappedDatabaseSizeMb;
initBits &= ~INIT_BIT_TRACE_CAPPED_DATABASE_SIZE_MB;
return this;
}
/**
* Initializes value for {@link ConfigJsonService.StorageConfigDto#version() version}.
* @param version value for version
* @return {@code this} builder for chained invocation
*/
public final Builder version(String version) {
this.version = Preconditions.checkNotNull(version);
initBits &= ~INIT_BIT_VERSION;
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutableStorageConfigDto ImmutableStorageConfigDto}.
* @return immutable instance of StorageConfigDto
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableStorageConfigDto build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableStorageConfigDto(
rollupExpirationHoursBuilder.build(),
traceExpirationHours,
rollupCappedDatabaseSizesMbBuilder.build(),
traceCappedDatabaseSizeMb,
version);
}
private boolean traceExpirationHoursIsSet() {
return (initBits & INIT_BIT_TRACE_EXPIRATION_HOURS) == 0;
}
private boolean traceCappedDatabaseSizeMbIsSet() {
return (initBits & INIT_BIT_TRACE_CAPPED_DATABASE_SIZE_MB) == 0;
}
private boolean versionIsSet() {
return (initBits & INIT_BIT_VERSION) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!traceExpirationHoursIsSet()) attributes.add("traceExpirationHours");
if (!traceCappedDatabaseSizeMbIsSet()) attributes.add("traceCappedDatabaseSizeMb");
if (!versionIsSet()) attributes.add("version");
return "Cannot build StorageConfigDto, some of required attributes are not set " + attributes;
}
}
}