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

org.glowroot.agent.weaving.ImmutableAnalyzedMethodKey Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
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.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 WeavingClassVisitor.AnalyzedMethodKey}.
 * 

* Use builder to create immutable instances: * {@code ImmutableAnalyzedMethodKey.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "WeavingClassVisitor.AnalyzedMethodKey"}) @Immutable final class ImmutableAnalyzedMethodKey extends WeavingClassVisitor.AnalyzedMethodKey { private final String name; private final ImmutableList parameterTypes; private final AnalyzedMethod analyzedMethod; private ImmutableAnalyzedMethodKey( String name, ImmutableList parameterTypes, AnalyzedMethod analyzedMethod) { this.name = name; this.parameterTypes = parameterTypes; this.analyzedMethod = analyzedMethod; } /** * @return value of {@code name} attribute */ @JsonProperty @Override String name() { return name; } /** * @return value of {@code parameterTypes} attribute */ @JsonProperty @Override ImmutableList parameterTypes() { return parameterTypes; } /** * @return value of {@code analyzedMethod} attribute */ @JsonProperty @Override AnalyzedMethod analyzedMethod() { return analyzedMethod; } /** * Copy current immutable object by setting value for {@link WeavingClassVisitor.AnalyzedMethodKey#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 ImmutableAnalyzedMethodKey withName(String value) { if (this.name == value) return this; String newValue = Preconditions.checkNotNull(value); return new ImmutableAnalyzedMethodKey(newValue, this.parameterTypes, this.analyzedMethod); } /** * Copy current immutable object with elements that replace content of {@link WeavingClassVisitor.AnalyzedMethodKey#parameterTypes() parameterTypes}. * @param elements elements to set * @return modified copy of {@code this} object */ public final ImmutableAnalyzedMethodKey withParameterTypes(String... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableAnalyzedMethodKey(this.name, newValue, this.analyzedMethod); } /** * Copy current immutable object with elements that replace content of {@link WeavingClassVisitor.AnalyzedMethodKey#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 ImmutableAnalyzedMethodKey withParameterTypes(Iterable elements) { if (this.parameterTypes == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableAnalyzedMethodKey(this.name, newValue, this.analyzedMethod); } /** * Copy current immutable object by setting value for {@link WeavingClassVisitor.AnalyzedMethodKey#analyzedMethod() analyzedMethod}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for analyzedMethod * @return modified copy of the {@code this} object */ public final ImmutableAnalyzedMethodKey withAnalyzedMethod(AnalyzedMethod value) { if (this.analyzedMethod == value) return this; AnalyzedMethod newValue = Preconditions.checkNotNull(value); return new ImmutableAnalyzedMethodKey(this.name, this.parameterTypes, newValue); } /** * This instance is equal to instances of {@code ImmutableAnalyzedMethodKey} 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 ImmutableAnalyzedMethodKey && equalTo((ImmutableAnalyzedMethodKey) another); } private boolean equalTo(ImmutableAnalyzedMethodKey another) { return name.equals(another.name) && parameterTypes.equals(another.parameterTypes); } /** * Computes hash code from attributes: {@code name}, {@code parameterTypes}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + name.hashCode(); h = h * 17 + parameterTypes.hashCode(); return h; } /** * Prints immutable value {@code AnalyzedMethodKey...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("AnalyzedMethodKey") .add("name", name) .add("parameterTypes", parameterTypes) .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 AnalyzedMethod analyzedMethod; } /** * @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 ImmutableAnalyzedMethodKey fromJson(Json json) { ImmutableAnalyzedMethodKey.Builder builder = ImmutableAnalyzedMethodKey.builder(); if (json.name != null) { builder.name(json.name); } if (json.parameterTypes != null) { builder.addAllParameterTypes(json.parameterTypes); } if (json.analyzedMethod != null) { builder.analyzedMethod(json.analyzedMethod); } return builder.build(); } /** * Creates immutable copy of {@link WeavingClassVisitor.AnalyzedMethodKey}. * 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 AnalyzedMethodKey instance */ static ImmutableAnalyzedMethodKey copyOf(WeavingClassVisitor.AnalyzedMethodKey instance) { if (instance instanceof ImmutableAnalyzedMethodKey) { return (ImmutableAnalyzedMethodKey) instance; } return ImmutableAnalyzedMethodKey.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.agent.weaving.ImmutableAnalyzedMethodKey ImmutableAnalyzedMethodKey}. * @return new ImmutableAnalyzedMethodKey builder */ static ImmutableAnalyzedMethodKey.Builder builder() { return new ImmutableAnalyzedMethodKey.Builder(); } /** * Builds instances of {@link org.glowroot.agent.weaving.ImmutableAnalyzedMethodKey ImmutableAnalyzedMethodKey}. * 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_NAME = 0x1L; private static final long INIT_BIT_ANALYZED_METHOD = 0x2L; private long initBits = 0x3; private @Nullable String name; private ImmutableList.Builder parameterTypesBuilder = ImmutableList.builder(); private @Nullable AnalyzedMethod analyzedMethod; private Builder() {} /** * Fill builder with attribute values from provided {@link WeavingClassVisitor.AnalyzedMethodKey} 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(WeavingClassVisitor.AnalyzedMethodKey instance) { Preconditions.checkNotNull(instance); name(instance.name()); addAllParameterTypes(instance.parameterTypes()); analyzedMethod(instance.analyzedMethod()); return this; } /** * Initializes value for {@link WeavingClassVisitor.AnalyzedMethodKey#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 WeavingClassVisitor.AnalyzedMethodKey#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 WeavingClassVisitor.AnalyzedMethodKey#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 WeavingClassVisitor.AnalyzedMethodKey#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 WeavingClassVisitor.AnalyzedMethodKey#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 WeavingClassVisitor.AnalyzedMethodKey#analyzedMethod() analyzedMethod}. * @param analyzedMethod value for analyzedMethod * @return {@code this} builder for chained invocation */ public final Builder analyzedMethod(AnalyzedMethod analyzedMethod) { this.analyzedMethod = Preconditions.checkNotNull(analyzedMethod); initBits &= ~INIT_BIT_ANALYZED_METHOD; return this; } /** * Builds new {@link org.glowroot.agent.weaving.ImmutableAnalyzedMethodKey ImmutableAnalyzedMethodKey}. * @return immutable instance of AnalyzedMethodKey * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutableAnalyzedMethodKey build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutableAnalyzedMethodKey(name, parameterTypesBuilder.build(), analyzedMethod); } private boolean nameIsSet() { return (initBits & INIT_BIT_NAME) == 0; } private boolean analyzedMethodIsSet() { return (initBits & INIT_BIT_ANALYZED_METHOD) == 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 (!analyzedMethodIsSet()) attributes.add("analyzedMethod"); return "Cannot build AnalyzedMethodKey, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy