
org.glowroot.ui.ImmutablePluginConfigDto Maven / Gradle / Ivy
package org.glowroot.ui;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonInclude;
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.Objects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.ImmutableMap;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Booleans;
import java.util.List;
import java.util.Map;
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.PropertyValue;
/**
* Immutable implementation of {@link ConfigJsonService.PluginConfigDto}.
*
* Use builder to create immutable instances:
* {@code ImmutablePluginConfigDto.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ConfigJsonService.PluginConfigDto"})
@Immutable
final class ImmutablePluginConfigDto extends ConfigJsonService.PluginConfigDto {
private final @Nullable String pluginId;
private final boolean enabled;
private final ImmutableMap properties;
private final String version;
private ImmutablePluginConfigDto(
@Nullable String pluginId,
boolean enabled,
ImmutableMap properties,
String version) {
this.pluginId = pluginId;
this.enabled = enabled;
this.properties = properties;
this.version = version;
}
/**
* @return value of {@code pluginId} attribute
*/
@JsonProperty
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
@Override
@Nullable String pluginId() {
return pluginId;
}
/**
* @return value of {@code enabled} attribute
*/
@JsonProperty
@Override
boolean enabled() {
return enabled;
}
/**
* @return value of {@code properties} attribute
*/
@JsonProperty
@Override
ImmutableMap properties() {
return properties;
}
/**
* @return value of {@code version} attribute
*/
@JsonProperty
@Override
String version() {
return version;
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.PluginConfigDto#pluginId() pluginId}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for pluginId, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutablePluginConfigDto withPluginId(@Nullable String value) {
if (this.pluginId == value) return this;
@Nullable String newValue = value;
return new ImmutablePluginConfigDto(newValue, this.enabled, this.properties, this.version);
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.PluginConfigDto#enabled() enabled}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for enabled
* @return modified copy of the {@code this} object
*/
public final ImmutablePluginConfigDto withEnabled(boolean value) {
if (this.enabled == value) return this;
boolean newValue = value;
return new ImmutablePluginConfigDto(this.pluginId, newValue, this.properties, this.version);
}
/**
* Copy current immutable object by replacing {@link ConfigJsonService.PluginConfigDto#properties() properties} map with specified map.
* Nulls are not permitted as keys or values.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param entries to be added to properties map
* @return modified copy of {@code this} object
*/
public final ImmutablePluginConfigDto withProperties(Map entries) {
if (this.properties == entries) return this;
ImmutableMap newValue = ImmutableMap.copyOf(entries);
return new ImmutablePluginConfigDto(this.pluginId, this.enabled, newValue, this.version);
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.PluginConfigDto#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
* @return modified copy of the {@code this} object
*/
public final ImmutablePluginConfigDto withVersion(String value) {
if (this.version == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutablePluginConfigDto(this.pluginId, this.enabled, this.properties, newValue);
}
/**
* This instance is equal to instances of {@code ImmutablePluginConfigDto} 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 ImmutablePluginConfigDto
&& equalTo((ImmutablePluginConfigDto) another);
}
private boolean equalTo(ImmutablePluginConfigDto another) {
return Objects.equal(pluginId, another.pluginId)
&& enabled == another.enabled
&& properties.equals(another.properties)
&& version.equals(another.version);
}
/**
* Computes hash code from attributes: {@code pluginId}, {@code enabled}, {@code properties}, {@code version}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Objects.hashCode(pluginId);
h = h * 17 + Booleans.hashCode(enabled);
h = h * 17 + properties.hashCode();
h = h * 17 + version.hashCode();
return h;
}
/**
* Prints immutable value {@code PluginConfigDto...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("PluginConfigDto")
.add("pluginId", pluginId)
.add("enabled", enabled)
.add("properties", properties)
.add("version", version)
.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
@JsonInclude(value = JsonInclude.Include.NON_EMPTY)
@Nullable String pluginId;
@JsonProperty
@Nullable Boolean enabled;
@JsonProperty
@Nullable Map properties;
@JsonProperty
@Nullable String version;
}
/**
* @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 ImmutablePluginConfigDto fromJson(Json json) {
ImmutablePluginConfigDto.Builder builder = ImmutablePluginConfigDto.builder();
if (json.pluginId != null) {
builder.pluginId(json.pluginId);
}
if (json.enabled != null) {
builder.enabled(json.enabled);
}
if (json.properties != null) {
builder.putAllProperties(json.properties);
}
if (json.version != null) {
builder.version(json.version);
}
return builder.build();
}
/**
* Creates immutable copy of {@link ConfigJsonService.PluginConfigDto}.
* 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 PluginConfigDto instance
*/
static ImmutablePluginConfigDto copyOf(ConfigJsonService.PluginConfigDto instance) {
if (instance instanceof ImmutablePluginConfigDto) {
return (ImmutablePluginConfigDto) instance;
}
return ImmutablePluginConfigDto.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutablePluginConfigDto ImmutablePluginConfigDto}.
* @return new ImmutablePluginConfigDto builder
*/
static ImmutablePluginConfigDto.Builder builder() {
return new ImmutablePluginConfigDto.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutablePluginConfigDto ImmutablePluginConfigDto}.
* 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_ENABLED = 0x1L;
private static final long INIT_BIT_VERSION = 0x2L;
private long initBits = 0x3;
private @Nullable String pluginId;
private boolean enabled;
private ImmutableMap.Builder propertiesBuilder = ImmutableMap.builder();
private @Nullable String version;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link ConfigJsonService.PluginConfigDto} 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.PluginConfigDto instance) {
Preconditions.checkNotNull(instance);
@Nullable String pluginIdValue = instance.pluginId();
if (pluginIdValue != null) {
pluginId(pluginIdValue);
}
enabled(instance.enabled());
putAllProperties(instance.properties());
version(instance.version());
return this;
}
/**
* Initializes value for {@link ConfigJsonService.PluginConfigDto#pluginId() pluginId}.
* @param pluginId value for pluginId, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder pluginId(@Nullable String pluginId) {
this.pluginId = pluginId;
return this;
}
/**
* Initializes value for {@link ConfigJsonService.PluginConfigDto#enabled() enabled}.
* @param enabled value for enabled
* @return {@code this} builder for chained invocation
*/
public final Builder enabled(boolean enabled) {
this.enabled = enabled;
initBits &= ~INIT_BIT_ENABLED;
return this;
}
/**
* Put one entry to {@link ConfigJsonService.PluginConfigDto#properties() properties} map.
* @param key the key in properties map
* @param value the associated value in properties map
* @return {@code this} builder for chained invocation
*/
public final Builder putProperties(String key, PropertyValue value) {
propertiesBuilder.put(key, value);
return this;
}
/**
* Put one entry to {@link ConfigJsonService.PluginConfigDto#properties() properties} map. Nulls are not permitted
* @param entry the key and value entry
* @return {@code this} builder for chained invocation
*/
public final Builder putProperties(Map.Entry entry) {
propertiesBuilder.put(entry);
return this;
}
/**
* Sets or replaces all mappings from specified map as entries for {@link ConfigJsonService.PluginConfigDto#properties() properties} map. Nulls are not permitted
* @param entries to be added to properties map
* @return {@code this} builder for chained invocation
*/
public final Builder properties(Map entries) {
propertiesBuilder = ImmutableMap.builder();
return putAllProperties(entries);
}
/**
* Put all mappings from specified map as entries to {@link ConfigJsonService.PluginConfigDto#properties() properties} map. Nulls are not permitted
* @param entries to be added to properties map
* @return {@code this} builder for chained invocation
*/
public final Builder putAllProperties(Map entries) {
propertiesBuilder.putAll(entries);
return this;
}
/**
* Initializes value for {@link ConfigJsonService.PluginConfigDto#version() version}.
* @param version value for version
* @return {@code this} builder for chained invocation
*/
public final Builder version(String version) {
this.version = Preconditions.checkNotNull(version);
initBits &= ~INIT_BIT_VERSION;
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutablePluginConfigDto ImmutablePluginConfigDto}.
* @return immutable instance of PluginConfigDto
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutablePluginConfigDto build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutablePluginConfigDto(pluginId, enabled, propertiesBuilder.build(), version);
}
private boolean enabledIsSet() {
return (initBits & INIT_BIT_ENABLED) == 0;
}
private boolean versionIsSet() {
return (initBits & INIT_BIT_VERSION) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!enabledIsSet()) attributes.add("enabled");
if (!versionIsSet()) attributes.add("version");
return "Cannot build PluginConfigDto, some of required attributes are not set " + attributes;
}
}
}