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

org.glowroot.agent.weaving.ImmutableLazyDefinedClass 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.Arrays;
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 ClassLoaders.LazyDefinedClass}.
 * 

* Use builder to create immutable instances: * {@code ImmutableLazyDefinedClass.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "ClassLoaders.LazyDefinedClass"}) @Immutable public final class ImmutableLazyDefinedClass implements ClassLoaders.LazyDefinedClass { private final Type type; private final byte[] bytes; private final ImmutableList dependencies; private ImmutableLazyDefinedClass( Type type, byte[] bytes, ImmutableList dependencies) { this.type = type; this.bytes = bytes; this.dependencies = dependencies; } /** * @return value of {@code type} attribute */ @JsonProperty @Override public Type type() { return type; } /** * @return cloned {@code bytes} array */ @JsonProperty @Override public byte[] bytes() { return bytes.clone(); } /** * @return value of {@code dependencies} attribute */ @JsonProperty @Override public ImmutableList dependencies() { return dependencies; } /** * Copy current immutable object by setting value for {@link ClassLoaders.LazyDefinedClass#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 ImmutableLazyDefinedClass withType(Type value) { if (this.type == value) return this; Type newValue = Preconditions.checkNotNull(value); return new ImmutableLazyDefinedClass(newValue, this.bytes, this.dependencies); } /** * Copy current immutable object with elements that replace content of {@link ClassLoaders.LazyDefinedClass#bytes() bytes}. * Array is cloned before saved as the attribute value. * @param elements elements for bytes, not null * @return modified copy of {@code this} object */ public final ImmutableLazyDefinedClass withBytes(byte... elements) { byte[] newValue = elements.clone(); return new ImmutableLazyDefinedClass(this.type, newValue, this.dependencies); } /** * Copy current immutable object with elements that replace content of {@link ClassLoaders.LazyDefinedClass#dependencies() dependencies}. * @param elements elements to set * @return modified copy of {@code this} object */ public final ImmutableLazyDefinedClass withDependencies(ClassLoaders.LazyDefinedClass... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableLazyDefinedClass(this.type, this.bytes, newValue); } /** * Copy current immutable object with elements that replace content of {@link ClassLoaders.LazyDefinedClass#dependencies() dependencies}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements iterable of dependencies elements to set * @return modified copy of {@code this} object */ public final ImmutableLazyDefinedClass withDependencies(Iterable elements) { if (this.dependencies == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableLazyDefinedClass(this.type, this.bytes, newValue); } /** * This instance is equal to instances of {@code ImmutableLazyDefinedClass} 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 ImmutableLazyDefinedClass && equalTo((ImmutableLazyDefinedClass) another); } private boolean equalTo(ImmutableLazyDefinedClass another) { return type.equals(another.type) && Arrays.equals(bytes, another.bytes) && dependencies.equals(another.dependencies); } /** * Computes hash code from attributes: {@code type}, {@code bytes}, {@code dependencies}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + type.hashCode(); h = h * 17 + Arrays.hashCode(bytes); h = h * 17 + dependencies.hashCode(); return h; } /** * Prints immutable value {@code LazyDefinedClass...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("LazyDefinedClass") .add("type", type) .add("bytes", Arrays.toString(bytes)) .add("dependencies", dependencies) .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 Type type; @JsonProperty @Nullable byte[] bytes; @JsonProperty @Nullable ImmutableList dependencies; } /** * @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 ImmutableLazyDefinedClass fromJson(Json json) { ImmutableLazyDefinedClass.Builder builder = ImmutableLazyDefinedClass.builder(); if (json.type != null) { builder.type(json.type); } if (json.bytes != null) { builder.bytes(json.bytes); } if (json.dependencies != null) { builder.addAllDependencies(json.dependencies); } return builder.build(); } /** * Creates immutable copy of {@link ClassLoaders.LazyDefinedClass}. * 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 LazyDefinedClass instance */ public static ImmutableLazyDefinedClass copyOf(ClassLoaders.LazyDefinedClass instance) { if (instance instanceof ImmutableLazyDefinedClass) { return (ImmutableLazyDefinedClass) instance; } return ImmutableLazyDefinedClass.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.agent.weaving.ImmutableLazyDefinedClass ImmutableLazyDefinedClass}. * @return new ImmutableLazyDefinedClass builder */ public static ImmutableLazyDefinedClass.Builder builder() { return new ImmutableLazyDefinedClass.Builder(); } /** * Builds instances of {@link org.glowroot.agent.weaving.ImmutableLazyDefinedClass ImmutableLazyDefinedClass}. * 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 public static final class Builder { private static final long INIT_BIT_TYPE = 0x1L; private static final long INIT_BIT_BYTES = 0x2L; private long initBits = 0x3; private @Nullable Type type; private @Nullable byte[] bytes; private ImmutableList.Builder dependenciesBuilder = ImmutableList.builder(); private Builder() {} /** * Fill builder with attribute values from provided {@link ClassLoaders.LazyDefinedClass} 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(ClassLoaders.LazyDefinedClass instance) { Preconditions.checkNotNull(instance); type(instance.type()); bytes(instance.bytes()); addAllDependencies(instance.dependencies()); return this; } /** * Initializes value for {@link ClassLoaders.LazyDefinedClass#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; } /** * Initializes value for {@link ClassLoaders.LazyDefinedClass#bytes() bytes}. * @param elements elements for bytes * @return {@code this} builder for chained invocation */ public final Builder bytes(byte... elements) { this.bytes = elements.clone(); initBits &= ~INIT_BIT_BYTES; return this; } /** * Adds one element to {@link ClassLoaders.LazyDefinedClass#dependencies() dependencies} list. * @param element dependencies element * @return {@code this} builder for chained invocation */ public final Builder addDependencies(ClassLoaders.LazyDefinedClass element) { dependenciesBuilder.add(element); return this; } /** * Adds elements to {@link ClassLoaders.LazyDefinedClass#dependencies() dependencies} list. * @param elements array of dependencies elements * @return {@code this} builder for chained invocation */ public final Builder addDependencies(ClassLoaders.LazyDefinedClass... elements) { dependenciesBuilder.add(elements); return this; } /** * Sets or replaces all elements for {@link ClassLoaders.LazyDefinedClass#dependencies() dependencies} list. * @param elements iterable of dependencies elements * @return {@code this} builder for chained invocation */ public final Builder dependencies(Iterable elements) { dependenciesBuilder = ImmutableList.builder(); return addAllDependencies(elements); } /** * Adds elements to {@link ClassLoaders.LazyDefinedClass#dependencies() dependencies} list. * @param elements iterable of dependencies elements * @return {@code this} builder for chained invocation */ public final Builder addAllDependencies(Iterable elements) { dependenciesBuilder.addAll(elements); return this; } /** * Builds new {@link org.glowroot.agent.weaving.ImmutableLazyDefinedClass ImmutableLazyDefinedClass}. * @return immutable instance of LazyDefinedClass * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutableLazyDefinedClass build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutableLazyDefinedClass(type, bytes, dependenciesBuilder.build()); } private boolean typeIsSet() { return (initBits & INIT_BIT_TYPE) == 0; } private boolean bytesIsSet() { return (initBits & INIT_BIT_BYTES) == 0; } private void checkRequiredAttributes() throws IllegalStateException { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if (!typeIsSet()) attributes.add("type"); if (!bytesIsSet()) attributes.add("bytes"); return "Cannot build LazyDefinedClass, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy