org.glowroot.weaving.AdviceParameter Maven / Gradle / Ivy
package org.glowroot.weaving;
import org.glowroot.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.shaded.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.shaded.google.common.base.MoreObjects;
import org.glowroot.shaded.google.common.base.Preconditions;
import org.glowroot.shaded.google.common.collect.Lists;
import java.util.Collection;
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.shaded.objectweb.asm.Type;
/**
* Immutable implementation of {@link AdviceBase.AdviceParameterBase}.
*
* Use builder to create immutable instances:
* {@code AdviceParameter.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "AdviceBase.AdviceParameterBase"})
@Immutable
final class AdviceParameter extends AdviceBase.AdviceParameterBase {
private final ParameterKind kind;
private final Type type;
private AdviceParameter(ParameterKind kind, Type type) {
this.kind = kind;
this.type = type;
}
/**
* {@inheritDoc}
* @return value of {@code kind} attribute
*/
@JsonProperty("kind")
@Override
public ParameterKind kind() {
return kind;
}
/**
* {@inheritDoc}
* @return value of {@code type} attribute
*/
@JsonProperty("type")
@Override
public Type type() {
return type;
}
/**
* Copy current immutable object by setting value for {@link AdviceBase.AdviceParameterBase#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 AdviceParameter withKind(ParameterKind value) {
if (this.kind == value) {
return this;
}
ParameterKind newValue = Preconditions.checkNotNull(value);
return new AdviceParameter(newValue, this.type);
}
/**
* Copy current immutable object by setting value for {@link AdviceBase.AdviceParameterBase#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 AdviceParameter withType(Type value) {
if (this.type == value) {
return this;
}
Type newValue = Preconditions.checkNotNull(value);
return new AdviceParameter(this.kind, newValue);
}
/**
* This instance is equal to instances of {@code AdviceParameter} with equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
return this == another
|| (another instanceof AdviceParameter && equalTo((AdviceParameter) another));
}
private boolean equalTo(AdviceParameter 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();
}
@JsonCreator
public static AdviceParameter fromAllAttributes(
@JsonProperty("kind") @Nullable ParameterKind kind,
@JsonProperty("type") @Nullable Type type) {
AdviceParameter.Builder builder = AdviceParameter.builder();
if (kind != null) {
builder.kind(kind);
}
if (type != null) {
builder.type(type);
}
return builder.build();
}
/**
* Creates immutable copy of {@link AdviceBase.AdviceParameterBase}.
* 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 AdviceParameter copyOf(AdviceBase.AdviceParameterBase instance) {
if (instance instanceof AdviceParameter) {
return (AdviceParameter) instance;
}
return AdviceParameter.builder()
.kind(instance.kind())
.type(instance.type())
.build();
}
/**
* Creates builder for {@link org.glowroot.weaving.AdviceParameter}.
* @return new AdviceParameter builder
*/
static AdviceParameter.Builder builder() {
return new AdviceParameter.Builder();
}
/**
* Builds instances of {@link org.glowroot.weaving.AdviceParameter}.
* Initialized attributes and then invoke {@link #build()} method to create
* immutable instance.
*
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 INITIALIZED_BITSET_ALL = 0x3;
private static final long INITIALIZED_BIT_KIND = 0x1L;
private static final long INITIALIZED_BIT_TYPE = 0x2L;
private long initializedBitset;
private @Nullable ParameterKind kind;
private @Nullable Type type;
private Builder() {}
/**
* Initializes value for {@link AdviceBase.AdviceParameterBase#kind() kind}.
* @param kind value for kind
* @return {@code this} builder for chained invocation
*/
public final Builder kind(ParameterKind kind) {
checkNotIsSet(kindIsSet(), "kind");
this.kind = Preconditions.checkNotNull(kind);
initializedBitset |= INITIALIZED_BIT_KIND;
return this;
}
/**
* Initializes value for {@link AdviceBase.AdviceParameterBase#type() type}.
* @param type value for type
* @return {@code this} builder for chained invocation
*/
public final Builder type(Type type) {
checkNotIsSet(typeIsSet(), "type");
this.type = Preconditions.checkNotNull(type);
initializedBitset |= INITIALIZED_BIT_TYPE;
return this;
}
/**
* Builds new {@link org.glowroot.weaving.AdviceParameter}.
* @return immutable instance of AdviceParameter
*/
public org.glowroot.weaving.AdviceParameter build() {
checkRequiredAttributes();
return new AdviceParameter(kind, type);
}
private boolean kindIsSet() {
return (initializedBitset & INITIALIZED_BIT_KIND) != 0;
}
private boolean typeIsSet() {
return (initializedBitset & INITIALIZED_BIT_TYPE) != 0;
}
private void checkNotIsSet(boolean isSet, String name) {
if (isSet) {
throw new IllegalStateException("Builder of AdviceParameter is strict, attribute is already set: ".concat(name));
}
}
private void checkRequiredAttributes() {
if (initializedBitset != INITIALIZED_BITSET_ALL) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
Collection 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;
}
}
}