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

org.glowroot.ui.ImmutablePluginConfigResponse Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
package org.glowroot.ui;

import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
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.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.common.config.PropertyDescriptor;

/**
 * Immutable implementation of {@link ConfigJsonService.PluginConfigResponse}.
 * 

* Use builder to create immutable instances: * {@code ImmutablePluginConfigResponse.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "ConfigJsonService.PluginConfigResponse"}) @Immutable final class ImmutablePluginConfigResponse implements ConfigJsonService.PluginConfigResponse { private final String name; private final ConfigJsonService.PluginConfigDto config; private final ImmutableList propertyDescriptors; private ImmutablePluginConfigResponse( String name, ConfigJsonService.PluginConfigDto config, ImmutableList propertyDescriptors) { this.name = name; this.config = config; this.propertyDescriptors = propertyDescriptors; } /** * @return value of {@code name} attribute */ @JsonProperty @Override public String name() { return name; } /** * @return value of {@code config} attribute */ @JsonProperty @Override public ConfigJsonService.PluginConfigDto config() { return config; } /** * @return value of {@code propertyDescriptors} attribute */ @JsonProperty @Override public ImmutableList propertyDescriptors() { return propertyDescriptors; } /** * Copy current immutable object by setting value for {@link ConfigJsonService.PluginConfigResponse#name() name}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for name * @return modified copy of the {@code this} object */ public final ImmutablePluginConfigResponse withName(String value) { if (this.name == value) return this; String newValue = Preconditions.checkNotNull(value); return new ImmutablePluginConfigResponse(newValue, this.config, this.propertyDescriptors); } /** * Copy current immutable object by setting value for {@link ConfigJsonService.PluginConfigResponse#config() config}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for config * @return modified copy of the {@code this} object */ public final ImmutablePluginConfigResponse withConfig(ConfigJsonService.PluginConfigDto value) { if (this.config == value) return this; ConfigJsonService.PluginConfigDto newValue = Preconditions.checkNotNull(value); return new ImmutablePluginConfigResponse(this.name, newValue, this.propertyDescriptors); } /** * Copy current immutable object with elements that replace content of {@link ConfigJsonService.PluginConfigResponse#propertyDescriptors() propertyDescriptors}. * @param elements elements to set * @return modified copy of {@code this} object */ public final ImmutablePluginConfigResponse withPropertyDescriptors(PropertyDescriptor... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePluginConfigResponse(this.name, this.config, newValue); } /** * Copy current immutable object with elements that replace content of {@link ConfigJsonService.PluginConfigResponse#propertyDescriptors() propertyDescriptors}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements iterable of propertyDescriptors elements to set * @return modified copy of {@code this} object */ public final ImmutablePluginConfigResponse withPropertyDescriptors(Iterable elements) { if (this.propertyDescriptors == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutablePluginConfigResponse(this.name, this.config, newValue); } /** * This instance is equal to instances of {@code ImmutablePluginConfigResponse} with 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 ImmutablePluginConfigResponse && equalTo((ImmutablePluginConfigResponse) another); } private boolean equalTo(ImmutablePluginConfigResponse another) { return name.equals(another.name) && config.equals(another.config) && propertyDescriptors.equals(another.propertyDescriptors); } /** * Computes hash code from attributes: {@code name}, {@code config}, {@code propertyDescriptors}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + name.hashCode(); h = h * 17 + config.hashCode(); h = h * 17 + propertyDescriptors.hashCode(); return h; } /** * Prints immutable value {@code PluginConfigResponse...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("PluginConfigResponse") .add("name", name) .add("config", config) .add("propertyDescriptors", propertyDescriptors) .toString(); } /** * Simple representation of this value type suitable Jackson binding * @deprecated Do not use this type directly, it exists only for Jackson-binding infrastructure */ @Deprecated static final class Json { @JsonProperty @Nullable String name; @JsonProperty @Nullable ConfigJsonService.PluginConfigDto config; @JsonProperty @Nullable ImmutableList propertyDescriptors; } /** * @param json JSON-bindable data structure * @return immutable value type * @deprecated Do not use this method directly, it exists only for Jackson-binding infrastructure */ @Deprecated @JsonCreator static ImmutablePluginConfigResponse fromJson(Json json) { ImmutablePluginConfigResponse.Builder builder = ImmutablePluginConfigResponse.builder(); if (json.name != null) { builder.name(json.name); } if (json.config != null) { builder.config(json.config); } if (json.propertyDescriptors != null) { builder.addAllPropertyDescriptors(json.propertyDescriptors); } return builder.build(); } /** * Creates immutable copy of {@link ConfigJsonService.PluginConfigResponse}. * 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 PluginConfigResponse instance */ static ImmutablePluginConfigResponse copyOf(ConfigJsonService.PluginConfigResponse instance) { if (instance instanceof ImmutablePluginConfigResponse) { return (ImmutablePluginConfigResponse) instance; } return ImmutablePluginConfigResponse.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.ui.ImmutablePluginConfigResponse ImmutablePluginConfigResponse}. * @return new ImmutablePluginConfigResponse builder */ static ImmutablePluginConfigResponse.Builder builder() { return new ImmutablePluginConfigResponse.Builder(); } /** * Builds instances of {@link org.glowroot.ui.ImmutablePluginConfigResponse ImmutablePluginConfigResponse}. * Initialize attributes and then invoke {@link #build()} method to create * immutable instance. *

{@code 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 INIT_BIT_NAME = 0x1L; private static final long INIT_BIT_CONFIG = 0x2L; private long initBits = 0x3; private @Nullable String name; private @Nullable ConfigJsonService.PluginConfigDto config; private ImmutableList.Builder propertyDescriptorsBuilder = ImmutableList.builder(); private Builder() {} /** * Fill builder with attribute values from provided {@link ConfigJsonService.PluginConfigResponse} instance. * Regular attribute values will be replaced with ones of an instance. * Instance's absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance instance to copy values from * @return {@code this} builder for chained invocation */ public final Builder copyFrom(ConfigJsonService.PluginConfigResponse instance) { Preconditions.checkNotNull(instance); name(instance.name()); config(instance.config()); addAllPropertyDescriptors(instance.propertyDescriptors()); return this; } /** * Initializes value for {@link ConfigJsonService.PluginConfigResponse#name() name}. * @param name value for name * @return {@code this} builder for chained invocation */ public final Builder name(String name) { this.name = Preconditions.checkNotNull(name); initBits &= ~INIT_BIT_NAME; return this; } /** * Initializes value for {@link ConfigJsonService.PluginConfigResponse#config() config}. * @param config value for config * @return {@code this} builder for chained invocation */ public final Builder config(ConfigJsonService.PluginConfigDto config) { this.config = Preconditions.checkNotNull(config); initBits &= ~INIT_BIT_CONFIG; return this; } /** * Adds one element to {@link ConfigJsonService.PluginConfigResponse#propertyDescriptors() propertyDescriptors} list. * @param element propertyDescriptors element * @return {@code this} builder for chained invocation */ public final Builder addPropertyDescriptors(PropertyDescriptor element) { propertyDescriptorsBuilder.add(element); return this; } /** * Adds elements to {@link ConfigJsonService.PluginConfigResponse#propertyDescriptors() propertyDescriptors} list. * @param elements array of propertyDescriptors elements * @return {@code this} builder for chained invocation */ public final Builder addPropertyDescriptors(PropertyDescriptor... elements) { propertyDescriptorsBuilder.add(elements); return this; } /** * Sets or replaces all elements for {@link ConfigJsonService.PluginConfigResponse#propertyDescriptors() propertyDescriptors} list. * @param elements iterable of propertyDescriptors elements * @return {@code this} builder for chained invocation */ public final Builder propertyDescriptors(Iterable elements) { propertyDescriptorsBuilder = ImmutableList.builder(); return addAllPropertyDescriptors(elements); } /** * Adds elements to {@link ConfigJsonService.PluginConfigResponse#propertyDescriptors() propertyDescriptors} list. * @param elements iterable of propertyDescriptors elements * @return {@code this} builder for chained invocation */ public final Builder addAllPropertyDescriptors(Iterable elements) { propertyDescriptorsBuilder.addAll(elements); return this; } /** * Builds new {@link org.glowroot.ui.ImmutablePluginConfigResponse ImmutablePluginConfigResponse}. * @return immutable instance of PluginConfigResponse * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutablePluginConfigResponse build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutablePluginConfigResponse(name, config, propertyDescriptorsBuilder.build()); } private boolean nameIsSet() { return (initBits & INIT_BIT_NAME) == 0; } private boolean configIsSet() { return (initBits & INIT_BIT_CONFIG) == 0; } private void checkRequiredAttributes() throws IllegalStateException { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if (!nameIsSet()) attributes.add("name"); if (!configIsSet()) attributes.add("config"); return "Cannot build PluginConfigResponse, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy