![JAR search and dependency download from the Maven repository](/logo.png)
org.glowroot.instrumentation.engine.config.ImmutableInstrumentationDescriptor Maven / Gradle / Ivy
package org.glowroot.instrumentation.engine.config;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.base.MoreObjects;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.base.Objects;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.base.Preconditions;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.collect.ImmutableList;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.primitives.Booleans;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link InstrumentationDescriptor}.
*
* Use the builder to create immutable instances:
* {@code ImmutableInstrumentationDescriptor.builder()}.
*/
@Generated(from = "InstrumentationDescriptor", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutableInstrumentationDescriptor
extends InstrumentationDescriptor {
private final String id;
private final String name;
private final ImmutableList properties;
private final ImmutableList adviceConfigs;
private final ImmutableList classes;
private final boolean collocate;
private final @Nullable File jarFile;
private ImmutableInstrumentationDescriptor(ImmutableInstrumentationDescriptor.Builder builder) {
this.id = builder.id;
this.name = builder.name;
this.properties = builder.properties.build();
this.adviceConfigs = builder.adviceConfigs.build();
this.classes = builder.classes.build();
this.jarFile = builder.jarFile;
this.collocate = builder.collocateIsSet()
? builder.collocate
: super.collocate();
}
private ImmutableInstrumentationDescriptor(
String id,
String name,
ImmutableList properties,
ImmutableList adviceConfigs,
ImmutableList classes,
boolean collocate,
@Nullable File jarFile) {
this.id = id;
this.name = name;
this.properties = properties;
this.adviceConfigs = adviceConfigs;
this.classes = classes;
this.collocate = collocate;
this.jarFile = jarFile;
}
/**
* @return The value of the {@code id} attribute
*/
@Override
public String id() {
return id;
}
/**
* @return The value of the {@code name} attribute
*/
@Override
public String name() {
return name;
}
/**
* @return The value of the {@code properties} attribute
*/
@Override
public ImmutableList properties() {
return properties;
}
/**
* @return The value of the {@code adviceConfigs} attribute
*/
@Override
public ImmutableList adviceConfigs() {
return adviceConfigs;
}
/**
* @return The value of the {@code classes} attribute
*/
@Override
public ImmutableList classes() {
return classes;
}
/**
* @return The value of the {@code collocate} attribute
*/
@Override
public boolean collocate() {
return collocate;
}
/**
* @return The value of the {@code jarFile} attribute
*/
@Override
public @Nullable File jarFile() {
return jarFile;
}
/**
* Copy the current immutable object by setting a value for the {@link InstrumentationDescriptor#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 ImmutableInstrumentationDescriptor withId(String value) {
String newValue = Preconditions.checkNotNull(value, "id");
if (this.id.equals(newValue)) return this;
return new ImmutableInstrumentationDescriptor(
newValue,
this.name,
this.properties,
this.adviceConfigs,
this.classes,
this.collocate,
this.jarFile);
}
/**
* Copy the current immutable object by setting a value for the {@link InstrumentationDescriptor#name() name} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for name
* @return A modified copy of the {@code this} object
*/
public final ImmutableInstrumentationDescriptor withName(String value) {
String newValue = Preconditions.checkNotNull(value, "name");
if (this.name.equals(newValue)) return this;
return new ImmutableInstrumentationDescriptor(
this.id,
newValue,
this.properties,
this.adviceConfigs,
this.classes,
this.collocate,
this.jarFile);
}
/**
* Copy the current immutable object with elements that replace the content of {@link InstrumentationDescriptor#properties() properties}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableInstrumentationDescriptor withProperties(PropertyDescriptor... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableInstrumentationDescriptor(this.id, this.name, newValue, this.adviceConfigs, this.classes, this.collocate, this.jarFile);
}
/**
* Copy the current immutable object with elements that replace the content of {@link InstrumentationDescriptor#properties() properties}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of properties elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableInstrumentationDescriptor withProperties(Iterable extends PropertyDescriptor> elements) {
if (this.properties == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableInstrumentationDescriptor(this.id, this.name, newValue, this.adviceConfigs, this.classes, this.collocate, this.jarFile);
}
/**
* Copy the current immutable object with elements that replace the content of {@link InstrumentationDescriptor#adviceConfigs() adviceConfigs}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableInstrumentationDescriptor withAdviceConfigs(AdviceConfig... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableInstrumentationDescriptor(this.id, this.name, this.properties, newValue, this.classes, this.collocate, this.jarFile);
}
/**
* Copy the current immutable object with elements that replace the content of {@link InstrumentationDescriptor#adviceConfigs() adviceConfigs}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of adviceConfigs elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableInstrumentationDescriptor withAdviceConfigs(Iterable extends AdviceConfig> elements) {
if (this.adviceConfigs == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableInstrumentationDescriptor(this.id, this.name, this.properties, newValue, this.classes, this.collocate, this.jarFile);
}
/**
* Copy the current immutable object with elements that replace the content of {@link InstrumentationDescriptor#classes() classes}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableInstrumentationDescriptor withClasses(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableInstrumentationDescriptor(this.id, this.name, this.properties, this.adviceConfigs, newValue, this.collocate, this.jarFile);
}
/**
* Copy the current immutable object with elements that replace the content of {@link InstrumentationDescriptor#classes() classes}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of classes elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableInstrumentationDescriptor withClasses(Iterable elements) {
if (this.classes == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableInstrumentationDescriptor(this.id, this.name, this.properties, this.adviceConfigs, newValue, this.collocate, this.jarFile);
}
/**
* Copy the current immutable object by setting a value for the {@link InstrumentationDescriptor#collocate() collocate} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for collocate
* @return A modified copy of the {@code this} object
*/
public final ImmutableInstrumentationDescriptor withCollocate(boolean value) {
if (this.collocate == value) return this;
return new ImmutableInstrumentationDescriptor(this.id, this.name, this.properties, this.adviceConfigs, this.classes, value, this.jarFile);
}
/**
* Copy the current immutable object by setting a value for the {@link InstrumentationDescriptor#jarFile() jarFile} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for jarFile (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableInstrumentationDescriptor withJarFile(@Nullable File value) {
if (this.jarFile == value) return this;
return new ImmutableInstrumentationDescriptor(this.id, this.name, this.properties, this.adviceConfigs, this.classes, this.collocate, value);
}
/**
* This instance is equal to all instances of {@code ImmutableInstrumentationDescriptor} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(Object another) {
if (this == another) return true;
return another instanceof ImmutableInstrumentationDescriptor
&& equalTo((ImmutableInstrumentationDescriptor) another);
}
private boolean equalTo(ImmutableInstrumentationDescriptor another) {
return id.equals(another.id)
&& name.equals(another.name)
&& properties.equals(another.properties)
&& adviceConfigs.equals(another.adviceConfigs)
&& classes.equals(another.classes)
&& collocate == another.collocate
&& Objects.equal(jarFile, another.jarFile);
}
/**
* Computes a hash code from attributes: {@code id}, {@code name}, {@code properties}, {@code adviceConfigs}, {@code classes}, {@code collocate}, {@code jarFile}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + id.hashCode();
h += (h << 5) + name.hashCode();
h += (h << 5) + properties.hashCode();
h += (h << 5) + adviceConfigs.hashCode();
h += (h << 5) + classes.hashCode();
h += (h << 5) + Booleans.hashCode(collocate);
h += (h << 5) + Objects.hashCode(jarFile);
return h;
}
/**
* Prints the immutable value {@code InstrumentationDescriptor} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("InstrumentationDescriptor")
.omitNullValues()
.add("id", id)
.add("name", name)
.add("properties", properties)
.add("adviceConfigs", adviceConfigs)
.add("classes", classes)
.add("collocate", collocate)
.add("jarFile", jarFile)
.toString();
}
/**
* Creates an immutable copy of a {@link InstrumentationDescriptor} 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 InstrumentationDescriptor instance
*/
public static ImmutableInstrumentationDescriptor copyOf(InstrumentationDescriptor instance) {
if (instance instanceof ImmutableInstrumentationDescriptor) {
return (ImmutableInstrumentationDescriptor) instance;
}
return ImmutableInstrumentationDescriptor.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableInstrumentationDescriptor ImmutableInstrumentationDescriptor}.
*
* ImmutableInstrumentationDescriptor.builder()
* .id(String) // required {@link InstrumentationDescriptor#id() id}
* .name(String) // required {@link InstrumentationDescriptor#name() name}
* .addProperties|addAllProperties(org.glowroot.instrumentation.engine.config.PropertyDescriptor) // {@link InstrumentationDescriptor#properties() properties} elements
* .addAdviceConfigs|addAllAdviceConfigs(org.glowroot.instrumentation.engine.config.AdviceConfig) // {@link InstrumentationDescriptor#adviceConfigs() adviceConfigs} elements
* .addClasses|addAllClasses(String) // {@link InstrumentationDescriptor#classes() classes} elements
* .collocate(boolean) // optional {@link InstrumentationDescriptor#collocate() collocate}
* .jarFile(java.io.File | null) // nullable {@link InstrumentationDescriptor#jarFile() jarFile}
* .build();
*
* @return A new ImmutableInstrumentationDescriptor builder
*/
public static ImmutableInstrumentationDescriptor.Builder builder() {
return new ImmutableInstrumentationDescriptor.Builder();
}
/**
* Builds instances of type {@link ImmutableInstrumentationDescriptor ImmutableInstrumentationDescriptor}.
* 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.
*/
@Generated(from = "InstrumentationDescriptor", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_ID = 0x1L;
private static final long INIT_BIT_NAME = 0x2L;
private static final long OPT_BIT_COLLOCATE = 0x1L;
private long initBits = 0x3L;
private long optBits;
private String id;
private String name;
private ImmutableList.Builder properties = ImmutableList.builder();
private ImmutableList.Builder adviceConfigs = ImmutableList.builder();
private ImmutableList.Builder classes = ImmutableList.builder();
private boolean collocate;
private File jarFile;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code InstrumentationDescriptor} 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
*/
public final Builder from(InstrumentationDescriptor instance) {
Preconditions.checkNotNull(instance, "instance");
id(instance.id());
name(instance.name());
addAllProperties(instance.properties());
addAllAdviceConfigs(instance.adviceConfigs());
addAllClasses(instance.classes());
collocate(instance.collocate());
@Nullable File jarFileValue = instance.jarFile();
if (jarFileValue != null) {
jarFile(jarFileValue);
}
return this;
}
/**
* Initializes the value for the {@link InstrumentationDescriptor#id() id} attribute.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/
public final Builder id(String id) {
this.id = Preconditions.checkNotNull(id, "id");
initBits &= ~INIT_BIT_ID;
return this;
}
/**
* Initializes the value for the {@link InstrumentationDescriptor#name() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
public final Builder name(String name) {
this.name = Preconditions.checkNotNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Adds one element to {@link InstrumentationDescriptor#properties() properties} list.
* @param element A properties element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addProperties(PropertyDescriptor element) {
this.properties.add(element);
return this;
}
/**
* Adds elements to {@link InstrumentationDescriptor#properties() properties} list.
* @param elements An array of properties elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addProperties(PropertyDescriptor... elements) {
this.properties.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link InstrumentationDescriptor#properties() properties} list.
* @param elements An iterable of properties elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder properties(Iterable extends PropertyDescriptor> elements) {
this.properties = ImmutableList.builder();
return addAllProperties(elements);
}
/**
* Adds elements to {@link InstrumentationDescriptor#properties() properties} list.
* @param elements An iterable of properties elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllProperties(Iterable extends PropertyDescriptor> elements) {
this.properties.addAll(elements);
return this;
}
/**
* Adds one element to {@link InstrumentationDescriptor#adviceConfigs() adviceConfigs} list.
* @param element A adviceConfigs element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAdviceConfigs(AdviceConfig element) {
this.adviceConfigs.add(element);
return this;
}
/**
* Adds elements to {@link InstrumentationDescriptor#adviceConfigs() adviceConfigs} list.
* @param elements An array of adviceConfigs elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAdviceConfigs(AdviceConfig... elements) {
this.adviceConfigs.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link InstrumentationDescriptor#adviceConfigs() adviceConfigs} list.
* @param elements An iterable of adviceConfigs elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder adviceConfigs(Iterable extends AdviceConfig> elements) {
this.adviceConfigs = ImmutableList.builder();
return addAllAdviceConfigs(elements);
}
/**
* Adds elements to {@link InstrumentationDescriptor#adviceConfigs() adviceConfigs} list.
* @param elements An iterable of adviceConfigs elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllAdviceConfigs(Iterable extends AdviceConfig> elements) {
this.adviceConfigs.addAll(elements);
return this;
}
/**
* Adds one element to {@link InstrumentationDescriptor#classes() classes} list.
* @param element A classes element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addClasses(String element) {
this.classes.add(element);
return this;
}
/**
* Adds elements to {@link InstrumentationDescriptor#classes() classes} list.
* @param elements An array of classes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addClasses(String... elements) {
this.classes.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link InstrumentationDescriptor#classes() classes} list.
* @param elements An iterable of classes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder classes(Iterable elements) {
this.classes = ImmutableList.builder();
return addAllClasses(elements);
}
/**
* Adds elements to {@link InstrumentationDescriptor#classes() classes} list.
* @param elements An iterable of classes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllClasses(Iterable elements) {
this.classes.addAll(elements);
return this;
}
/**
* Initializes the value for the {@link InstrumentationDescriptor#collocate() collocate} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link InstrumentationDescriptor#collocate() collocate}.
* @param collocate The value for collocate
* @return {@code this} builder for use in a chained invocation
*/
public final Builder collocate(boolean collocate) {
this.collocate = collocate;
optBits |= OPT_BIT_COLLOCATE;
return this;
}
/**
* Initializes the value for the {@link InstrumentationDescriptor#jarFile() jarFile} attribute.
* @param jarFile The value for jarFile (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder jarFile(@Nullable File jarFile) {
this.jarFile = jarFile;
return this;
}
/**
* Builds a new {@link ImmutableInstrumentationDescriptor ImmutableInstrumentationDescriptor}.
* @return An immutable instance of InstrumentationDescriptor
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableInstrumentationDescriptor build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableInstrumentationDescriptor(this);
}
private boolean collocateIsSet() {
return (optBits & OPT_BIT_COLLOCATE) != 0;
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_ID) != 0) attributes.add("id");
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
return "Cannot build InstrumentationDescriptor, some of required attributes are not set " + attributes;
}
}
}