
org.glowroot.storage.repo.config.ImmutableAlertConfig Maven / Gradle / Ivy
package org.glowroot.storage.repo.config;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonIgnore;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonInclude;
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.Doubles;
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 AlertConfig}.
*
* Use builder to create immutable instances:
* {@code ImmutableAlertConfig.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "AlertConfig"})
@Immutable
public final class ImmutableAlertConfig extends AlertConfig {
private final String transactionType;
private final double percentile;
private final int timePeriodMinutes;
private final int thresholdMillis;
private final int minTransactionCount;
private final ImmutableList emailAddresses;
private final String version;
private ImmutableAlertConfig(
String transactionType,
double percentile,
int timePeriodMinutes,
int thresholdMillis,
int minTransactionCount,
ImmutableList emailAddresses) {
this.transactionType = transactionType;
this.percentile = percentile;
this.timePeriodMinutes = timePeriodMinutes;
this.thresholdMillis = thresholdMillis;
this.minTransactionCount = minTransactionCount;
this.emailAddresses = emailAddresses;
this.version = Preconditions.checkNotNull(super.version());
}
/**
* @return value of {@code transactionType} attribute
*/
@JsonProperty
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
@Override
public String transactionType() {
return transactionType;
}
/**
* @return value of {@code percentile} attribute
*/
@JsonProperty
@Override
public double percentile() {
return percentile;
}
/**
* @return value of {@code timePeriodMinutes} attribute
*/
@JsonProperty
@Override
public int timePeriodMinutes() {
return timePeriodMinutes;
}
/**
* @return value of {@code thresholdMillis} attribute
*/
@JsonProperty
@Override
public int thresholdMillis() {
return thresholdMillis;
}
/**
* @return value of {@code minTransactionCount} attribute
*/
@JsonProperty
@Override
public int minTransactionCount() {
return minTransactionCount;
}
/**
* @return value of {@code emailAddresses} attribute
*/
@JsonProperty
@Override
public ImmutableList emailAddresses() {
return emailAddresses;
}
/**
* @return computed at construction value of {@code version} attribute
*/
@JsonProperty
@JsonIgnore
@Override
public String version() {
return version;
}
/**
* Copy current immutable object by setting value for {@link AlertConfig#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 ImmutableAlertConfig withTransactionType(String value) {
if (this.transactionType == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableAlertConfig(
newValue,
this.percentile,
this.timePeriodMinutes,
this.thresholdMillis,
this.minTransactionCount,
this.emailAddresses);
}
/**
* Copy current immutable object by setting value for {@link AlertConfig#percentile() percentile}.
* @param value new value for percentile
* @return modified copy of the {@code this} object
*/
public final ImmutableAlertConfig withPercentile(double value) {
double newValue = value;
return new ImmutableAlertConfig(
this.transactionType,
newValue,
this.timePeriodMinutes,
this.thresholdMillis,
this.minTransactionCount,
this.emailAddresses);
}
/**
* Copy current immutable object by setting value for {@link AlertConfig#timePeriodMinutes() timePeriodMinutes}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for timePeriodMinutes
* @return modified copy of the {@code this} object
*/
public final ImmutableAlertConfig withTimePeriodMinutes(int value) {
if (this.timePeriodMinutes == value) return this;
int newValue = value;
return new ImmutableAlertConfig(
this.transactionType,
this.percentile,
newValue,
this.thresholdMillis,
this.minTransactionCount,
this.emailAddresses);
}
/**
* Copy current immutable object by setting value for {@link AlertConfig#thresholdMillis() thresholdMillis}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for thresholdMillis
* @return modified copy of the {@code this} object
*/
public final ImmutableAlertConfig withThresholdMillis(int value) {
if (this.thresholdMillis == value) return this;
int newValue = value;
return new ImmutableAlertConfig(
this.transactionType,
this.percentile,
this.timePeriodMinutes,
newValue,
this.minTransactionCount,
this.emailAddresses);
}
/**
* Copy current immutable object by setting value for {@link AlertConfig#minTransactionCount() minTransactionCount}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for minTransactionCount
* @return modified copy of the {@code this} object
*/
public final ImmutableAlertConfig withMinTransactionCount(int value) {
if (this.minTransactionCount == value) return this;
int newValue = value;
return new ImmutableAlertConfig(
this.transactionType,
this.percentile,
this.timePeriodMinutes,
this.thresholdMillis,
newValue,
this.emailAddresses);
}
/**
* Copy current immutable object with elements that replace content of {@link AlertConfig#emailAddresses() emailAddresses}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAlertConfig withEmailAddresses(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAlertConfig(
this.transactionType,
this.percentile,
this.timePeriodMinutes,
this.thresholdMillis,
this.minTransactionCount,
newValue);
}
/**
* Copy current immutable object with elements that replace content of {@link AlertConfig#emailAddresses() emailAddresses}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of emailAddresses elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableAlertConfig withEmailAddresses(Iterable elements) {
if (this.emailAddresses == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAlertConfig(
this.transactionType,
this.percentile,
this.timePeriodMinutes,
this.thresholdMillis,
this.minTransactionCount,
newValue);
}
/**
* This instance is equal to instances of {@code ImmutableAlertConfig} 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 ImmutableAlertConfig
&& equalTo((ImmutableAlertConfig) another);
}
private boolean equalTo(ImmutableAlertConfig another) {
return transactionType.equals(another.transactionType)
&& Double.doubleToLongBits(percentile) == Double.doubleToLongBits(another.percentile)
&& timePeriodMinutes == another.timePeriodMinutes
&& thresholdMillis == another.thresholdMillis
&& minTransactionCount == another.minTransactionCount
&& emailAddresses.equals(another.emailAddresses)
&& version.equals(another.version);
}
/**
* Computes hash code from attributes: {@code transactionType}, {@code percentile}, {@code timePeriodMinutes}, {@code thresholdMillis}, {@code minTransactionCount}, {@code emailAddresses}, {@code version}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + transactionType.hashCode();
h = h * 17 + Doubles.hashCode(percentile);
h = h * 17 + timePeriodMinutes;
h = h * 17 + thresholdMillis;
h = h * 17 + minTransactionCount;
h = h * 17 + emailAddresses.hashCode();
h = h * 17 + version.hashCode();
return h;
}
/**
* Prints immutable value {@code AlertConfig...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("AlertConfig")
.add("transactionType", transactionType)
.add("percentile", percentile)
.add("timePeriodMinutes", timePeriodMinutes)
.add("thresholdMillis", thresholdMillis)
.add("minTransactionCount", minTransactionCount)
.add("emailAddresses", emailAddresses)
.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
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
@Nullable String transactionType;
@JsonProperty
@Nullable java.lang.Double percentile;
@JsonProperty
@Nullable Integer timePeriodMinutes;
@JsonProperty
@Nullable Integer thresholdMillis;
@JsonProperty
@Nullable Integer minTransactionCount;
@JsonProperty
@Nullable ImmutableList emailAddresses;
@JsonProperty
@JsonIgnore
@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 ImmutableAlertConfig fromJson(Json json) {
ImmutableAlertConfig.Builder builder = ImmutableAlertConfig.builder();
if (json.transactionType != null) {
builder.transactionType(json.transactionType);
}
if (json.percentile != null) {
builder.percentile(json.percentile);
}
if (json.timePeriodMinutes != null) {
builder.timePeriodMinutes(json.timePeriodMinutes);
}
if (json.thresholdMillis != null) {
builder.thresholdMillis(json.thresholdMillis);
}
if (json.minTransactionCount != null) {
builder.minTransactionCount(json.minTransactionCount);
}
if (json.emailAddresses != null) {
builder.addAllEmailAddresses(json.emailAddresses);
}
return builder.build();
}
/**
* Creates immutable copy of {@link AlertConfig}.
* 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 AlertConfig instance
*/
public static ImmutableAlertConfig copyOf(AlertConfig instance) {
if (instance instanceof ImmutableAlertConfig) {
return (ImmutableAlertConfig) instance;
}
return ImmutableAlertConfig.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.storage.repo.config.ImmutableAlertConfig ImmutableAlertConfig}.
* @return new ImmutableAlertConfig builder
*/
public static ImmutableAlertConfig.Builder builder() {
return new ImmutableAlertConfig.Builder();
}
/**
* Builds instances of {@link org.glowroot.storage.repo.config.ImmutableAlertConfig ImmutableAlertConfig}.
* 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
public static final class Builder {
private static final long INIT_BIT_TRANSACTION_TYPE = 0x1L;
private static final long INIT_BIT_PERCENTILE = 0x2L;
private static final long INIT_BIT_TIME_PERIOD_MINUTES = 0x4L;
private static final long INIT_BIT_THRESHOLD_MILLIS = 0x8L;
private static final long INIT_BIT_MIN_TRANSACTION_COUNT = 0x10L;
private long initBits = 0x1f;
private @Nullable String transactionType;
private double percentile;
private int timePeriodMinutes;
private int thresholdMillis;
private int minTransactionCount;
private ImmutableList.Builder emailAddressesBuilder = ImmutableList.builder();
private Builder() {}
/**
* Fill builder with attribute values from provided {@link AlertConfig} 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(AlertConfig instance) {
Preconditions.checkNotNull(instance);
transactionType(instance.transactionType());
percentile(instance.percentile());
timePeriodMinutes(instance.timePeriodMinutes());
thresholdMillis(instance.thresholdMillis());
minTransactionCount(instance.minTransactionCount());
addAllEmailAddresses(instance.emailAddresses());
return this;
}
/**
* Initializes value for {@link AlertConfig#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 AlertConfig#percentile() percentile}.
* @param percentile value for percentile
* @return {@code this} builder for chained invocation
*/
public final Builder percentile(double percentile) {
this.percentile = percentile;
initBits &= ~INIT_BIT_PERCENTILE;
return this;
}
/**
* Initializes value for {@link AlertConfig#timePeriodMinutes() timePeriodMinutes}.
* @param timePeriodMinutes value for timePeriodMinutes
* @return {@code this} builder for chained invocation
*/
public final Builder timePeriodMinutes(int timePeriodMinutes) {
this.timePeriodMinutes = timePeriodMinutes;
initBits &= ~INIT_BIT_TIME_PERIOD_MINUTES;
return this;
}
/**
* Initializes value for {@link AlertConfig#thresholdMillis() thresholdMillis}.
* @param thresholdMillis value for thresholdMillis
* @return {@code this} builder for chained invocation
*/
public final Builder thresholdMillis(int thresholdMillis) {
this.thresholdMillis = thresholdMillis;
initBits &= ~INIT_BIT_THRESHOLD_MILLIS;
return this;
}
/**
* Initializes value for {@link AlertConfig#minTransactionCount() minTransactionCount}.
* @param minTransactionCount value for minTransactionCount
* @return {@code this} builder for chained invocation
*/
public final Builder minTransactionCount(int minTransactionCount) {
this.minTransactionCount = minTransactionCount;
initBits &= ~INIT_BIT_MIN_TRANSACTION_COUNT;
return this;
}
/**
* Adds one element to {@link AlertConfig#emailAddresses() emailAddresses} list.
* @param element emailAddresses element
* @return {@code this} builder for chained invocation
*/
public final Builder addEmailAddresses(String element) {
emailAddressesBuilder.add(element);
return this;
}
/**
* Adds elements to {@link AlertConfig#emailAddresses() emailAddresses} list.
* @param elements array of emailAddresses elements
* @return {@code this} builder for chained invocation
*/
public final Builder addEmailAddresses(String... elements) {
emailAddressesBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link AlertConfig#emailAddresses() emailAddresses} list.
* @param elements iterable of emailAddresses elements
* @return {@code this} builder for chained invocation
*/
public final Builder emailAddresses(Iterable elements) {
emailAddressesBuilder = ImmutableList.builder();
return addAllEmailAddresses(elements);
}
/**
* Adds elements to {@link AlertConfig#emailAddresses() emailAddresses} list.
* @param elements iterable of emailAddresses elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllEmailAddresses(Iterable elements) {
emailAddressesBuilder.addAll(elements);
return this;
}
/**
* Builds new {@link org.glowroot.storage.repo.config.ImmutableAlertConfig ImmutableAlertConfig}.
* @return immutable instance of AlertConfig
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableAlertConfig build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableAlertConfig(
transactionType,
percentile,
timePeriodMinutes,
thresholdMillis,
minTransactionCount,
emailAddressesBuilder.build());
}
private boolean transactionTypeIsSet() {
return (initBits & INIT_BIT_TRANSACTION_TYPE) == 0;
}
private boolean percentileIsSet() {
return (initBits & INIT_BIT_PERCENTILE) == 0;
}
private boolean timePeriodMinutesIsSet() {
return (initBits & INIT_BIT_TIME_PERIOD_MINUTES) == 0;
}
private boolean thresholdMillisIsSet() {
return (initBits & INIT_BIT_THRESHOLD_MILLIS) == 0;
}
private boolean minTransactionCountIsSet() {
return (initBits & INIT_BIT_MIN_TRANSACTION_COUNT) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!transactionTypeIsSet()) attributes.add("transactionType");
if (!percentileIsSet()) attributes.add("percentile");
if (!timePeriodMinutesIsSet()) attributes.add("timePeriodMinutes");
if (!thresholdMillisIsSet()) attributes.add("thresholdMillis");
if (!minTransactionCountIsSet()) attributes.add("minTransactionCount");
return "Cannot build AlertConfig, some of required attributes are not set " + attributes;
}
}
}