All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.glowroot.agent.config.ImmutableAlertConfig Maven / Gradle / Ivy

There is a newer version: 0.9.24
Show newest version
package org.glowroot.agent.config;

import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
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.Objects;
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 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;
import org.glowroot.agent.shaded.glowroot.wire.api.model.AgentConfigOuterClass;

/**
 * Immutable implementation of {@link AlertConfig}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableAlertConfig.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "AlertConfig"}) @Immutable public final class ImmutableAlertConfig extends AlertConfig { private final AgentConfigOuterClass.AgentConfig.AlertConfig.AlertKind kind; private final @Nullable String transactionType; private final @Nullable Double transactionPercentile; private final @Nullable Integer transactionThresholdMillis; private final @Nullable Integer minTransactionCount; private final @Nullable String gaugeName; private final @Nullable Double gaugeThreshold; private final int timePeriodSeconds; private final ImmutableList emailAddresses; private ImmutableAlertConfig( AgentConfigOuterClass.AgentConfig.AlertConfig.AlertKind kind, @Nullable String transactionType, @Nullable Double transactionPercentile, @Nullable Integer transactionThresholdMillis, @Nullable Integer minTransactionCount, @Nullable String gaugeName, @Nullable Double gaugeThreshold, int timePeriodSeconds, ImmutableList emailAddresses) { this.kind = kind; this.transactionType = transactionType; this.transactionPercentile = transactionPercentile; this.transactionThresholdMillis = transactionThresholdMillis; this.minTransactionCount = minTransactionCount; this.gaugeName = gaugeName; this.gaugeThreshold = gaugeThreshold; this.timePeriodSeconds = timePeriodSeconds; this.emailAddresses = emailAddresses; } /** * @return The value of the {@code kind} attribute */ @JsonProperty @Override public AgentConfigOuterClass.AgentConfig.AlertConfig.AlertKind kind() { return kind; } /** * @return The value of the {@code transactionType} attribute */ @JsonProperty @Override public @Nullable String transactionType() { return transactionType; } /** * @return The value of the {@code transactionPercentile} attribute */ @JsonProperty @Override public @Nullable Double transactionPercentile() { return transactionPercentile; } /** * @return The value of the {@code transactionThresholdMillis} attribute */ @JsonProperty @Override public @Nullable Integer transactionThresholdMillis() { return transactionThresholdMillis; } /** * @return The value of the {@code minTransactionCount} attribute */ @JsonProperty @Override public @Nullable Integer minTransactionCount() { return minTransactionCount; } /** * @return The value of the {@code gaugeName} attribute */ @JsonProperty @JsonInclude(value = JsonInclude.Include.NON_EMPTY) @Override public @Nullable String gaugeName() { return gaugeName; } /** * @return The value of the {@code gaugeThreshold} attribute */ @JsonProperty @Override public @Nullable Double gaugeThreshold() { return gaugeThreshold; } /** * @return The value of the {@code timePeriodSeconds} attribute */ @JsonProperty @Override public int timePeriodSeconds() { return timePeriodSeconds; } /** * @return The value of the {@code emailAddresses} attribute */ @JsonProperty @Override public ImmutableList emailAddresses() { return emailAddresses; } /** * Copy the current immutable object by setting a value for the {@link AlertConfig#kind() kind} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for kind * @return A modified copy of the {@code this} object */ public final ImmutableAlertConfig withKind(AgentConfigOuterClass.AgentConfig.AlertConfig.AlertKind value) { if (this.kind == value) return this; return new ImmutableAlertConfig( Preconditions.checkNotNull(value, "kind"), this.transactionType, this.transactionPercentile, this.transactionThresholdMillis, this.minTransactionCount, this.gaugeName, this.gaugeThreshold, this.timePeriodSeconds, this.emailAddresses); } /** * Copy the current immutable object by setting a value for the {@link AlertConfig#transactionType() transactionType} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for transactionType (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableAlertConfig withTransactionType(@Nullable String value) { if (Objects.equal(this.transactionType, value)) return this; return new ImmutableAlertConfig( this.kind, value, this.transactionPercentile, this.transactionThresholdMillis, this.minTransactionCount, this.gaugeName, this.gaugeThreshold, this.timePeriodSeconds, this.emailAddresses); } /** * Copy the current immutable object by setting a value for the {@link AlertConfig#transactionPercentile() transactionPercentile} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for transactionPercentile (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableAlertConfig withTransactionPercentile(@Nullable Double value) { if (Objects.equal(this.transactionPercentile, value)) return this; return new ImmutableAlertConfig( this.kind, this.transactionType, value, this.transactionThresholdMillis, this.minTransactionCount, this.gaugeName, this.gaugeThreshold, this.timePeriodSeconds, this.emailAddresses); } /** * Copy the current immutable object by setting a value for the {@link AlertConfig#transactionThresholdMillis() transactionThresholdMillis} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for transactionThresholdMillis (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableAlertConfig withTransactionThresholdMillis(@Nullable Integer value) { if (Objects.equal(this.transactionThresholdMillis, value)) return this; return new ImmutableAlertConfig( this.kind, this.transactionType, this.transactionPercentile, value, this.minTransactionCount, this.gaugeName, this.gaugeThreshold, this.timePeriodSeconds, this.emailAddresses); } /** * Copy the current immutable object by setting a value for the {@link AlertConfig#minTransactionCount() minTransactionCount} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for minTransactionCount (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableAlertConfig withMinTransactionCount(@Nullable Integer value) { if (Objects.equal(this.minTransactionCount, value)) return this; return new ImmutableAlertConfig( this.kind, this.transactionType, this.transactionPercentile, this.transactionThresholdMillis, value, this.gaugeName, this.gaugeThreshold, this.timePeriodSeconds, this.emailAddresses); } /** * Copy the current immutable object by setting a value for the {@link AlertConfig#gaugeName() gaugeName} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for gaugeName (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableAlertConfig withGaugeName(@Nullable String value) { if (Objects.equal(this.gaugeName, value)) return this; return new ImmutableAlertConfig( this.kind, this.transactionType, this.transactionPercentile, this.transactionThresholdMillis, this.minTransactionCount, value, this.gaugeThreshold, this.timePeriodSeconds, this.emailAddresses); } /** * Copy the current immutable object by setting a value for the {@link AlertConfig#gaugeThreshold() gaugeThreshold} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for gaugeThreshold (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableAlertConfig withGaugeThreshold(@Nullable Double value) { if (Objects.equal(this.gaugeThreshold, value)) return this; return new ImmutableAlertConfig( this.kind, this.transactionType, this.transactionPercentile, this.transactionThresholdMillis, this.minTransactionCount, this.gaugeName, value, this.timePeriodSeconds, this.emailAddresses); } /** * Copy the current immutable object by setting a value for the {@link AlertConfig#timePeriodSeconds() timePeriodSeconds} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for timePeriodSeconds * @return A modified copy of the {@code this} object */ public final ImmutableAlertConfig withTimePeriodSeconds(int value) { if (this.timePeriodSeconds == value) return this; return new ImmutableAlertConfig( this.kind, this.transactionType, this.transactionPercentile, this.transactionThresholdMillis, this.minTransactionCount, this.gaugeName, this.gaugeThreshold, value, this.emailAddresses); } /** * Copy the current immutable object with elements that replace the content of {@link AlertConfig#emailAddresses() emailAddresses}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableAlertConfig withEmailAddresses(String... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableAlertConfig( this.kind, this.transactionType, this.transactionPercentile, this.transactionThresholdMillis, this.minTransactionCount, this.gaugeName, this.gaugeThreshold, this.timePeriodSeconds, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link AlertConfig#emailAddresses() emailAddresses}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of emailAddresses elements to set * @return A 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.kind, this.transactionType, this.transactionPercentile, this.transactionThresholdMillis, this.minTransactionCount, this.gaugeName, this.gaugeThreshold, this.timePeriodSeconds, newValue); } /** * This instance is equal to all instances of {@code ImmutableAlertConfig} that have 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 kind.equals(another.kind) && Objects.equal(transactionType, another.transactionType) && Objects.equal(transactionPercentile, another.transactionPercentile) && Objects.equal(transactionThresholdMillis, another.transactionThresholdMillis) && Objects.equal(minTransactionCount, another.minTransactionCount) && Objects.equal(gaugeName, another.gaugeName) && Objects.equal(gaugeThreshold, another.gaugeThreshold) && timePeriodSeconds == another.timePeriodSeconds && emailAddresses.equals(another.emailAddresses); } /** * Computes a hash code from attributes: {@code kind}, {@code transactionType}, {@code transactionPercentile}, {@code transactionThresholdMillis}, {@code minTransactionCount}, {@code gaugeName}, {@code gaugeThreshold}, {@code timePeriodSeconds}, {@code emailAddresses}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + kind.hashCode(); h = h * 17 + Objects.hashCode(transactionType); h = h * 17 + Objects.hashCode(transactionPercentile); h = h * 17 + Objects.hashCode(transactionThresholdMillis); h = h * 17 + Objects.hashCode(minTransactionCount); h = h * 17 + Objects.hashCode(gaugeName); h = h * 17 + Objects.hashCode(gaugeThreshold); h = h * 17 + timePeriodSeconds; h = h * 17 + emailAddresses.hashCode(); return h; } /** * Prints the immutable value {@code AlertConfig...} with all non-generated * and non-auxiliary attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("AlertConfig") .add("kind", kind) .add("transactionType", transactionType) .add("transactionPercentile", transactionPercentile) .add("transactionThresholdMillis", transactionThresholdMillis) .add("minTransactionCount", minTransactionCount) .add("gaugeName", gaugeName) .add("gaugeThreshold", gaugeThreshold) .add("timePeriodSeconds", timePeriodSeconds) .add("emailAddresses", emailAddresses) .toString(); } /** * Utility type used to correctly read immutable object from JSON representation. * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure */ @Deprecated static final class Json extends AlertConfig { @Nullable AgentConfigOuterClass.AgentConfig.AlertConfig.AlertKind kind; @Nullable String transactionType; @Nullable Double transactionPercentile; @Nullable Integer transactionThresholdMillis; @Nullable Integer minTransactionCount; @Nullable String gaugeName; @Nullable Double gaugeThreshold; @Nullable Integer timePeriodSeconds; ImmutableList emailAddresses = ImmutableList.of(); @JsonProperty public void setKind(AgentConfigOuterClass.AgentConfig.AlertConfig.AlertKind kind) { this.kind = kind; } @JsonProperty public void setTransactionType(@Nullable String transactionType) { this.transactionType = transactionType; } @JsonProperty public void setTransactionPercentile(@Nullable Double transactionPercentile) { this.transactionPercentile = transactionPercentile; } @JsonProperty public void setTransactionThresholdMillis(@Nullable Integer transactionThresholdMillis) { this.transactionThresholdMillis = transactionThresholdMillis; } @JsonProperty public void setMinTransactionCount(@Nullable Integer minTransactionCount) { this.minTransactionCount = minTransactionCount; } @JsonProperty @JsonInclude(value = JsonInclude.Include.NON_EMPTY) public void setGaugeName(@Nullable String gaugeName) { this.gaugeName = gaugeName; } @JsonProperty public void setGaugeThreshold(@Nullable Double gaugeThreshold) { this.gaugeThreshold = gaugeThreshold; } @JsonProperty public void setTimePeriodSeconds(int timePeriodSeconds) { this.timePeriodSeconds = timePeriodSeconds; } @JsonProperty public void setEmailAddresses(ImmutableList emailAddresses) { this.emailAddresses = emailAddresses; } @Override public AgentConfigOuterClass.AgentConfig.AlertConfig.AlertKind kind() { throw new UnsupportedOperationException(); } @Override public String transactionType() { throw new UnsupportedOperationException(); } @Override public Double transactionPercentile() { throw new UnsupportedOperationException(); } @Override public Integer transactionThresholdMillis() { throw new UnsupportedOperationException(); } @Override public Integer minTransactionCount() { throw new UnsupportedOperationException(); } @Override public String gaugeName() { throw new UnsupportedOperationException(); } @Override public Double gaugeThreshold() { throw new UnsupportedOperationException(); } @Override public int timePeriodSeconds() { throw new UnsupportedOperationException(); } @Override public ImmutableList emailAddresses() { throw new UnsupportedOperationException(); } } /** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonCreator static ImmutableAlertConfig fromJson(Json json) { ImmutableAlertConfig.Builder builder = ImmutableAlertConfig.builder(); if (json.kind != null) { builder.kind(json.kind); } if (json.transactionType != null) { builder.transactionType(json.transactionType); } if (json.transactionPercentile != null) { builder.transactionPercentile(json.transactionPercentile); } if (json.transactionThresholdMillis != null) { builder.transactionThresholdMillis(json.transactionThresholdMillis); } if (json.minTransactionCount != null) { builder.minTransactionCount(json.minTransactionCount); } if (json.gaugeName != null) { builder.gaugeName(json.gaugeName); } if (json.gaugeThreshold != null) { builder.gaugeThreshold(json.gaugeThreshold); } if (json.timePeriodSeconds != null) { builder.timePeriodSeconds(json.timePeriodSeconds); } if (json.emailAddresses != null) { builder.addAllEmailAddresses(json.emailAddresses); } return builder.build(); } /** * Creates an immutable copy of a {@link AlertConfig} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable AlertConfig instance */ public static ImmutableAlertConfig copyOf(AlertConfig instance) { if (instance instanceof ImmutableAlertConfig) { return (ImmutableAlertConfig) instance; } return ImmutableAlertConfig.builder() .copyFrom(instance) .build(); } /** * Creates a builder for {@link ImmutableAlertConfig ImmutableAlertConfig}. * @return A new ImmutableAlertConfig builder */ public static ImmutableAlertConfig.Builder builder() { return new ImmutableAlertConfig.Builder(); } /** * Builds instances of type {@link ImmutableAlertConfig ImmutableAlertConfig}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @NotThreadSafe public static final class Builder { private static final long INIT_BIT_KIND = 0x1L; private static final long INIT_BIT_TIME_PERIOD_SECONDS = 0x2L; private long initBits = 0x3; private @Nullable AgentConfigOuterClass.AgentConfig.AlertConfig.AlertKind kind; private @Nullable String transactionType; private @Nullable Double transactionPercentile; private @Nullable Integer transactionThresholdMillis; private @Nullable Integer minTransactionCount; private @Nullable String gaugeName; private @Nullable Double gaugeThreshold; private int timePeriodSeconds; private ImmutableList.Builder emailAddressesBuilder = ImmutableList.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code AlertConfig} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder copyFrom(AlertConfig instance) { Preconditions.checkNotNull(instance, "instance"); kind(instance.kind()); @Nullable String transactionTypeValue = instance.transactionType(); if (transactionTypeValue != null) { transactionType(transactionTypeValue); } @Nullable Double transactionPercentileValue = instance.transactionPercentile(); if (transactionPercentileValue != null) { transactionPercentile(transactionPercentileValue); } @Nullable Integer transactionThresholdMillisValue = instance.transactionThresholdMillis(); if (transactionThresholdMillisValue != null) { transactionThresholdMillis(transactionThresholdMillisValue); } @Nullable Integer minTransactionCountValue = instance.minTransactionCount(); if (minTransactionCountValue != null) { minTransactionCount(minTransactionCountValue); } @Nullable String gaugeNameValue = instance.gaugeName(); if (gaugeNameValue != null) { gaugeName(gaugeNameValue); } @Nullable Double gaugeThresholdValue = instance.gaugeThreshold(); if (gaugeThresholdValue != null) { gaugeThreshold(gaugeThresholdValue); } timePeriodSeconds(instance.timePeriodSeconds()); addAllEmailAddresses(instance.emailAddresses()); return this; } /** * Initializes the value for the {@link AlertConfig#kind() kind} attribute. * @param kind The value for kind * @return {@code this} builder for use in a chained invocation */ public final Builder kind(AgentConfigOuterClass.AgentConfig.AlertConfig.AlertKind kind) { this.kind = Preconditions.checkNotNull(kind, "kind"); initBits &= ~INIT_BIT_KIND; return this; } /** * Initializes the value for the {@link AlertConfig#transactionType() transactionType} attribute. * @param transactionType The value for transactionType (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ public final Builder transactionType(@Nullable String transactionType) { this.transactionType = transactionType; return this; } /** * Initializes the value for the {@link AlertConfig#transactionPercentile() transactionPercentile} attribute. * @param transactionPercentile The value for transactionPercentile (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ public final Builder transactionPercentile(@Nullable Double transactionPercentile) { this.transactionPercentile = transactionPercentile; return this; } /** * Initializes the value for the {@link AlertConfig#transactionThresholdMillis() transactionThresholdMillis} attribute. * @param transactionThresholdMillis The value for transactionThresholdMillis (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ public final Builder transactionThresholdMillis(@Nullable Integer transactionThresholdMillis) { this.transactionThresholdMillis = transactionThresholdMillis; return this; } /** * Initializes the value for the {@link AlertConfig#minTransactionCount() minTransactionCount} attribute. * @param minTransactionCount The value for minTransactionCount (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ public final Builder minTransactionCount(@Nullable Integer minTransactionCount) { this.minTransactionCount = minTransactionCount; return this; } /** * Initializes the value for the {@link AlertConfig#gaugeName() gaugeName} attribute. * @param gaugeName The value for gaugeName (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ public final Builder gaugeName(@Nullable String gaugeName) { this.gaugeName = gaugeName; return this; } /** * Initializes the value for the {@link AlertConfig#gaugeThreshold() gaugeThreshold} attribute. * @param gaugeThreshold The value for gaugeThreshold (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ public final Builder gaugeThreshold(@Nullable Double gaugeThreshold) { this.gaugeThreshold = gaugeThreshold; return this; } /** * Initializes the value for the {@link AlertConfig#timePeriodSeconds() timePeriodSeconds} attribute. * @param timePeriodSeconds The value for timePeriodSeconds * @return {@code this} builder for use in a chained invocation */ public final Builder timePeriodSeconds(int timePeriodSeconds) { this.timePeriodSeconds = timePeriodSeconds; initBits &= ~INIT_BIT_TIME_PERIOD_SECONDS; return this; } /** * Adds one element to {@link AlertConfig#emailAddresses() emailAddresses} list. * @param element A emailAddresses element * @return {@code this} builder for use in a chained invocation */ public final Builder addEmailAddresses(String element) { emailAddressesBuilder.add(element); return this; } /** * Adds elements to {@link AlertConfig#emailAddresses() emailAddresses} list. * @param elements An array of emailAddresses elements * @return {@code this} builder for use in a 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 An iterable of emailAddresses elements * @return {@code this} builder for use in a chained invocation */ public final Builder emailAddresses(Iterable elements) { emailAddressesBuilder = ImmutableList.builder(); return addAllEmailAddresses(elements); } /** * Adds elements to {@link AlertConfig#emailAddresses() emailAddresses} list. * @param elements An iterable of emailAddresses elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllEmailAddresses(Iterable elements) { emailAddressesBuilder.addAll(elements); return this; } /** * Builds a new {@link ImmutableAlertConfig ImmutableAlertConfig}. * @return An immutable instance of AlertConfig * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableAlertConfig build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableAlertConfig( kind, transactionType, transactionPercentile, transactionThresholdMillis, minTransactionCount, gaugeName, gaugeThreshold, timePeriodSeconds, emailAddressesBuilder.build()); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_KIND) != 0) attributes.add("kind"); if ((initBits & INIT_BIT_TIME_PERIOD_SECONDS) != 0) attributes.add("timePeriodSeconds"); return "Cannot build AlertConfig, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy