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

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

There is a newer version: 0.14.0-beta.3
Show newest version
package org.glowroot.agent.config;

import org.glowroot.agent.shaded.com.fasterxml.jackson.annotation.JsonAutoDetect;
import org.glowroot.agent.shaded.com.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.agent.shaded.com.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.com.google.common.base.MoreObjects;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.com.google.common.base.Preconditions;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.com.google.common.collect.ImmutableList;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.com.google.common.collect.Lists;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.com.google.common.primitives.Doubles;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.ArrayList;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.javax.annotation.CheckReturnValue;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.javax.annotation.Generated;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.javax.annotation.Nullable;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.javax.annotation.ParametersAreNonnullByDefault;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.javax.annotation.concurrent.Immutable;
import org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.javax.annotation.concurrent.NotThreadSafe;

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

* Use the builder to create immutable instances: * {@code ImmutableUiConfig.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "UiConfig"}) @Immutable @CheckReturnValue public final class ImmutableUiConfig extends UiConfig { private final String defaultTransactionType; private final ImmutableList defaultPercentiles; private final ImmutableList defaultGaugeNames; private ImmutableUiConfig(ImmutableUiConfig.Builder builder) { if (builder.defaultTransactionType != null) { initShim.defaultTransactionType(builder.defaultTransactionType); } if (builder.defaultPercentilesIsSet()) { initShim.defaultPercentiles(builder.defaultPercentiles.build()); } if (builder.defaultGaugeNamesIsSet()) { initShim.defaultGaugeNames(builder.defaultGaugeNames.build()); } this.defaultTransactionType = initShim.defaultTransactionType(); this.defaultPercentiles = initShim.defaultPercentiles(); this.defaultGaugeNames = initShim.defaultGaugeNames(); this.initShim = null; } private ImmutableUiConfig( String defaultTransactionType, ImmutableList defaultPercentiles, ImmutableList defaultGaugeNames) { this.defaultTransactionType = defaultTransactionType; this.defaultPercentiles = defaultPercentiles; this.defaultGaugeNames = defaultGaugeNames; this.initShim = null; } private static final int STAGE_INITIALIZING = -1; private static final int STAGE_UNINITIALIZED = 0; private static final int STAGE_INITIALIZED = 1; private transient volatile InitShim initShim = new InitShim(); private final class InitShim { private String defaultTransactionType; private int defaultTransactionTypeBuildStage; String defaultTransactionType() { if (defaultTransactionTypeBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (defaultTransactionTypeBuildStage == STAGE_UNINITIALIZED) { defaultTransactionTypeBuildStage = STAGE_INITIALIZING; this.defaultTransactionType = Preconditions.checkNotNull(ImmutableUiConfig.super.defaultTransactionType(), "defaultTransactionType"); defaultTransactionTypeBuildStage = STAGE_INITIALIZED; } return this.defaultTransactionType; } void defaultTransactionType(String defaultTransactionType) { this.defaultTransactionType = defaultTransactionType; defaultTransactionTypeBuildStage = STAGE_INITIALIZED; } private ImmutableList defaultPercentiles; private int defaultPercentilesBuildStage; ImmutableList defaultPercentiles() { if (defaultPercentilesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (defaultPercentilesBuildStage == STAGE_UNINITIALIZED) { defaultPercentilesBuildStage = STAGE_INITIALIZING; this.defaultPercentiles = Preconditions.checkNotNull(ImmutableUiConfig.super.defaultPercentiles(), "defaultPercentiles"); defaultPercentilesBuildStage = STAGE_INITIALIZED; } return this.defaultPercentiles; } void defaultPercentiles(ImmutableList defaultPercentiles) { this.defaultPercentiles = defaultPercentiles; defaultPercentilesBuildStage = STAGE_INITIALIZED; } private ImmutableList defaultGaugeNames; private int defaultGaugeNamesBuildStage; ImmutableList defaultGaugeNames() { if (defaultGaugeNamesBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (defaultGaugeNamesBuildStage == STAGE_UNINITIALIZED) { defaultGaugeNamesBuildStage = STAGE_INITIALIZING; this.defaultGaugeNames = Preconditions.checkNotNull(ImmutableUiConfig.super.defaultGaugeNames(), "defaultGaugeNames"); defaultGaugeNamesBuildStage = STAGE_INITIALIZED; } return this.defaultGaugeNames; } void defaultGaugeNames(ImmutableList defaultGaugeNames) { this.defaultGaugeNames = defaultGaugeNames; defaultGaugeNamesBuildStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { ArrayList attributes = Lists.newArrayList(); if (defaultTransactionTypeBuildStage == STAGE_INITIALIZING) attributes.add("defaultTransactionType"); if (defaultPercentilesBuildStage == STAGE_INITIALIZING) attributes.add("defaultPercentiles"); if (defaultGaugeNamesBuildStage == STAGE_INITIALIZING) attributes.add("defaultGaugeNames"); return "Cannot build UiConfig, attribute initializers form cycle" + attributes; } } /** * @return The value of the {@code defaultTransactionType} attribute */ @JsonProperty("defaultTransactionType") @Override public String defaultTransactionType() { InitShim shim = this.initShim; return shim != null ? shim.defaultTransactionType() : this.defaultTransactionType; } /** * @return The value of the {@code defaultPercentiles} attribute */ @JsonProperty("defaultPercentiles") @Override public ImmutableList defaultPercentiles() { InitShim shim = this.initShim; return shim != null ? shim.defaultPercentiles() : this.defaultPercentiles; } /** * @return The value of the {@code defaultGaugeNames} attribute */ @JsonProperty("defaultGaugeNames") @Override public ImmutableList defaultGaugeNames() { InitShim shim = this.initShim; return shim != null ? shim.defaultGaugeNames() : this.defaultGaugeNames; } /** * Copy the current immutable object by setting a value for the {@link UiConfig#defaultTransactionType() defaultTransactionType} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for defaultTransactionType * @return A modified copy of the {@code this} object */ public final ImmutableUiConfig withDefaultTransactionType(String value) { if (this.defaultTransactionType.equals(value)) return this; String newValue = Preconditions.checkNotNull(value, "defaultTransactionType"); return new ImmutableUiConfig(newValue, this.defaultPercentiles, this.defaultGaugeNames); } /** * Copy the current immutable object with elements that replace the content of {@link UiConfig#defaultPercentiles() defaultPercentiles}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableUiConfig withDefaultPercentiles(double... elements) { ImmutableList newValue = ImmutableList.copyOf(Doubles.asList(elements)); return new ImmutableUiConfig(this.defaultTransactionType, newValue, this.defaultGaugeNames); } /** * Copy the current immutable object with elements that replace the content of {@link UiConfig#defaultPercentiles() defaultPercentiles}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of defaultPercentiles elements to set * @return A modified copy of {@code this} object */ public final ImmutableUiConfig withDefaultPercentiles(Iterable elements) { if (this.defaultPercentiles == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableUiConfig(this.defaultTransactionType, newValue, this.defaultGaugeNames); } /** * Copy the current immutable object with elements that replace the content of {@link UiConfig#defaultGaugeNames() defaultGaugeNames}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableUiConfig withDefaultGaugeNames(String... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableUiConfig(this.defaultTransactionType, this.defaultPercentiles, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link UiConfig#defaultGaugeNames() defaultGaugeNames}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of defaultGaugeNames elements to set * @return A modified copy of {@code this} object */ public final ImmutableUiConfig withDefaultGaugeNames(Iterable elements) { if (this.defaultGaugeNames == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableUiConfig(this.defaultTransactionType, this.defaultPercentiles, newValue); } /** * This instance is equal to all instances of {@code ImmutableUiConfig} 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 ImmutableUiConfig && equalTo((ImmutableUiConfig) another); } private boolean equalTo(ImmutableUiConfig another) { return defaultTransactionType.equals(another.defaultTransactionType) && defaultPercentiles.equals(another.defaultPercentiles) && defaultGaugeNames.equals(another.defaultGaugeNames); } /** * Computes a hash code from attributes: {@code defaultTransactionType}, {@code defaultPercentiles}, {@code defaultGaugeNames}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + defaultTransactionType.hashCode(); h += (h << 5) + defaultPercentiles.hashCode(); h += (h << 5) + defaultGaugeNames.hashCode(); return h; } /** * Prints the immutable value {@code UiConfig} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("UiConfig") .omitNullValues() .add("defaultTransactionType", defaultTransactionType) .add("defaultPercentiles", defaultPercentiles) .add("defaultGaugeNames", defaultGaugeNames) .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 @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json extends UiConfig { @Nullable String defaultTransactionType; @Nullable ImmutableList defaultPercentiles = ImmutableList.of(); boolean defaultPercentilesIsSet; @Nullable ImmutableList defaultGaugeNames = ImmutableList.of(); boolean defaultGaugeNamesIsSet; @JsonProperty("defaultTransactionType") public void setDefaultTransactionType(String defaultTransactionType) { this.defaultTransactionType = defaultTransactionType; } @JsonProperty("defaultPercentiles") public void setDefaultPercentiles(ImmutableList defaultPercentiles) { this.defaultPercentiles = defaultPercentiles; this.defaultPercentilesIsSet = true; } @JsonProperty("defaultGaugeNames") public void setDefaultGaugeNames(ImmutableList defaultGaugeNames) { this.defaultGaugeNames = defaultGaugeNames; this.defaultGaugeNamesIsSet = true; } @Override public String defaultTransactionType() { throw new UnsupportedOperationException(); } @Override public ImmutableList defaultPercentiles() { throw new UnsupportedOperationException(); } @Override public ImmutableList defaultGaugeNames() { 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(mode = JsonCreator.Mode.DELEGATING) static ImmutableUiConfig fromJson(Json json) { ImmutableUiConfig.Builder builder = ImmutableUiConfig.builder(); if (json.defaultTransactionType != null) { builder.defaultTransactionType(json.defaultTransactionType); } if (json.defaultPercentilesIsSet) { builder.addAllDefaultPercentiles(json.defaultPercentiles); } if (json.defaultGaugeNamesIsSet) { builder.addAllDefaultGaugeNames(json.defaultGaugeNames); } return builder.build(); } /** * Creates an immutable copy of a {@link UiConfig} 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 UiConfig instance */ public static ImmutableUiConfig copyOf(UiConfig instance) { if (instance instanceof ImmutableUiConfig) { return (ImmutableUiConfig) instance; } return ImmutableUiConfig.builder() .copyFrom(instance) .build(); } /** * Creates a builder for {@link ImmutableUiConfig ImmutableUiConfig}. * @return A new ImmutableUiConfig builder */ public static ImmutableUiConfig.Builder builder() { return new ImmutableUiConfig.Builder(); } /** * Builds instances of type {@link ImmutableUiConfig ImmutableUiConfig}. * 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 OPT_BIT_DEFAULT_PERCENTILES = 0x1L; private static final long OPT_BIT_DEFAULT_GAUGE_NAMES = 0x2L; private long optBits; private @Nullable String defaultTransactionType; private ImmutableList.Builder defaultPercentiles = ImmutableList.builder(); private ImmutableList.Builder defaultGaugeNames = ImmutableList.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code UiConfig} 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 */ @CanIgnoreReturnValue public final Builder copyFrom(UiConfig instance) { Preconditions.checkNotNull(instance, "instance"); defaultTransactionType(instance.defaultTransactionType()); addAllDefaultPercentiles(instance.defaultPercentiles()); addAllDefaultGaugeNames(instance.defaultGaugeNames()); return this; } /** * Initializes the value for the {@link UiConfig#defaultTransactionType() defaultTransactionType} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link UiConfig#defaultTransactionType() defaultTransactionType}. * @param defaultTransactionType The value for defaultTransactionType * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder defaultTransactionType(String defaultTransactionType) { this.defaultTransactionType = Preconditions.checkNotNull(defaultTransactionType, "defaultTransactionType"); return this; } /** * Adds one element to {@link UiConfig#defaultPercentiles() defaultPercentiles} list. * @param element A defaultPercentiles element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addDefaultPercentiles(double element) { this.defaultPercentiles.add(element); optBits |= OPT_BIT_DEFAULT_PERCENTILES; return this; } /** * Adds elements to {@link UiConfig#defaultPercentiles() defaultPercentiles} list. * @param elements An array of defaultPercentiles elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addDefaultPercentiles(double... elements) { this.defaultPercentiles.addAll(Doubles.asList(elements)); optBits |= OPT_BIT_DEFAULT_PERCENTILES; return this; } /** * Sets or replaces all elements for {@link UiConfig#defaultPercentiles() defaultPercentiles} list. * @param elements An iterable of defaultPercentiles elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder defaultPercentiles(Iterable elements) { this.defaultPercentiles = ImmutableList.builder(); return addAllDefaultPercentiles(elements); } /** * Adds elements to {@link UiConfig#defaultPercentiles() defaultPercentiles} list. * @param elements An iterable of defaultPercentiles elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllDefaultPercentiles(Iterable elements) { this.defaultPercentiles.addAll(elements); optBits |= OPT_BIT_DEFAULT_PERCENTILES; return this; } /** * Adds one element to {@link UiConfig#defaultGaugeNames() defaultGaugeNames} list. * @param element A defaultGaugeNames element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addDefaultGaugeNames(String element) { this.defaultGaugeNames.add(element); optBits |= OPT_BIT_DEFAULT_GAUGE_NAMES; return this; } /** * Adds elements to {@link UiConfig#defaultGaugeNames() defaultGaugeNames} list. * @param elements An array of defaultGaugeNames elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addDefaultGaugeNames(String... elements) { this.defaultGaugeNames.add(elements); optBits |= OPT_BIT_DEFAULT_GAUGE_NAMES; return this; } /** * Sets or replaces all elements for {@link UiConfig#defaultGaugeNames() defaultGaugeNames} list. * @param elements An iterable of defaultGaugeNames elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder defaultGaugeNames(Iterable elements) { this.defaultGaugeNames = ImmutableList.builder(); return addAllDefaultGaugeNames(elements); } /** * Adds elements to {@link UiConfig#defaultGaugeNames() defaultGaugeNames} list. * @param elements An iterable of defaultGaugeNames elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllDefaultGaugeNames(Iterable elements) { this.defaultGaugeNames.addAll(elements); optBits |= OPT_BIT_DEFAULT_GAUGE_NAMES; return this; } /** * Builds a new {@link ImmutableUiConfig ImmutableUiConfig}. * @return An immutable instance of UiConfig * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableUiConfig build() { return new ImmutableUiConfig(this); } private boolean defaultPercentilesIsSet() { return (optBits & OPT_BIT_DEFAULT_PERCENTILES) != 0; } private boolean defaultGaugeNamesIsSet() { return (optBits & OPT_BIT_DEFAULT_GAUGE_NAMES) != 0; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy