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

org.glowroot.agent.config.ImmutablePluginConfigTemp 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.ImmutableMap;
import org.glowroot.agent.shaded.org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.com.google.errorprone.annotations.CanIgnoreReturnValue;
import org.glowroot.agent.shaded.org.glowroot.agent.shaded.org.glowroot.agent.it.harness.shaded.com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
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;
import org.glowroot.agent.shaded.org.glowroot.common.config.PropertyValue;

/**
 * Immutable implementation of {@link ConfigService.PluginConfigTemp}.
 * 

* Use the builder to create immutable instances: * {@code ImmutablePluginConfigTemp.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue final class ImmutablePluginConfigTemp implements ConfigService.PluginConfigTemp { private final String id; private final ImmutableMap properties; private ImmutablePluginConfigTemp( String id, ImmutableMap properties) { this.id = id; this.properties = properties; } /** * @return The value of the {@code id} attribute */ @JsonProperty("id") @Override public String id() { return id; } /** * @return The value of the {@code properties} attribute */ @JsonProperty("properties") @Override public ImmutableMap properties() { return properties; } /** * Copy the current immutable object by setting a value for the {@link ConfigService.PluginConfigTemp#id() id} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for id * @return A modified copy of the {@code this} object */ public final ImmutablePluginConfigTemp withId(String value) { if (this.id.equals(value)) return this; String newValue = Preconditions.checkNotNull(value, "id"); return new ImmutablePluginConfigTemp(newValue, this.properties); } /** * Copy the current immutable object by replacing the {@link ConfigService.PluginConfigTemp#properties() properties} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param entries The entries to be added to the properties map * @return A modified copy of {@code this} object */ public final ImmutablePluginConfigTemp withProperties(Map entries) { if (this.properties == entries) return this; ImmutableMap newValue = ImmutableMap.copyOf(entries); return new ImmutablePluginConfigTemp(this.id, newValue); } /** * This instance is equal to all instances of {@code ImmutablePluginConfigTemp} 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 ImmutablePluginConfigTemp && equalTo((ImmutablePluginConfigTemp) another); } private boolean equalTo(ImmutablePluginConfigTemp another) { return id.equals(another.id) && properties.equals(another.properties); } /** * Computes a hash code from attributes: {@code id}, {@code properties}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + id.hashCode(); h += (h << 5) + properties.hashCode(); return h; } /** * Prints the immutable value {@code PluginConfigTemp} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("PluginConfigTemp") .omitNullValues() .add("id", id) .add("properties", properties) .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 @SuppressWarnings("Immutable") @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements ConfigService.PluginConfigTemp { @Nullable String id; @Nullable Map properties = ImmutableMap.of(); @JsonProperty("id") public void setId(String id) { this.id = id; } @JsonProperty("properties") public void setProperties(Map properties) { this.properties = properties; } @Override public String id() { throw new UnsupportedOperationException(); } @Override public Map properties() { 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 ImmutablePluginConfigTemp fromJson(Json json) { ImmutablePluginConfigTemp.Builder builder = ImmutablePluginConfigTemp.builder(); if (json.id != null) { builder.id(json.id); } if (json.properties != null) { builder.putAllProperties(json.properties); } return builder.build(); } /** * Creates an immutable copy of a {@link ConfigService.PluginConfigTemp} 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 PluginConfigTemp instance */ public static ImmutablePluginConfigTemp copyOf(ConfigService.PluginConfigTemp instance) { if (instance instanceof ImmutablePluginConfigTemp) { return (ImmutablePluginConfigTemp) instance; } return ImmutablePluginConfigTemp.builder() .copyFrom(instance) .build(); } /** * Creates a builder for {@link ImmutablePluginConfigTemp ImmutablePluginConfigTemp}. * @return A new ImmutablePluginConfigTemp builder */ public static ImmutablePluginConfigTemp.Builder builder() { return new ImmutablePluginConfigTemp.Builder(); } /** * Builds instances of type {@link ImmutablePluginConfigTemp ImmutablePluginConfigTemp}. * 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_ID = 0x1L; private long initBits = 0x1L; private @Nullable String id; private ImmutableMap.Builder properties = ImmutableMap.builder(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code PluginConfigTemp} 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(ConfigService.PluginConfigTemp instance) { Preconditions.checkNotNull(instance, "instance"); id(instance.id()); putAllProperties(instance.properties()); return this; } /** * Initializes the value for the {@link ConfigService.PluginConfigTemp#id() id} attribute. * @param id The value for id * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder id(String id) { this.id = Preconditions.checkNotNull(id, "id"); initBits &= ~INIT_BIT_ID; return this; } /** * Put one entry to the {@link ConfigService.PluginConfigTemp#properties() properties} map. * @param key The key in the properties map * @param value The associated value in the properties map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putProperties(String key, PropertyValue value) { this.properties.put(key, value); return this; } /** * Put one entry to the {@link ConfigService.PluginConfigTemp#properties() properties} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putProperties(Map.Entry entry) { this.properties.put(entry); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link ConfigService.PluginConfigTemp#properties() properties} map. Nulls are not permitted * @param entries The entries that will be added to the properties map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder properties(Map entries) { this.properties = ImmutableMap.builder(); return putAllProperties(entries); } /** * Put all mappings from the specified map as entries to {@link ConfigService.PluginConfigTemp#properties() properties} map. Nulls are not permitted * @param entries The entries that will be added to the properties map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putAllProperties(Map entries) { this.properties.putAll(entries); return this; } /** * Builds a new {@link ImmutablePluginConfigTemp ImmutablePluginConfigTemp}. * @return An immutable instance of PluginConfigTemp * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutablePluginConfigTemp build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutablePluginConfigTemp(id, properties.build()); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList(); if ((initBits & INIT_BIT_ID) != 0) attributes.add("id"); return "Cannot build PluginConfigTemp, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy