org.glowroot.instrumentation.engine.weaving.ImmutablePublicFinalMethod 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.immutables.value.Generated;
/**
* Immutable implementation of {@link PublicFinalMethod}.
*
* Use the builder to create immutable instances:
* {@code ImmutablePublicFinalMethod.builder()}.
*/
@Generated(from = "PublicFinalMethod", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
final class ImmutablePublicFinalMethod
extends PublicFinalMethod {
private final String name;
private final ImmutableList parameterTypes;
private ImmutablePublicFinalMethod(String name, ImmutableList parameterTypes) {
this.name = name;
this.parameterTypes = parameterTypes;
}
/**
* @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;
}
/**
* Copy the current immutable object by setting a value for the {@link PublicFinalMethod#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 ImmutablePublicFinalMethod withName(String value) {
String newValue = Preconditions.checkNotNull(value, "name");
if (this.name.equals(newValue)) return this;
return new ImmutablePublicFinalMethod(newValue, this.parameterTypes);
}
/**
* Copy the current immutable object with elements that replace the content of {@link PublicFinalMethod#parameterTypes() parameterTypes}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutablePublicFinalMethod withParameterTypes(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePublicFinalMethod(this.name, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link PublicFinalMethod#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 ImmutablePublicFinalMethod withParameterTypes(Iterable elements) {
if (this.parameterTypes == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePublicFinalMethod(this.name, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutablePublicFinalMethod} 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 ImmutablePublicFinalMethod
&& equalTo((ImmutablePublicFinalMethod) another);
}
private boolean equalTo(ImmutablePublicFinalMethod 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 PublicFinalMethod} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("PublicFinalMethod")
.omitNullValues()
.add("name", name)
.add("parameterTypes", parameterTypes)
.toString();
}
/**
* Creates an immutable copy of a {@link PublicFinalMethod} 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 PublicFinalMethod instance
*/
public static ImmutablePublicFinalMethod copyOf(PublicFinalMethod instance) {
if (instance instanceof ImmutablePublicFinalMethod) {
return (ImmutablePublicFinalMethod) instance;
}
return ImmutablePublicFinalMethod.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutablePublicFinalMethod ImmutablePublicFinalMethod}.
*
* ImmutablePublicFinalMethod.builder()
* .name(String) // required {@link PublicFinalMethod#name() name}
* .addParameterTypes|addAllParameterTypes(String) // {@link PublicFinalMethod#parameterTypes() parameterTypes} elements
* .build();
*
* @return A new ImmutablePublicFinalMethod builder
*/
public static ImmutablePublicFinalMethod.Builder builder() {
return new ImmutablePublicFinalMethod.Builder();
}
/**
* Builds instances of type {@link ImmutablePublicFinalMethod ImmutablePublicFinalMethod}.
* 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 = "PublicFinalMethod", 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 Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code PublicFinalMethod} 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(PublicFinalMethod instance) {
Preconditions.checkNotNull(instance, "instance");
name(instance.name());
addAllParameterTypes(instance.parameterTypes());
return this;
}
/**
* Initializes the value for the {@link PublicFinalMethod#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 PublicFinalMethod#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 PublicFinalMethod#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 PublicFinalMethod#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 PublicFinalMethod#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;
}
/**
* Builds a new {@link ImmutablePublicFinalMethod ImmutablePublicFinalMethod}.
* @return An immutable instance of PublicFinalMethod
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutablePublicFinalMethod build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutablePublicFinalMethod(name, parameterTypes.build());
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
return "Cannot build PublicFinalMethod, some of required attributes are not set " + attributes;
}
}
}