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

org.glowroot.local.ui.AlertConfigDto Maven / Gradle / Ivy

The newest version!
package org.glowroot.local.ui;

import org.glowroot.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.shaded.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.shaded.google.common.base.MoreObjects;
import org.glowroot.shaded.google.common.base.Objects;
import org.glowroot.shaded.google.common.base.Preconditions;
import org.glowroot.shaded.google.common.collect.ImmutableList;
import org.glowroot.shaded.google.common.collect.Lists;
import org.glowroot.shaded.google.common.primitives.Doubles;
import java.util.Collection;
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 AlertJsonService.AlertConfigDtoBase}.
 * 

* Use builder to create immutable instances: * {@code AlertConfigDto.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "AlertJsonService.AlertConfigDtoBase"}) @Immutable final class AlertConfigDto extends AlertJsonService.AlertConfigDtoBase { 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 @Nullable String version; private AlertConfigDto( String transactionType, double percentile, int timePeriodMinutes, int thresholdMillis, int minTransactionCount, ImmutableList emailAddresses, @Nullable String version) { this.transactionType = transactionType; this.percentile = percentile; this.timePeriodMinutes = timePeriodMinutes; this.thresholdMillis = thresholdMillis; this.minTransactionCount = minTransactionCount; this.emailAddresses = emailAddresses; this.version = version; } /** * {@inheritDoc} * @return value of {@code transactionType} attribute */ @JsonProperty("transactionType") @Override public String transactionType() { return transactionType; } /** * {@inheritDoc} * @return value of {@code percentile} attribute */ @JsonProperty("percentile") @Override public double percentile() { return percentile; } /** * {@inheritDoc} * @return value of {@code timePeriodMinutes} attribute */ @JsonProperty("timePeriodMinutes") @Override public int timePeriodMinutes() { return timePeriodMinutes; } /** * {@inheritDoc} * @return value of {@code thresholdMillis} attribute */ @JsonProperty("thresholdMillis") @Override public int thresholdMillis() { return thresholdMillis; } /** * {@inheritDoc} * @return value of {@code minTransactionCount} attribute */ @JsonProperty("minTransactionCount") @Override public int minTransactionCount() { return minTransactionCount; } /** * {@inheritDoc} * @return value of {@code emailAddresses} attribute */ @JsonProperty("emailAddresses") @Override public ImmutableList emailAddresses() { return emailAddresses; } /** * {@inheritDoc} * @return value of {@code version} attribute */ @JsonProperty("version") @Override public String version() { return version; } /** * Copy current immutable object by setting value for {@link AlertJsonService.AlertConfigDtoBase#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 AlertConfigDto withTransactionType(String value) { if (this.transactionType == value) { return this; } String newValue = Preconditions.checkNotNull(value); return new AlertConfigDto( newValue, this.percentile, this.timePeriodMinutes, this.thresholdMillis, this.minTransactionCount, this.emailAddresses, this.version); } /** * Copy current immutable object by setting value for {@link AlertJsonService.AlertConfigDtoBase#percentile() percentile}. * @param value new value for percentile * @return modified copy of the {@code this} object */ public final AlertConfigDto withPercentile(double value) { double newValue = value; return new AlertConfigDto( this.transactionType, newValue, this.timePeriodMinutes, this.thresholdMillis, this.minTransactionCount, this.emailAddresses, this.version); } /** * Copy current immutable object by setting value for {@link AlertJsonService.AlertConfigDtoBase#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 AlertConfigDto withTimePeriodMinutes(int value) { if (this.timePeriodMinutes == value) { return this; } int newValue = value; return new AlertConfigDto( this.transactionType, this.percentile, newValue, this.thresholdMillis, this.minTransactionCount, this.emailAddresses, this.version); } /** * Copy current immutable object by setting value for {@link AlertJsonService.AlertConfigDtoBase#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 AlertConfigDto withThresholdMillis(int value) { if (this.thresholdMillis == value) { return this; } int newValue = value; return new AlertConfigDto( this.transactionType, this.percentile, this.timePeriodMinutes, newValue, this.minTransactionCount, this.emailAddresses, this.version); } /** * Copy current immutable object by setting value for {@link AlertJsonService.AlertConfigDtoBase#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 AlertConfigDto withMinTransactionCount(int value) { if (this.minTransactionCount == value) { return this; } int newValue = value; return new AlertConfigDto( this.transactionType, this.percentile, this.timePeriodMinutes, this.thresholdMillis, newValue, this.emailAddresses, this.version); } /** * Copy current immutable object with elements that replace content of {@link AlertJsonService.AlertConfigDtoBase#emailAddresses() emailAddresses}. * @param elements elements to set * @return modified copy of {@code this} object */ public final AlertConfigDto withEmailAddresses(String... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new AlertConfigDto( this.transactionType, this.percentile, this.timePeriodMinutes, this.thresholdMillis, this.minTransactionCount, newValue, this.version); } /** * Copy current immutable object with elements that replace content of {@link AlertJsonService.AlertConfigDtoBase#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 AlertConfigDto withEmailAddresses(Iterable elements) { if (this.emailAddresses == elements) { return this; } ImmutableList newValue = ImmutableList.copyOf(elements); return new AlertConfigDto( this.transactionType, this.percentile, this.timePeriodMinutes, this.thresholdMillis, this.minTransactionCount, newValue, this.version); } /** * Copy current immutable object by setting value for {@link AlertJsonService.AlertConfigDtoBase#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, can be {@code null} * @return modified copy of the {@code this} object */ public final AlertConfigDto withVersion(@Nullable String value) { if (this.version == value) { return this; } @Nullable String newValue = value; return new AlertConfigDto( this.transactionType, this.percentile, this.timePeriodMinutes, this.thresholdMillis, this.minTransactionCount, this.emailAddresses, newValue); } /** * This instance is equal to instances of {@code AlertConfigDto} with equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { return this == another || (another instanceof AlertConfigDto && equalTo((AlertConfigDto) another)); } private boolean equalTo(AlertConfigDto 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) && Objects.equal(version, 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 + Objects.hashCode(version); return h; } /** * Prints immutable value {@code AlertConfigDto{...}} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("AlertConfigDto") .add("transactionType", transactionType) .add("percentile", percentile) .add("timePeriodMinutes", timePeriodMinutes) .add("thresholdMillis", thresholdMillis) .add("minTransactionCount", minTransactionCount) .add("emailAddresses", emailAddresses) .add("version", version) .toString(); } @JsonCreator public static AlertConfigDto fromAllAttributes( @JsonProperty("transactionType") @Nullable String transactionType, @JsonProperty("percentile") @Nullable java.lang.Double percentile, @JsonProperty("timePeriodMinutes") @Nullable Integer timePeriodMinutes, @JsonProperty("thresholdMillis") @Nullable Integer thresholdMillis, @JsonProperty("minTransactionCount") @Nullable Integer minTransactionCount, @JsonProperty("emailAddresses") @Nullable ImmutableList emailAddresses, @JsonProperty("version") @Nullable String version) { AlertConfigDto.Builder builder = AlertConfigDto.builder(); if (transactionType != null) { builder.transactionType(transactionType); } if (percentile != null) { builder.percentile(percentile); } if (timePeriodMinutes != null) { builder.timePeriodMinutes(timePeriodMinutes); } if (thresholdMillis != null) { builder.thresholdMillis(thresholdMillis); } if (minTransactionCount != null) { builder.minTransactionCount(minTransactionCount); } if (emailAddresses != null) { builder.addAllEmailAddresses(emailAddresses); } if (version != null) { builder.version(version); } return builder.build(); } /** * Creates immutable copy of {@link AlertJsonService.AlertConfigDtoBase}. * 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 AlertConfigDto instance */ static AlertConfigDto copyOf(AlertJsonService.AlertConfigDtoBase instance) { if (instance instanceof AlertConfigDto) { return (AlertConfigDto) instance; } return AlertConfigDto.builder() .transactionType(instance.transactionType()) .percentile(instance.percentile()) .timePeriodMinutes(instance.timePeriodMinutes()) .thresholdMillis(instance.thresholdMillis()) .minTransactionCount(instance.minTransactionCount()) .addAllEmailAddresses(instance.emailAddresses()) .version(instance.version()) .build(); } /** * Creates builder for {@link org.glowroot.local.ui.AlertConfigDto}. * @return new AlertConfigDto builder */ static AlertConfigDto.Builder builder() { return new AlertConfigDto.Builder(); } /** * Builds instances of {@link org.glowroot.local.ui.AlertConfigDto}. * Initialized attributes and then invoke {@link #build()} method to create * immutable instance. *

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 INITIALIZED_BITSET_ALL = 0x1f; private static final long INITIALIZED_BIT_TRANSACTION_TYPE = 0x1L; private static final long INITIALIZED_BIT_PERCENTILE = 0x2L; private static final long INITIALIZED_BIT_TIME_PERIOD_MINUTES = 0x4L; private static final long INITIALIZED_BIT_THRESHOLD_MILLIS = 0x8L; private static final long INITIALIZED_BIT_MIN_TRANSACTION_COUNT = 0x10L; private static final long NONDEFAULT_BIT_VERSION = 0x1L; private long initializedBitset; private long nondefaultBitset; private @Nullable String transactionType; private double percentile; private int timePeriodMinutes; private int thresholdMillis; private int minTransactionCount; private ImmutableList.Builder emailAddressesBuilder = ImmutableList.builder(); private @Nullable String version; private Builder() {} /** * Initializes value for {@link AlertJsonService.AlertConfigDtoBase#transactionType() transactionType}. * @param transactionType value for transactionType * @return {@code this} builder for chained invocation */ public final Builder transactionType(String transactionType) { checkNotIsSet(transactionTypeIsSet(), "transactionType"); this.transactionType = Preconditions.checkNotNull(transactionType); initializedBitset |= INITIALIZED_BIT_TRANSACTION_TYPE; return this; } /** * Initializes value for {@link AlertJsonService.AlertConfigDtoBase#percentile() percentile}. * @param percentile value for percentile * @return {@code this} builder for chained invocation */ public final Builder percentile(double percentile) { checkNotIsSet(percentileIsSet(), "percentile"); this.percentile = percentile; initializedBitset |= INITIALIZED_BIT_PERCENTILE; return this; } /** * Initializes value for {@link AlertJsonService.AlertConfigDtoBase#timePeriodMinutes() timePeriodMinutes}. * @param timePeriodMinutes value for timePeriodMinutes * @return {@code this} builder for chained invocation */ public final Builder timePeriodMinutes(int timePeriodMinutes) { checkNotIsSet(timePeriodMinutesIsSet(), "timePeriodMinutes"); this.timePeriodMinutes = timePeriodMinutes; initializedBitset |= INITIALIZED_BIT_TIME_PERIOD_MINUTES; return this; } /** * Initializes value for {@link AlertJsonService.AlertConfigDtoBase#thresholdMillis() thresholdMillis}. * @param thresholdMillis value for thresholdMillis * @return {@code this} builder for chained invocation */ public final Builder thresholdMillis(int thresholdMillis) { checkNotIsSet(thresholdMillisIsSet(), "thresholdMillis"); this.thresholdMillis = thresholdMillis; initializedBitset |= INITIALIZED_BIT_THRESHOLD_MILLIS; return this; } /** * Initializes value for {@link AlertJsonService.AlertConfigDtoBase#minTransactionCount() minTransactionCount}. * @param minTransactionCount value for minTransactionCount * @return {@code this} builder for chained invocation */ public final Builder minTransactionCount(int minTransactionCount) { checkNotIsSet(minTransactionCountIsSet(), "minTransactionCount"); this.minTransactionCount = minTransactionCount; initializedBitset |= INITIALIZED_BIT_MIN_TRANSACTION_COUNT; return this; } /** * Adds one element to {@link AlertJsonService.AlertConfigDtoBase#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 AlertJsonService.AlertConfigDtoBase#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; } /** * Adds elements to {@link AlertJsonService.AlertConfigDtoBase#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; } /** * Initializes value for {@link AlertJsonService.AlertConfigDtoBase#version() version}. * @param version value for version, can be {@code null} * @return {@code this} builder for chained invocation */ public final Builder version(@Nullable String version) { checkNotIsSet(versionIsSet(), "version"); this.version = version; nondefaultBitset |= NONDEFAULT_BIT_VERSION; return this; } /** * Builds new {@link org.glowroot.local.ui.AlertConfigDto}. * @return immutable instance of AlertConfigDto */ public org.glowroot.local.ui.AlertConfigDto build() { checkRequiredAttributes(); return new AlertConfigDto( transactionType, percentile, timePeriodMinutes, thresholdMillis, minTransactionCount, emailAddressesBuilder.build(), version); } private boolean versionIsSet() { return (nondefaultBitset & NONDEFAULT_BIT_VERSION) != 0; } private boolean transactionTypeIsSet() { return (initializedBitset & INITIALIZED_BIT_TRANSACTION_TYPE) != 0; } private boolean percentileIsSet() { return (initializedBitset & INITIALIZED_BIT_PERCENTILE) != 0; } private boolean timePeriodMinutesIsSet() { return (initializedBitset & INITIALIZED_BIT_TIME_PERIOD_MINUTES) != 0; } private boolean thresholdMillisIsSet() { return (initializedBitset & INITIALIZED_BIT_THRESHOLD_MILLIS) != 0; } private boolean minTransactionCountIsSet() { return (initializedBitset & INITIALIZED_BIT_MIN_TRANSACTION_COUNT) != 0; } private void checkNotIsSet(boolean isSet, String name) { if (isSet) { throw new IllegalStateException("Builder of AlertConfigDto is strict, attribute is already set: ".concat(name)); } } private void checkRequiredAttributes() { if (initializedBitset != INITIALIZED_BITSET_ALL) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { Collection 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 AlertConfigDto, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy