
org.glowroot.ui.ImmutableTransactionConfigDto 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 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.TransactionConfigDto}.
*
* Use builder to create immutable instances:
* {@code ImmutableTransactionConfigDto.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ConfigJsonService.TransactionConfigDto"})
@Immutable
final class ImmutableTransactionConfigDto
extends ConfigJsonService.TransactionConfigDto {
private final int slowThresholdMillis;
private final int profilingIntervalMillis;
private final String version;
private ImmutableTransactionConfigDto(int slowThresholdMillis, int profilingIntervalMillis, String version) {
this.slowThresholdMillis = slowThresholdMillis;
this.profilingIntervalMillis = profilingIntervalMillis;
this.version = version;
}
/**
* @return value of {@code slowThresholdMillis} attribute
*/
@JsonProperty
@Override
int slowThresholdMillis() {
return slowThresholdMillis;
}
/**
* @return value of {@code profilingIntervalMillis} attribute
*/
@JsonProperty
@Override
int profilingIntervalMillis() {
return profilingIntervalMillis;
}
/**
* @return value of {@code version} attribute
*/
@JsonProperty
@Override
String version() {
return version;
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.TransactionConfigDto#slowThresholdMillis() slowThresholdMillis}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for slowThresholdMillis
* @return modified copy of the {@code this} object
*/
public final ImmutableTransactionConfigDto withSlowThresholdMillis(int value) {
if (this.slowThresholdMillis == value) return this;
int newValue = value;
return new ImmutableTransactionConfigDto(newValue, this.profilingIntervalMillis, this.version);
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.TransactionConfigDto#profilingIntervalMillis() profilingIntervalMillis}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for profilingIntervalMillis
* @return modified copy of the {@code this} object
*/
public final ImmutableTransactionConfigDto withProfilingIntervalMillis(int value) {
if (this.profilingIntervalMillis == value) return this;
int newValue = value;
return new ImmutableTransactionConfigDto(this.slowThresholdMillis, newValue, this.version);
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.TransactionConfigDto#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 ImmutableTransactionConfigDto withVersion(String value) {
if (this.version == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableTransactionConfigDto(this.slowThresholdMillis, this.profilingIntervalMillis, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableTransactionConfigDto} 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 ImmutableTransactionConfigDto
&& equalTo((ImmutableTransactionConfigDto) another);
}
private boolean equalTo(ImmutableTransactionConfigDto another) {
return slowThresholdMillis == another.slowThresholdMillis
&& profilingIntervalMillis == another.profilingIntervalMillis
&& version.equals(another.version);
}
/**
* Computes hash code from attributes: {@code slowThresholdMillis}, {@code profilingIntervalMillis}, {@code version}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + slowThresholdMillis;
h = h * 17 + profilingIntervalMillis;
h = h * 17 + version.hashCode();
return h;
}
/**
* Prints immutable value {@code TransactionConfigDto...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("TransactionConfigDto")
.add("slowThresholdMillis", slowThresholdMillis)
.add("profilingIntervalMillis", profilingIntervalMillis)
.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 Integer slowThresholdMillis;
@JsonProperty
@Nullable Integer profilingIntervalMillis;
@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 ImmutableTransactionConfigDto fromJson(Json json) {
ImmutableTransactionConfigDto.Builder builder = ImmutableTransactionConfigDto.builder();
if (json.slowThresholdMillis != null) {
builder.slowThresholdMillis(json.slowThresholdMillis);
}
if (json.profilingIntervalMillis != null) {
builder.profilingIntervalMillis(json.profilingIntervalMillis);
}
if (json.version != null) {
builder.version(json.version);
}
return builder.build();
}
/**
* Creates immutable copy of {@link ConfigJsonService.TransactionConfigDto}.
* 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 TransactionConfigDto instance
*/
static ImmutableTransactionConfigDto copyOf(ConfigJsonService.TransactionConfigDto instance) {
if (instance instanceof ImmutableTransactionConfigDto) {
return (ImmutableTransactionConfigDto) instance;
}
return ImmutableTransactionConfigDto.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableTransactionConfigDto ImmutableTransactionConfigDto}.
* @return new ImmutableTransactionConfigDto builder
*/
static ImmutableTransactionConfigDto.Builder builder() {
return new ImmutableTransactionConfigDto.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableTransactionConfigDto ImmutableTransactionConfigDto}.
* 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_SLOW_THRESHOLD_MILLIS = 0x1L;
private static final long INIT_BIT_PROFILING_INTERVAL_MILLIS = 0x2L;
private static final long INIT_BIT_VERSION = 0x4L;
private long initBits = 0x7;
private int slowThresholdMillis;
private int profilingIntervalMillis;
private @Nullable String version;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link ConfigJsonService.TransactionConfigDto} 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(ConfigJsonService.TransactionConfigDto instance) {
Preconditions.checkNotNull(instance);
slowThresholdMillis(instance.slowThresholdMillis());
profilingIntervalMillis(instance.profilingIntervalMillis());
version(instance.version());
return this;
}
/**
* Initializes value for {@link ConfigJsonService.TransactionConfigDto#slowThresholdMillis() slowThresholdMillis}.
* @param slowThresholdMillis value for slowThresholdMillis
* @return {@code this} builder for chained invocation
*/
public final Builder slowThresholdMillis(int slowThresholdMillis) {
this.slowThresholdMillis = slowThresholdMillis;
initBits &= ~INIT_BIT_SLOW_THRESHOLD_MILLIS;
return this;
}
/**
* Initializes value for {@link ConfigJsonService.TransactionConfigDto#profilingIntervalMillis() profilingIntervalMillis}.
* @param profilingIntervalMillis value for profilingIntervalMillis
* @return {@code this} builder for chained invocation
*/
public final Builder profilingIntervalMillis(int profilingIntervalMillis) {
this.profilingIntervalMillis = profilingIntervalMillis;
initBits &= ~INIT_BIT_PROFILING_INTERVAL_MILLIS;
return this;
}
/**
* Initializes value for {@link ConfigJsonService.TransactionConfigDto#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.ImmutableTransactionConfigDto ImmutableTransactionConfigDto}.
* @return immutable instance of TransactionConfigDto
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableTransactionConfigDto build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableTransactionConfigDto(slowThresholdMillis, profilingIntervalMillis, version);
}
private boolean slowThresholdMillisIsSet() {
return (initBits & INIT_BIT_SLOW_THRESHOLD_MILLIS) == 0;
}
private boolean profilingIntervalMillisIsSet() {
return (initBits & INIT_BIT_PROFILING_INTERVAL_MILLIS) == 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 (!slowThresholdMillisIsSet()) attributes.add("slowThresholdMillis");
if (!profilingIntervalMillisIsSet()) attributes.add("profilingIntervalMillis");
if (!versionIsSet()) attributes.add("version");
return "Cannot build TransactionConfigDto, some of required attributes are not set " + attributes;
}
}
}