
org.glowroot.common.config.ImmutablePluginDescriptor Maven / Gradle / Ivy
package org.glowroot.common.config;
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;
/**
* Immutable implementation of {@link PluginDescriptor}.
*
* Use builder to create immutable instances:
* {@code ImmutablePluginDescriptor.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "PluginDescriptor"})
@Immutable
public final class ImmutablePluginDescriptor implements PluginDescriptor {
private final String name;
private final String id;
private final ImmutableList properties;
private final ImmutableList instrumentationConfigs;
private final ImmutableList aspects;
private ImmutablePluginDescriptor(
String name,
String id,
ImmutableList properties,
ImmutableList instrumentationConfigs,
ImmutableList aspects) {
this.name = name;
this.id = id;
this.properties = properties;
this.instrumentationConfigs = instrumentationConfigs;
this.aspects = aspects;
}
/**
* @return value of {@code name} attribute
*/
@JsonProperty
@Override
public String name() {
return name;
}
/**
* @return value of {@code id} attribute
*/
@JsonProperty
@Override
public String id() {
return id;
}
/**
* @return value of {@code properties} attribute
*/
@JsonProperty
@Override
public ImmutableList properties() {
return properties;
}
/**
* @return value of {@code instrumentationConfigs} attribute
*/
@JsonProperty(value = "instrumentation")
@Override
public ImmutableList instrumentationConfigs() {
return instrumentationConfigs;
}
/**
* @return value of {@code aspects} attribute
*/
@JsonProperty
@Override
public ImmutableList aspects() {
return aspects;
}
/**
* Copy current immutable object by setting value for {@link PluginDescriptor#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 ImmutablePluginDescriptor withName(String value) {
if (this.name == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutablePluginDescriptor(newValue, this.id, this.properties, this.instrumentationConfigs, this.aspects);
}
/**
* Copy current immutable object by setting value for {@link PluginDescriptor#id() id}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for id
* @return modified copy of the {@code this} object
*/
public final ImmutablePluginDescriptor withId(String value) {
if (this.id == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutablePluginDescriptor(this.name, newValue, this.properties, this.instrumentationConfigs, this.aspects);
}
/**
* Copy current immutable object with elements that replace content of {@link PluginDescriptor#properties() properties}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutablePluginDescriptor withProperties(PropertyDescriptor... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePluginDescriptor(this.name, this.id, newValue, this.instrumentationConfigs, this.aspects);
}
/**
* Copy current immutable object with elements that replace content of {@link PluginDescriptor#properties() properties}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of properties elements to set
* @return modified copy of {@code this} object
*/
public final ImmutablePluginDescriptor withProperties(Iterable extends PropertyDescriptor> elements) {
if (this.properties == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePluginDescriptor(this.name, this.id, newValue, this.instrumentationConfigs, this.aspects);
}
/**
* Copy current immutable object with elements that replace content of {@link PluginDescriptor#instrumentationConfigs() instrumentationConfigs}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutablePluginDescriptor withInstrumentationConfigs(InstrumentationConfig... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePluginDescriptor(this.name, this.id, this.properties, newValue, this.aspects);
}
/**
* Copy current immutable object with elements that replace content of {@link PluginDescriptor#instrumentationConfigs() instrumentationConfigs}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of instrumentationConfigs elements to set
* @return modified copy of {@code this} object
*/
public final ImmutablePluginDescriptor withInstrumentationConfigs(Iterable extends InstrumentationConfig> elements) {
if (this.instrumentationConfigs == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePluginDescriptor(this.name, this.id, this.properties, newValue, this.aspects);
}
/**
* Copy current immutable object with elements that replace content of {@link PluginDescriptor#aspects() aspects}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutablePluginDescriptor withAspects(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePluginDescriptor(this.name, this.id, this.properties, this.instrumentationConfigs, newValue);
}
/**
* Copy current immutable object with elements that replace content of {@link PluginDescriptor#aspects() aspects}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of aspects elements to set
* @return modified copy of {@code this} object
*/
public final ImmutablePluginDescriptor withAspects(Iterable elements) {
if (this.aspects == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePluginDescriptor(this.name, this.id, this.properties, this.instrumentationConfigs, newValue);
}
/**
* This instance is equal to instances of {@code ImmutablePluginDescriptor} 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 ImmutablePluginDescriptor
&& equalTo((ImmutablePluginDescriptor) another);
}
private boolean equalTo(ImmutablePluginDescriptor another) {
return name.equals(another.name)
&& id.equals(another.id)
&& properties.equals(another.properties)
&& instrumentationConfigs.equals(another.instrumentationConfigs)
&& aspects.equals(another.aspects);
}
/**
* Computes hash code from attributes: {@code name}, {@code id}, {@code properties}, {@code instrumentationConfigs}, {@code aspects}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + name.hashCode();
h = h * 17 + id.hashCode();
h = h * 17 + properties.hashCode();
h = h * 17 + instrumentationConfigs.hashCode();
h = h * 17 + aspects.hashCode();
return h;
}
/**
* Prints immutable value {@code PluginDescriptor...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("PluginDescriptor")
.add("name", name)
.add("id", id)
.add("properties", properties)
.add("instrumentationConfigs", instrumentationConfigs)
.add("aspects", aspects)
.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 String id;
@JsonProperty
@Nullable ImmutableList properties;
@JsonProperty(value = "instrumentation")
@Nullable ImmutableList instrumentationConfigs;
@JsonProperty
@Nullable ImmutableList aspects;
}
/**
* @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 ImmutablePluginDescriptor fromJson(Json json) {
ImmutablePluginDescriptor.Builder builder = ImmutablePluginDescriptor.builder();
if (json.name != null) {
builder.name(json.name);
}
if (json.id != null) {
builder.id(json.id);
}
if (json.properties != null) {
builder.addAllProperties(json.properties);
}
if (json.instrumentationConfigs != null) {
builder.addAllInstrumentationConfigs(json.instrumentationConfigs);
}
if (json.aspects != null) {
builder.addAllAspects(json.aspects);
}
return builder.build();
}
/**
* Creates immutable copy of {@link PluginDescriptor}.
* 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 PluginDescriptor instance
*/
public static ImmutablePluginDescriptor copyOf(PluginDescriptor instance) {
if (instance instanceof ImmutablePluginDescriptor) {
return (ImmutablePluginDescriptor) instance;
}
return ImmutablePluginDescriptor.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.common.config.ImmutablePluginDescriptor ImmutablePluginDescriptor}.
* @return new ImmutablePluginDescriptor builder
*/
public static ImmutablePluginDescriptor.Builder builder() {
return new ImmutablePluginDescriptor.Builder();
}
/**
* Builds instances of {@link org.glowroot.common.config.ImmutablePluginDescriptor ImmutablePluginDescriptor}.
* 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
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private static final long INIT_BIT_ID = 0x2L;
private long initBits = 0x3;
private @Nullable String name;
private @Nullable String id;
private ImmutableList.Builder propertiesBuilder = ImmutableList.builder();
private ImmutableList.Builder instrumentationConfigsBuilder = ImmutableList.builder();
private ImmutableList.Builder aspectsBuilder = ImmutableList.builder();
private Builder() {}
/**
* Fill builder with attribute values from provided {@link PluginDescriptor} 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(PluginDescriptor instance) {
Preconditions.checkNotNull(instance);
name(instance.name());
id(instance.id());
addAllProperties(instance.properties());
addAllInstrumentationConfigs(instance.instrumentationConfigs());
addAllAspects(instance.aspects());
return this;
}
/**
* Initializes value for {@link PluginDescriptor#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 PluginDescriptor#id() id}.
* @param id value for id
* @return {@code this} builder for chained invocation
*/
public final Builder id(String id) {
this.id = Preconditions.checkNotNull(id);
initBits &= ~INIT_BIT_ID;
return this;
}
/**
* Adds one element to {@link PluginDescriptor#properties() properties} list.
* @param element properties element
* @return {@code this} builder for chained invocation
*/
public final Builder addProperties(PropertyDescriptor element) {
propertiesBuilder.add(element);
return this;
}
/**
* Adds elements to {@link PluginDescriptor#properties() properties} list.
* @param elements array of properties elements
* @return {@code this} builder for chained invocation
*/
public final Builder addProperties(PropertyDescriptor... elements) {
propertiesBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link PluginDescriptor#properties() properties} list.
* @param elements iterable of properties elements
* @return {@code this} builder for chained invocation
*/
public final Builder properties(Iterable extends PropertyDescriptor> elements) {
propertiesBuilder = ImmutableList.builder();
return addAllProperties(elements);
}
/**
* Adds elements to {@link PluginDescriptor#properties() properties} list.
* @param elements iterable of properties elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllProperties(Iterable extends PropertyDescriptor> elements) {
propertiesBuilder.addAll(elements);
return this;
}
/**
* Adds one element to {@link PluginDescriptor#instrumentationConfigs() instrumentationConfigs} list.
* @param element instrumentationConfigs element
* @return {@code this} builder for chained invocation
*/
public final Builder addInstrumentationConfigs(InstrumentationConfig element) {
instrumentationConfigsBuilder.add(element);
return this;
}
/**
* Adds elements to {@link PluginDescriptor#instrumentationConfigs() instrumentationConfigs} list.
* @param elements array of instrumentationConfigs elements
* @return {@code this} builder for chained invocation
*/
public final Builder addInstrumentationConfigs(InstrumentationConfig... elements) {
instrumentationConfigsBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link PluginDescriptor#instrumentationConfigs() instrumentationConfigs} list.
* @param elements iterable of instrumentationConfigs elements
* @return {@code this} builder for chained invocation
*/
public final Builder instrumentationConfigs(Iterable extends InstrumentationConfig> elements) {
instrumentationConfigsBuilder = ImmutableList.builder();
return addAllInstrumentationConfigs(elements);
}
/**
* Adds elements to {@link PluginDescriptor#instrumentationConfigs() instrumentationConfigs} list.
* @param elements iterable of instrumentationConfigs elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllInstrumentationConfigs(Iterable extends InstrumentationConfig> elements) {
instrumentationConfigsBuilder.addAll(elements);
return this;
}
/**
* Adds one element to {@link PluginDescriptor#aspects() aspects} list.
* @param element aspects element
* @return {@code this} builder for chained invocation
*/
public final Builder addAspects(String element) {
aspectsBuilder.add(element);
return this;
}
/**
* Adds elements to {@link PluginDescriptor#aspects() aspects} list.
* @param elements array of aspects elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAspects(String... elements) {
aspectsBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link PluginDescriptor#aspects() aspects} list.
* @param elements iterable of aspects elements
* @return {@code this} builder for chained invocation
*/
public final Builder aspects(Iterable elements) {
aspectsBuilder = ImmutableList.builder();
return addAllAspects(elements);
}
/**
* Adds elements to {@link PluginDescriptor#aspects() aspects} list.
* @param elements iterable of aspects elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllAspects(Iterable elements) {
aspectsBuilder.addAll(elements);
return this;
}
/**
* Builds new {@link org.glowroot.common.config.ImmutablePluginDescriptor ImmutablePluginDescriptor}.
* @return immutable instance of PluginDescriptor
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutablePluginDescriptor build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutablePluginDescriptor(
name,
id,
propertiesBuilder.build(),
instrumentationConfigsBuilder.build(),
aspectsBuilder.build());
}
private boolean nameIsSet() {
return (initBits & INIT_BIT_NAME) == 0;
}
private boolean idIsSet() {
return (initBits & INIT_BIT_ID) == 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 (!idIsSet()) attributes.add("id");
return "Cannot build PluginDescriptor, some of required attributes are not set " + attributes;
}
}
}