![JAR search and dependency download from the Maven repository](/logo.png)
org.glowroot.instrumentation.engine.weaving.ImmutableAnalyzedMethodKey Maven / Gradle / Ivy
package org.glowroot.instrumentation.engine.weaving;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.base.MoreObjects;
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 java.util.ArrayList;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link ClassAnalyzer.AnalyzedMethodKey}.
*
* Use the builder to create immutable instances:
* {@code ImmutableAnalyzedMethodKey.builder()}.
*/
@Generated(from = "ClassAnalyzer.AnalyzedMethodKey", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
final class ImmutableAnalyzedMethodKey
extends ClassAnalyzer.AnalyzedMethodKey {
private final String name;
private final ImmutableList parameterTypes;
private final @Nullable AnalyzedMethod analyzedMethod;
private ImmutableAnalyzedMethodKey(
String name,
ImmutableList parameterTypes,
@Nullable AnalyzedMethod analyzedMethod) {
this.name = name;
this.parameterTypes = parameterTypes;
this.analyzedMethod = analyzedMethod;
}
/**
* @return The value of the {@code name} attribute
*/
@Override
String name() {
return name;
}
/**
* @return The value of the {@code parameterTypes} attribute
*/
@Override
ImmutableList parameterTypes() {
return parameterTypes;
}
/**
* @return The value of the {@code analyzedMethod} attribute
*/
@Override
@Nullable AnalyzedMethod analyzedMethod() {
return analyzedMethod;
}
/**
* Copy the current immutable object by setting a value for the {@link ClassAnalyzer.AnalyzedMethodKey#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 ImmutableAnalyzedMethodKey withName(String value) {
String newValue = Preconditions.checkNotNull(value, "name");
if (this.name.equals(newValue)) return this;
return new ImmutableAnalyzedMethodKey(newValue, this.parameterTypes, this.analyzedMethod);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ClassAnalyzer.AnalyzedMethodKey#parameterTypes() parameterTypes}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableAnalyzedMethodKey withParameterTypes(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAnalyzedMethodKey(this.name, newValue, this.analyzedMethod);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ClassAnalyzer.AnalyzedMethodKey#parameterTypes() parameterTypes}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of parameterTypes elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableAnalyzedMethodKey withParameterTypes(Iterable elements) {
if (this.parameterTypes == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableAnalyzedMethodKey(this.name, newValue, this.analyzedMethod);
}
/**
* Copy the current immutable object by setting a value for the {@link ClassAnalyzer.AnalyzedMethodKey#analyzedMethod() analyzedMethod} 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 analyzedMethod (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableAnalyzedMethodKey withAnalyzedMethod(@Nullable AnalyzedMethod value) {
if (this.analyzedMethod == value) return this;
return new ImmutableAnalyzedMethodKey(this.name, this.parameterTypes, value);
}
/**
* This instance is equal to all instances of {@code ImmutableAnalyzedMethodKey} 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 ImmutableAnalyzedMethodKey
&& equalTo((ImmutableAnalyzedMethodKey) another);
}
private boolean equalTo(ImmutableAnalyzedMethodKey another) {
return name.equals(another.name)
&& parameterTypes.equals(another.parameterTypes);
}
/**
* Computes a hash code from attributes: {@code name}, {@code parameterTypes}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + name.hashCode();
h += (h << 5) + parameterTypes.hashCode();
return h;
}
/**
* Prints the immutable value {@code AnalyzedMethodKey} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("AnalyzedMethodKey")
.omitNullValues()
.add("name", name)
.add("parameterTypes", parameterTypes)
.toString();
}
/**
* Creates an immutable copy of a {@link ClassAnalyzer.AnalyzedMethodKey} 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 AnalyzedMethodKey instance
*/
public static ImmutableAnalyzedMethodKey copyOf(ClassAnalyzer.AnalyzedMethodKey instance) {
if (instance instanceof ImmutableAnalyzedMethodKey) {
return (ImmutableAnalyzedMethodKey) instance;
}
return ImmutableAnalyzedMethodKey.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableAnalyzedMethodKey ImmutableAnalyzedMethodKey}.
*
* ImmutableAnalyzedMethodKey.builder()
* .name(String) // required {@link ClassAnalyzer.AnalyzedMethodKey#name() name}
* .addParameterTypes|addAllParameterTypes(String) // {@link ClassAnalyzer.AnalyzedMethodKey#parameterTypes() parameterTypes} elements
* .analyzedMethod(org.glowroot.instrumentation.engine.weaving.AnalyzedMethod | null) // nullable {@link ClassAnalyzer.AnalyzedMethodKey#analyzedMethod() analyzedMethod}
* .build();
*
* @return A new ImmutableAnalyzedMethodKey builder
*/
public static ImmutableAnalyzedMethodKey.Builder builder() {
return new ImmutableAnalyzedMethodKey.Builder();
}
/**
* Builds instances of type {@link ImmutableAnalyzedMethodKey ImmutableAnalyzedMethodKey}.
* 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 = "ClassAnalyzer.AnalyzedMethodKey", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private long initBits = 0x1L;
private String name;
private ImmutableList.Builder parameterTypes = ImmutableList.builder();
private AnalyzedMethod analyzedMethod;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code AnalyzedMethodKey} 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(ClassAnalyzer.AnalyzedMethodKey instance) {
Preconditions.checkNotNull(instance, "instance");
name(instance.name());
addAllParameterTypes(instance.parameterTypes());
@Nullable AnalyzedMethod analyzedMethodValue = instance.analyzedMethod();
if (analyzedMethodValue != null) {
analyzedMethod(analyzedMethodValue);
}
return this;
}
/**
* Initializes the value for the {@link ClassAnalyzer.AnalyzedMethodKey#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 ClassAnalyzer.AnalyzedMethodKey#parameterTypes() parameterTypes} list.
* @param element A parameterTypes element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addParameterTypes(String element) {
this.parameterTypes.add(element);
return this;
}
/**
* Adds elements to {@link ClassAnalyzer.AnalyzedMethodKey#parameterTypes() parameterTypes} list.
* @param elements An array of parameterTypes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addParameterTypes(String... elements) {
this.parameterTypes.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link ClassAnalyzer.AnalyzedMethodKey#parameterTypes() parameterTypes} list.
* @param elements An iterable of parameterTypes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder parameterTypes(Iterable elements) {
this.parameterTypes = ImmutableList.builder();
return addAllParameterTypes(elements);
}
/**
* Adds elements to {@link ClassAnalyzer.AnalyzedMethodKey#parameterTypes() parameterTypes} list.
* @param elements An iterable of parameterTypes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllParameterTypes(Iterable elements) {
this.parameterTypes.addAll(elements);
return this;
}
/**
* Initializes the value for the {@link ClassAnalyzer.AnalyzedMethodKey#analyzedMethod() analyzedMethod} attribute.
* @param analyzedMethod The value for analyzedMethod (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder analyzedMethod(@Nullable AnalyzedMethod analyzedMethod) {
this.analyzedMethod = analyzedMethod;
return this;
}
/**
* Builds a new {@link ImmutableAnalyzedMethodKey ImmutableAnalyzedMethodKey}.
* @return An immutable instance of AnalyzedMethodKey
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableAnalyzedMethodKey build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableAnalyzedMethodKey(name, parameterTypes.build(), analyzedMethod);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
return "Cannot build AnalyzedMethodKey, some of required attributes are not set " + attributes;
}
}
}