
org.glowroot.agent.live.ImmutableUiAnalyzedMethod Maven / Gradle / Ivy
package org.glowroot.agent.live;
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.Objects;
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 ClasspathCache.UiAnalyzedMethod}.
*
* Use builder to create immutable instances:
* {@code ImmutableUiAnalyzedMethod.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ClasspathCache.UiAnalyzedMethod"})
@Immutable
final class ImmutableUiAnalyzedMethod
implements ClasspathCache.UiAnalyzedMethod {
private final String name;
private final ImmutableList parameterTypes;
private final String returnType;
private final int modifiers;
private final @Nullable String signature;
private final ImmutableList exceptions;
private final int hashCode;
private ImmutableUiAnalyzedMethod(
String name,
ImmutableList parameterTypes,
String returnType,
int modifiers,
@Nullable String signature,
ImmutableList exceptions) {
this.name = name;
this.parameterTypes = parameterTypes;
this.returnType = returnType;
this.modifiers = modifiers;
this.signature = signature;
this.exceptions = exceptions;
this.hashCode = computeHashCode();
}
/**
* @return value of {@code name} attribute
*/
@JsonProperty
@Override
public String name() {
return name;
}
/**
* @return value of {@code parameterTypes} attribute
*/
@JsonProperty
@Override
public ImmutableList parameterTypes() {
return parameterTypes;
}
/**
* @return value of {@code returnType} attribute
*/
@JsonProperty
@Override
public String returnType() {
return returnType;
}
/**
* @return value of {@code modifiers} attribute
*/
@JsonProperty
@Override
public int modifiers() {
return modifiers;
}
/**
* @return value of {@code signature} attribute
*/
@JsonProperty
@Override
public @Nullable String signature() {
return signature;
}
/**
* @return value of {@code exceptions} attribute
*/
@JsonProperty
@Override
public ImmutableList exceptions() {
return exceptions;
}
/**
* Copy current immutable object by setting value for {@link ClasspathCache.UiAnalyzedMethod#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 ImmutableUiAnalyzedMethod withName(String value) {
if (this.name == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableUiAnalyzedMethod(newValue, this.parameterTypes, this.returnType, this.modifiers, this.signature, this.exceptions);
}
/**
* Copy current immutable object with elements that replace content of {@link ClasspathCache.UiAnalyzedMethod#parameterTypes() parameterTypes}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableUiAnalyzedMethod withParameterTypes(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableUiAnalyzedMethod(this.name, newValue, this.returnType, this.modifiers, this.signature, this.exceptions);
}
/**
* Copy current immutable object with elements that replace content of {@link ClasspathCache.UiAnalyzedMethod#parameterTypes() parameterTypes}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of parameterTypes elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableUiAnalyzedMethod withParameterTypes(Iterable elements) {
if (this.parameterTypes == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableUiAnalyzedMethod(this.name, newValue, this.returnType, this.modifiers, this.signature, this.exceptions);
}
/**
* Copy current immutable object by setting value for {@link ClasspathCache.UiAnalyzedMethod#returnType() returnType}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for returnType
* @return modified copy of the {@code this} object
*/
public final ImmutableUiAnalyzedMethod withReturnType(String value) {
if (this.returnType == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableUiAnalyzedMethod(this.name, this.parameterTypes, newValue, this.modifiers, this.signature, this.exceptions);
}
/**
* Copy current immutable object by setting value for {@link ClasspathCache.UiAnalyzedMethod#modifiers() modifiers}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for modifiers
* @return modified copy of the {@code this} object
*/
public final ImmutableUiAnalyzedMethod withModifiers(int value) {
if (this.modifiers == value) return this;
int newValue = value;
return new ImmutableUiAnalyzedMethod(this.name, this.parameterTypes, this.returnType, newValue, this.signature, this.exceptions);
}
/**
* Copy current immutable object by setting value for {@link ClasspathCache.UiAnalyzedMethod#signature() signature}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for signature, can be {@code null}
* @return modified copy of the {@code this} object
*/
public final ImmutableUiAnalyzedMethod withSignature(@Nullable String value) {
if (this.signature == value) return this;
@Nullable String newValue = value;
return new ImmutableUiAnalyzedMethod(this.name, this.parameterTypes, this.returnType, this.modifiers, newValue, this.exceptions);
}
/**
* Copy current immutable object with elements that replace content of {@link ClasspathCache.UiAnalyzedMethod#exceptions() exceptions}.
* @param elements elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableUiAnalyzedMethod withExceptions(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableUiAnalyzedMethod(this.name, this.parameterTypes, this.returnType, this.modifiers, this.signature, newValue);
}
/**
* Copy current immutable object with elements that replace content of {@link ClasspathCache.UiAnalyzedMethod#exceptions() exceptions}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements iterable of exceptions elements to set
* @return modified copy of {@code this} object
*/
public final ImmutableUiAnalyzedMethod withExceptions(Iterable elements) {
if (this.exceptions == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableUiAnalyzedMethod(this.name, this.parameterTypes, this.returnType, this.modifiers, this.signature, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableUiAnalyzedMethod} 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 ImmutableUiAnalyzedMethod
&& equalTo((ImmutableUiAnalyzedMethod) another);
}
private boolean equalTo(ImmutableUiAnalyzedMethod another) {
return name.equals(another.name)
&& parameterTypes.equals(another.parameterTypes)
&& returnType.equals(another.returnType)
&& modifiers == another.modifiers
&& Objects.equal(signature, another.signature)
&& exceptions.equals(another.exceptions);
}
/**
* Returns precomputed on construction hash code from attributes: {@code name}, {@code parameterTypes}, {@code returnType}, {@code modifiers}, {@code signature}, {@code exceptions}.
* @return hashCode value
*/
@Override
public int hashCode() {
return hashCode;
}
private int computeHashCode() {
int h = 31;
h = h * 17 + name.hashCode();
h = h * 17 + parameterTypes.hashCode();
h = h * 17 + returnType.hashCode();
h = h * 17 + modifiers;
h = h * 17 + Objects.hashCode(signature);
h = h * 17 + exceptions.hashCode();
return h;
}
/**
* Prints immutable value {@code UiAnalyzedMethod...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("UiAnalyzedMethod")
.add("name", name)
.add("parameterTypes", parameterTypes)
.add("returnType", returnType)
.add("modifiers", modifiers)
.add("signature", signature)
.add("exceptions", exceptions)
.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 ImmutableList parameterTypes;
@JsonProperty
@Nullable String returnType;
@JsonProperty
@Nullable Integer modifiers;
@JsonProperty
@Nullable String signature;
@JsonProperty
@Nullable ImmutableList exceptions;
}
/**
* @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 ImmutableUiAnalyzedMethod fromJson(Json json) {
ImmutableUiAnalyzedMethod.Builder builder = ImmutableUiAnalyzedMethod.builder();
if (json.name != null) {
builder.name(json.name);
}
if (json.parameterTypes != null) {
builder.addAllParameterTypes(json.parameterTypes);
}
if (json.returnType != null) {
builder.returnType(json.returnType);
}
if (json.modifiers != null) {
builder.modifiers(json.modifiers);
}
if (json.signature != null) {
builder.signature(json.signature);
}
if (json.exceptions != null) {
builder.addAllExceptions(json.exceptions);
}
return builder.build();
}
/**
* Creates immutable copy of {@link ClasspathCache.UiAnalyzedMethod}.
* 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 UiAnalyzedMethod instance
*/
static ImmutableUiAnalyzedMethod copyOf(ClasspathCache.UiAnalyzedMethod instance) {
if (instance instanceof ImmutableUiAnalyzedMethod) {
return (ImmutableUiAnalyzedMethod) instance;
}
return ImmutableUiAnalyzedMethod.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.agent.live.ImmutableUiAnalyzedMethod ImmutableUiAnalyzedMethod}.
* @return new ImmutableUiAnalyzedMethod builder
*/
static ImmutableUiAnalyzedMethod.Builder builder() {
return new ImmutableUiAnalyzedMethod.Builder();
}
/**
* Builds instances of {@link org.glowroot.agent.live.ImmutableUiAnalyzedMethod ImmutableUiAnalyzedMethod}.
* 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_NAME = 0x1L;
private static final long INIT_BIT_RETURN_TYPE = 0x2L;
private static final long INIT_BIT_MODIFIERS = 0x4L;
private long initBits = 0x7;
private @Nullable String name;
private ImmutableList.Builder parameterTypesBuilder = ImmutableList.builder();
private @Nullable String returnType;
private int modifiers;
private @Nullable String signature;
private ImmutableList.Builder exceptionsBuilder = ImmutableList.builder();
private Builder() {}
/**
* Fill builder with attribute values from provided {@link ClasspathCache.UiAnalyzedMethod} 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(ClasspathCache.UiAnalyzedMethod instance) {
Preconditions.checkNotNull(instance);
name(instance.name());
addAllParameterTypes(instance.parameterTypes());
returnType(instance.returnType());
modifiers(instance.modifiers());
@Nullable String signatureValue = instance.signature();
if (signatureValue != null) {
signature(signatureValue);
}
addAllExceptions(instance.exceptions());
return this;
}
/**
* Initializes value for {@link ClasspathCache.UiAnalyzedMethod#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;
}
/**
* Adds one element to {@link ClasspathCache.UiAnalyzedMethod#parameterTypes() parameterTypes} list.
* @param element parameterTypes element
* @return {@code this} builder for chained invocation
*/
public final Builder addParameterTypes(String element) {
parameterTypesBuilder.add(element);
return this;
}
/**
* Adds elements to {@link ClasspathCache.UiAnalyzedMethod#parameterTypes() parameterTypes} list.
* @param elements array of parameterTypes elements
* @return {@code this} builder for chained invocation
*/
public final Builder addParameterTypes(String... elements) {
parameterTypesBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link ClasspathCache.UiAnalyzedMethod#parameterTypes() parameterTypes} list.
* @param elements iterable of parameterTypes elements
* @return {@code this} builder for chained invocation
*/
public final Builder parameterTypes(Iterable elements) {
parameterTypesBuilder = ImmutableList.builder();
return addAllParameterTypes(elements);
}
/**
* Adds elements to {@link ClasspathCache.UiAnalyzedMethod#parameterTypes() parameterTypes} list.
* @param elements iterable of parameterTypes elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllParameterTypes(Iterable elements) {
parameterTypesBuilder.addAll(elements);
return this;
}
/**
* Initializes value for {@link ClasspathCache.UiAnalyzedMethod#returnType() returnType}.
* @param returnType value for returnType
* @return {@code this} builder for chained invocation
*/
public final Builder returnType(String returnType) {
this.returnType = Preconditions.checkNotNull(returnType);
initBits &= ~INIT_BIT_RETURN_TYPE;
return this;
}
/**
* Initializes value for {@link ClasspathCache.UiAnalyzedMethod#modifiers() modifiers}.
* @param modifiers value for modifiers
* @return {@code this} builder for chained invocation
*/
public final Builder modifiers(int modifiers) {
this.modifiers = modifiers;
initBits &= ~INIT_BIT_MODIFIERS;
return this;
}
/**
* Initializes value for {@link ClasspathCache.UiAnalyzedMethod#signature() signature}.
* @param signature value for signature, can be {@code null}
* @return {@code this} builder for chained invocation
*/
public final Builder signature(@Nullable String signature) {
this.signature = signature;
return this;
}
/**
* Adds one element to {@link ClasspathCache.UiAnalyzedMethod#exceptions() exceptions} list.
* @param element exceptions element
* @return {@code this} builder for chained invocation
*/
public final Builder addExceptions(String element) {
exceptionsBuilder.add(element);
return this;
}
/**
* Adds elements to {@link ClasspathCache.UiAnalyzedMethod#exceptions() exceptions} list.
* @param elements array of exceptions elements
* @return {@code this} builder for chained invocation
*/
public final Builder addExceptions(String... elements) {
exceptionsBuilder.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link ClasspathCache.UiAnalyzedMethod#exceptions() exceptions} list.
* @param elements iterable of exceptions elements
* @return {@code this} builder for chained invocation
*/
public final Builder exceptions(Iterable elements) {
exceptionsBuilder = ImmutableList.builder();
return addAllExceptions(elements);
}
/**
* Adds elements to {@link ClasspathCache.UiAnalyzedMethod#exceptions() exceptions} list.
* @param elements iterable of exceptions elements
* @return {@code this} builder for chained invocation
*/
public final Builder addAllExceptions(Iterable elements) {
exceptionsBuilder.addAll(elements);
return this;
}
/**
* Builds new {@link org.glowroot.agent.live.ImmutableUiAnalyzedMethod ImmutableUiAnalyzedMethod}.
* @return immutable instance of UiAnalyzedMethod
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableUiAnalyzedMethod build()
throws IllegalStateException {
checkRequiredAttributes();
return new ImmutableUiAnalyzedMethod(
name,
parameterTypesBuilder.build(),
returnType,
modifiers,
signature,
exceptionsBuilder.build());
}
private boolean nameIsSet() {
return (initBits & INIT_BIT_NAME) == 0;
}
private boolean returnTypeIsSet() {
return (initBits & INIT_BIT_RETURN_TYPE) == 0;
}
private boolean modifiersIsSet() {
return (initBits & INIT_BIT_MODIFIERS) == 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 (!returnTypeIsSet()) attributes.add("returnType");
if (!modifiersIsSet()) attributes.add("modifiers");
return "Cannot build UiAnalyzedMethod, some of required attributes are not set " + attributes;
}
}
}