org.glowroot.instrumentation.engine.weaving.ImmutableBindAnnotation 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 java.util.ArrayList;
import java.util.List;
import org.immutables.value.Generated;
import org.glowroot.instrumentation.test.harness.shaded.org.objectweb.asm.Type;
/**
* Immutable implementation of {@link InstrumentationDetail.BindAnnotation}.
*
* Use the builder to create immutable instances:
* {@code ImmutableBindAnnotation.builder()}.
*/
@Generated(from = "InstrumentationDetail.BindAnnotation", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutableBindAnnotation
extends InstrumentationDetail.BindAnnotation {
private final Type type;
private final int argIndex;
private ImmutableBindAnnotation(Type type, int argIndex) {
this.type = type;
this.argIndex = argIndex;
}
/**
* @return The value of the {@code type} attribute
*/
@Override
Type type() {
return type;
}
/**
* @return The value of the {@code argIndex} attribute
*/
@Override
int argIndex() {
return argIndex;
}
/**
* Copy the current immutable object by setting a value for the {@link InstrumentationDetail.BindAnnotation#type() type} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for type
* @return A modified copy of the {@code this} object
*/
public final ImmutableBindAnnotation withType(Type value) {
if (this.type == value) return this;
Type newValue = Preconditions.checkNotNull(value, "type");
return new ImmutableBindAnnotation(newValue, this.argIndex);
}
/**
* Copy the current immutable object by setting a value for the {@link InstrumentationDetail.BindAnnotation#argIndex() argIndex} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for argIndex
* @return A modified copy of the {@code this} object
*/
public final ImmutableBindAnnotation withArgIndex(int value) {
if (this.argIndex == value) return this;
return new ImmutableBindAnnotation(this.type, value);
}
/**
* This instance is equal to all instances of {@code ImmutableBindAnnotation} 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 ImmutableBindAnnotation
&& equalTo((ImmutableBindAnnotation) another);
}
private boolean equalTo(ImmutableBindAnnotation another) {
return type.equals(another.type)
&& argIndex == another.argIndex;
}
/**
* Computes a hash code from attributes: {@code type}, {@code argIndex}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + type.hashCode();
h += (h << 5) + argIndex;
return h;
}
/**
* Prints the immutable value {@code BindAnnotation} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("BindAnnotation")
.omitNullValues()
.add("type", type)
.add("argIndex", argIndex)
.toString();
}
/**
* Creates an immutable copy of a {@link InstrumentationDetail.BindAnnotation} 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 BindAnnotation instance
*/
public static ImmutableBindAnnotation copyOf(InstrumentationDetail.BindAnnotation instance) {
if (instance instanceof ImmutableBindAnnotation) {
return (ImmutableBindAnnotation) instance;
}
return ImmutableBindAnnotation.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableBindAnnotation ImmutableBindAnnotation}.
*
* ImmutableBindAnnotation.builder()
* .type(org.glowroot.instrumentation.test.harness.shaded.org.objectweb.asm.Type) // required {@link InstrumentationDetail.BindAnnotation#type() type}
* .argIndex(int) // required {@link InstrumentationDetail.BindAnnotation#argIndex() argIndex}
* .build();
*
* @return A new ImmutableBindAnnotation builder
*/
public static ImmutableBindAnnotation.Builder builder() {
return new ImmutableBindAnnotation.Builder();
}
/**
* Builds instances of type {@link ImmutableBindAnnotation ImmutableBindAnnotation}.
* 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 = "InstrumentationDetail.BindAnnotation", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_TYPE = 0x1L;
private static final long INIT_BIT_ARG_INDEX = 0x2L;
private long initBits = 0x3L;
private Type type;
private int argIndex;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code BindAnnotation} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(InstrumentationDetail.BindAnnotation instance) {
Preconditions.checkNotNull(instance, "instance");
type(instance.type());
argIndex(instance.argIndex());
return this;
}
/**
* Initializes the value for the {@link InstrumentationDetail.BindAnnotation#type() type} attribute.
* @param type The value for type
* @return {@code this} builder for use in a chained invocation
*/
public final Builder type(Type type) {
this.type = Preconditions.checkNotNull(type, "type");
initBits &= ~INIT_BIT_TYPE;
return this;
}
/**
* Initializes the value for the {@link InstrumentationDetail.BindAnnotation#argIndex() argIndex} attribute.
* @param argIndex The value for argIndex
* @return {@code this} builder for use in a chained invocation
*/
public final Builder argIndex(int argIndex) {
this.argIndex = argIndex;
initBits &= ~INIT_BIT_ARG_INDEX;
return this;
}
/**
* Builds a new {@link ImmutableBindAnnotation ImmutableBindAnnotation}.
* @return An immutable instance of BindAnnotation
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableBindAnnotation build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableBindAnnotation(type, argIndex);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type");
if ((initBits & INIT_BIT_ARG_INDEX) != 0) attributes.add("argIndex");
return "Cannot build BindAnnotation, some of required attributes are not set " + attributes;
}
}
}