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

org.glowroot.agent.config.ImmutableJvmConfig 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.errorprone.annotations.CanIgnoreReturnValue;
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 JvmConfig}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableJvmConfig.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "JvmConfig"}) @Immutable @CheckReturnValue public final class ImmutableJvmConfig extends JvmConfig { private final ImmutableList maskSystemProperties; private ImmutableJvmConfig(ImmutableJvmConfig.Builder builder) { this.maskSystemProperties = builder.maskSystemPropertiesIsSet() ? builder.maskSystemProperties.build() : Preconditions.checkNotNull(super.maskSystemProperties(), "maskSystemProperties"); } private ImmutableJvmConfig(ImmutableList maskSystemProperties) { this.maskSystemProperties = maskSystemProperties; } /** * @return The value of the {@code maskSystemProperties} attribute */ @JsonProperty("maskSystemProperties") @Override public ImmutableList maskSystemProperties() { return maskSystemProperties; } /** * Copy the current immutable object with elements that replace the content of {@link JvmConfig#maskSystemProperties() maskSystemProperties}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableJvmConfig withMaskSystemProperties(String... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableJvmConfig(newValue); } /** * Copy the current immutable object with elements that replace the content of {@link JvmConfig#maskSystemProperties() maskSystemProperties}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of maskSystemProperties elements to set * @return A modified copy of {@code this} object */ public final ImmutableJvmConfig withMaskSystemProperties(Iterable elements) { if (this.maskSystemProperties == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableJvmConfig(newValue); } /** * This instance is equal to all instances of {@code ImmutableJvmConfig} 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 ImmutableJvmConfig && equalTo((ImmutableJvmConfig) another); } private boolean equalTo(ImmutableJvmConfig another) { return maskSystemProperties.equals(another.maskSystemProperties); } /** * Computes a hash code from attributes: {@code maskSystemProperties}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + maskSystemProperties.hashCode(); return h; } /** * Prints the immutable value {@code JvmConfig} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("JvmConfig") .omitNullValues() .add("maskSystemProperties", maskSystemProperties) .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 JvmConfig { @Nullable ImmutableList maskSystemProperties = ImmutableList.of(); boolean maskSystemPropertiesIsSet; @JsonProperty("maskSystemProperties") public void setMaskSystemProperties(ImmutableList maskSystemProperties) { this.maskSystemProperties = maskSystemProperties; this.maskSystemPropertiesIsSet = true; } @Override public ImmutableList maskSystemProperties() { 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 ImmutableJvmConfig fromJson(Json json) { ImmutableJvmConfig.Builder builder = ImmutableJvmConfig.builder(); if (json.maskSystemPropertiesIsSet) { builder.addAllMaskSystemProperties(json.maskSystemProperties); } return builder.build(); } /** * Creates an immutable copy of a {@link JvmConfig} 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 JvmConfig instance */ public static ImmutableJvmConfig copyOf(JvmConfig instance) { if (instance instanceof ImmutableJvmConfig) { return (ImmutableJvmConfig) instance; } return ImmutableJvmConfig.builder() .copyFrom(instance) .build(); } /** * Creates a builder for {@link ImmutableJvmConfig ImmutableJvmConfig}. * @return A new ImmutableJvmConfig builder */ public static ImmutableJvmConfig.Builder builder() { return new ImmutableJvmConfig.Builder(); } /** * Builds instances of type {@link ImmutableJvmConfig ImmutableJvmConfig}. * 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_MASK_SYSTEM_PROPERTIES = 0x1L; private long optBits; private ImmutableList.Builder maskSystemProperties = ImmutableList.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code JvmConfig} 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(JvmConfig instance) { Preconditions.checkNotNull(instance, "instance"); addAllMaskSystemProperties(instance.maskSystemProperties()); return this; } /** * Adds one element to {@link JvmConfig#maskSystemProperties() maskSystemProperties} list. * @param element A maskSystemProperties element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addMaskSystemProperties(String element) { this.maskSystemProperties.add(element); optBits |= OPT_BIT_MASK_SYSTEM_PROPERTIES; return this; } /** * Adds elements to {@link JvmConfig#maskSystemProperties() maskSystemProperties} list. * @param elements An array of maskSystemProperties elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addMaskSystemProperties(String... elements) { this.maskSystemProperties.add(elements); optBits |= OPT_BIT_MASK_SYSTEM_PROPERTIES; return this; } /** * Sets or replaces all elements for {@link JvmConfig#maskSystemProperties() maskSystemProperties} list. * @param elements An iterable of maskSystemProperties elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder maskSystemProperties(Iterable elements) { this.maskSystemProperties = ImmutableList.builder(); return addAllMaskSystemProperties(elements); } /** * Adds elements to {@link JvmConfig#maskSystemProperties() maskSystemProperties} list. * @param elements An iterable of maskSystemProperties elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllMaskSystemProperties(Iterable elements) { this.maskSystemProperties.addAll(elements); optBits |= OPT_BIT_MASK_SYSTEM_PROPERTIES; return this; } /** * Builds a new {@link ImmutableJvmConfig ImmutableJvmConfig}. * @return An immutable instance of JvmConfig * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableJvmConfig build() { return new ImmutableJvmConfig(this); } private boolean maskSystemPropertiesIsSet() { return (optBits & OPT_BIT_MASK_SYSTEM_PROPERTIES) != 0; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy