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