All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.glowroot.instrumentation.engine.weaving.ImmutableAdviceParameter Maven / Gradle / Ivy

The newest version!
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 Advice.AdviceParameter}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableAdviceParameter.builder()}. */ @Generated(from = "Advice.AdviceParameter", generator = "Immutables") @SuppressWarnings({"all"}) @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") final class ImmutableAdviceParameter implements Advice.AdviceParameter { private final Advice.ParameterKind kind; private final Type type; private final int argIndex; private ImmutableAdviceParameter( Advice.ParameterKind kind, Type type, int argIndex) { this.kind = kind; this.type = type; this.argIndex = argIndex; } /** * @return The value of the {@code kind} attribute */ @Override public Advice.ParameterKind kind() { return kind; } /** * @return The value of the {@code type} attribute */ @Override public Type type() { return type; } /** * @return The value of the {@code argIndex} attribute */ @Override public int argIndex() { return argIndex; } /** * Copy the current immutable object by setting a value for the {@link Advice.AdviceParameter#kind() kind} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for kind * @return A modified copy of the {@code this} object */ public final ImmutableAdviceParameter withKind(Advice.ParameterKind value) { if (this.kind == value) return this; Advice.ParameterKind newValue = Preconditions.checkNotNull(value, "kind"); if (this.kind.equals(newValue)) return this; return new ImmutableAdviceParameter(newValue, this.type, this.argIndex); } /** * Copy the current immutable object by setting a value for the {@link Advice.AdviceParameter#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 ImmutableAdviceParameter withType(Type value) { if (this.type == value) return this; Type newValue = Preconditions.checkNotNull(value, "type"); return new ImmutableAdviceParameter(this.kind, newValue, this.argIndex); } /** * Copy the current immutable object by setting a value for the {@link Advice.AdviceParameter#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 ImmutableAdviceParameter withArgIndex(int value) { if (this.argIndex == value) return this; return new ImmutableAdviceParameter(this.kind, this.type, value); } /** * This instance is equal to all instances of {@code ImmutableAdviceParameter} 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 ImmutableAdviceParameter && equalTo((ImmutableAdviceParameter) another); } private boolean equalTo(ImmutableAdviceParameter another) { return kind.equals(another.kind) && type.equals(another.type) && argIndex == another.argIndex; } /** * Computes a hash code from attributes: {@code kind}, {@code type}, {@code argIndex}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + kind.hashCode(); h += (h << 5) + type.hashCode(); h += (h << 5) + argIndex; return h; } /** * Prints the immutable value {@code AdviceParameter} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("AdviceParameter") .omitNullValues() .add("kind", kind) .add("type", type) .add("argIndex", argIndex) .toString(); } /** * Creates an immutable copy of a {@link Advice.AdviceParameter} 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 AdviceParameter instance */ public static ImmutableAdviceParameter copyOf(Advice.AdviceParameter instance) { if (instance instanceof ImmutableAdviceParameter) { return (ImmutableAdviceParameter) instance; } return ImmutableAdviceParameter.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableAdviceParameter ImmutableAdviceParameter}. *

   * ImmutableAdviceParameter.builder()
   *    .kind(org.glowroot.instrumentation.engine.weaving.Advice.ParameterKind) // required {@link Advice.AdviceParameter#kind() kind}
   *    .type(org.glowroot.instrumentation.test.harness.shaded.org.objectweb.asm.Type) // required {@link Advice.AdviceParameter#type() type}
   *    .argIndex(int) // required {@link Advice.AdviceParameter#argIndex() argIndex}
   *    .build();
   * 
* @return A new ImmutableAdviceParameter builder */ public static ImmutableAdviceParameter.Builder builder() { return new ImmutableAdviceParameter.Builder(); } /** * Builds instances of type {@link ImmutableAdviceParameter ImmutableAdviceParameter}. * 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 = "Advice.AdviceParameter", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_KIND = 0x1L; private static final long INIT_BIT_TYPE = 0x2L; private static final long INIT_BIT_ARG_INDEX = 0x4L; private long initBits = 0x7L; private Advice.ParameterKind kind; private Type type; private int argIndex; private Builder() { } /** * Fill a builder with attribute values from the provided {@code AdviceParameter} 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(Advice.AdviceParameter instance) { Preconditions.checkNotNull(instance, "instance"); kind(instance.kind()); type(instance.type()); argIndex(instance.argIndex()); return this; } /** * Initializes the value for the {@link Advice.AdviceParameter#kind() kind} attribute. * @param kind The value for kind * @return {@code this} builder for use in a chained invocation */ public final Builder kind(Advice.ParameterKind kind) { this.kind = Preconditions.checkNotNull(kind, "kind"); initBits &= ~INIT_BIT_KIND; return this; } /** * Initializes the value for the {@link Advice.AdviceParameter#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 Advice.AdviceParameter#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 ImmutableAdviceParameter ImmutableAdviceParameter}. * @return An immutable instance of AdviceParameter * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableAdviceParameter build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableAdviceParameter(kind, type, argIndex); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList(); if ((initBits & INIT_BIT_KIND) != 0) attributes.add("kind"); if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type"); if ((initBits & INIT_BIT_ARG_INDEX) != 0) attributes.add("argIndex"); return "Cannot build AdviceParameter, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy