
org.glowroot.agent.weaving.ImmutableAdviceParameter Maven / Gradle / Ivy
package org.glowroot.agent.weaving;
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.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;
import org.glowroot.agent.shaded.objectweb.asm.Type;
/**
* Immutable implementation of {@link Advice.AdviceParameter}.
*
* Use builder to create immutable instances:
* {@code ImmutableAdviceParameter.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "Advice.AdviceParameter"})
@Immutable
final class ImmutableAdviceParameter implements Advice.AdviceParameter {
private final ParameterKind kind;
private final Type type;
private ImmutableAdviceParameter(ParameterKind kind, Type type) {
this.kind = kind;
this.type = type;
}
/**
* @return value of {@code kind} attribute
*/
@JsonProperty
@Override
public ParameterKind kind() {
return kind;
}
/**
* @return value of {@code type} attribute
*/
@JsonProperty
@Override
public Type type() {
return type;
}
/**
* Copy current immutable object by setting value for {@link Advice.AdviceParameter#kind() kind}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for kind
* @return modified copy of the {@code this} object
*/
public final ImmutableAdviceParameter withKind(ParameterKind value) {
if (this.kind == value) return this;
ParameterKind newValue = Preconditions.checkNotNull(value);
return new ImmutableAdviceParameter(newValue, this.type);
}
/**
* Copy current immutable object by setting value for {@link Advice.AdviceParameter#type() type}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for type
* @return modified copy of the {@code this} object
*/
public final ImmutableAdviceParameter withType(Type value) {
if (this.type == value) return this;
Type newValue = Preconditions.checkNotNull(value);
return new ImmutableAdviceParameter(this.kind, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableAdviceParameter} 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 ImmutableAdviceParameter
&& equalTo((ImmutableAdviceParameter) another);
}
private boolean equalTo(ImmutableAdviceParameter another) {
return kind.equals(another.kind)
&& type.equals(another.type);
}
/**
* Computes hash code from attributes: {@code kind}, {@code type}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + kind.hashCode();
h = h * 17 + type.hashCode();
return h;
}
/**
* Prints immutable value {@code AdviceParameter...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("AdviceParameter")
.add("kind", kind)
.add("type", type)
.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 ParameterKind kind;
@JsonProperty
@Nullable Type type;
}
/**
* @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 ImmutableAdviceParameter fromJson(Json json) {
ImmutableAdviceParameter.Builder builder = ImmutableAdviceParameter.builder();
if (json.kind != null) {
builder.kind(json.kind);
}
if (json.type != null) {
builder.type(json.type);
}
return builder.build();
}
/**
* Creates immutable copy of {@link Advice.AdviceParameter}.
* 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 AdviceParameter instance
*/
static ImmutableAdviceParameter copyOf(Advice.AdviceParameter instance) {
if (instance instanceof ImmutableAdviceParameter) {
return (ImmutableAdviceParameter) instance;
}
return ImmutableAdviceParameter.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.agent.weaving.ImmutableAdviceParameter ImmutableAdviceParameter}.
* @return new ImmutableAdviceParameter builder
*/
static ImmutableAdviceParameter.Builder builder() {
return new ImmutableAdviceParameter.Builder();
}
/**
* Builds instances of {@link org.glowroot.agent.weaving.ImmutableAdviceParameter ImmutableAdviceParameter}.
* 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_KIND = 0x1L;
private static final long INIT_BIT_TYPE = 0x2L;
private long initBits = 0x3;
private @Nullable ParameterKind kind;
private @Nullable Type type;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link Advice.AdviceParameter} instance.
* Regular attribute values will be replaced with ones of an instance.
* Instance's absent optional values will not replace present values.
* @param instance instance to copy values from
* @return {@code this} builder for chained invocation
*/
public final Builder copyFrom(Advice.AdviceParameter instance) {
Preconditions.checkNotNull(instance);
kind(instance.kind());
type(instance.type());
return this;
}
/**
* Initializes value for {@link Advice.AdviceParameter#kind() kind}.
* @param kind value for kind
* @return {@code this} builder for chained invocation
*/
public final Builder kind(ParameterKind kind) {
this.kind = Preconditions.checkNotNull(kind);
initBits &= ~INIT_BIT_KIND;
return this;
}
/**
* Initializes value for {@link Advice.AdviceParameter#type() type}.
* @param type value for type
* @return {@code this} builder for chained invocation
*/
public final Builder type(Type type) {
this.type = Preconditions.checkNotNull(type);
initBits &= ~INIT_BIT_TYPE;
return this;
}
/**
* Builds new {@link org.glowroot.agent.weaving.ImmutableAdviceParameter ImmutableAdviceParameter}.
* @return immutable instance of AdviceParameter
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableAdviceParameter build()
throws IllegalStateException {
checkRequiredAttributes(); return new ImmutableAdviceParameter(kind, type);
}
private boolean kindIsSet() {
return (initBits & INIT_BIT_KIND) == 0;
}
private boolean typeIsSet() {
return (initBits & INIT_BIT_TYPE) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!kindIsSet()) attributes.add("kind");
if (!typeIsSet()) attributes.add("type");
return "Cannot build AdviceParameter, some of required attributes are not set " + attributes;
}
}
}