org.glowroot.instrumentation.engine.weaving.ImmutablePointcutClassName 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.Objects;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.base.Preconditions;
import org.glowroot.instrumentation.test.harness.shaded.com.google.common.primitives.Booleans;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link Reweaving.PointcutClassName}.
*
* Use the builder to create immutable instances:
* {@code ImmutablePointcutClassName.builder()}.
*/
@Generated(from = "Reweaving.PointcutClassName", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutablePointcutClassName
extends Reweaving.PointcutClassName {
private final @Nullable Pattern pattern;
private final @Nullable String nonPattern;
private final @Nullable Reweaving.PointcutClassName subTypeRestriction;
private final boolean doNotMatchSubClasses;
private ImmutablePointcutClassName(
@Nullable Pattern pattern,
@Nullable String nonPattern,
@Nullable Reweaving.PointcutClassName subTypeRestriction,
boolean doNotMatchSubClasses) {
this.pattern = pattern;
this.nonPattern = nonPattern;
this.subTypeRestriction = subTypeRestriction;
this.doNotMatchSubClasses = doNotMatchSubClasses;
}
/**
* @return The value of the {@code pattern} attribute
*/
@Override
@Nullable Pattern pattern() {
return pattern;
}
/**
* @return The value of the {@code nonPattern} attribute
*/
@Override
@Nullable String nonPattern() {
return nonPattern;
}
/**
* @return The value of the {@code subTypeRestriction} attribute
*/
@Override
@Nullable Reweaving.PointcutClassName subTypeRestriction() {
return subTypeRestriction;
}
/**
* @return The value of the {@code doNotMatchSubClasses} attribute
*/
@Override
boolean doNotMatchSubClasses() {
return doNotMatchSubClasses;
}
/**
* Copy the current immutable object by setting a value for the {@link Reweaving.PointcutClassName#pattern() pattern} 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 pattern (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePointcutClassName withPattern(@Nullable Pattern value) {
if (this.pattern == value) return this;
return new ImmutablePointcutClassName(value, this.nonPattern, this.subTypeRestriction, this.doNotMatchSubClasses);
}
/**
* Copy the current immutable object by setting a value for the {@link Reweaving.PointcutClassName#nonPattern() nonPattern} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for nonPattern (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePointcutClassName withNonPattern(@Nullable String value) {
if (Objects.equal(this.nonPattern, value)) return this;
return new ImmutablePointcutClassName(this.pattern, value, this.subTypeRestriction, this.doNotMatchSubClasses);
}
/**
* Copy the current immutable object by setting a value for the {@link Reweaving.PointcutClassName#subTypeRestriction() subTypeRestriction} 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 subTypeRestriction (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePointcutClassName withSubTypeRestriction(@Nullable Reweaving.PointcutClassName value) {
if (this.subTypeRestriction == value) return this;
return new ImmutablePointcutClassName(this.pattern, this.nonPattern, value, this.doNotMatchSubClasses);
}
/**
* Copy the current immutable object by setting a value for the {@link Reweaving.PointcutClassName#doNotMatchSubClasses() doNotMatchSubClasses} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for doNotMatchSubClasses
* @return A modified copy of the {@code this} object
*/
public final ImmutablePointcutClassName withDoNotMatchSubClasses(boolean value) {
if (this.doNotMatchSubClasses == value) return this;
return new ImmutablePointcutClassName(this.pattern, this.nonPattern, this.subTypeRestriction, value);
}
/**
* This instance is equal to all instances of {@code ImmutablePointcutClassName} 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 ImmutablePointcutClassName
&& equalTo((ImmutablePointcutClassName) another);
}
private boolean equalTo(ImmutablePointcutClassName another) {
return Objects.equal(pattern, another.pattern)
&& Objects.equal(nonPattern, another.nonPattern)
&& Objects.equal(subTypeRestriction, another.subTypeRestriction)
&& doNotMatchSubClasses == another.doNotMatchSubClasses;
}
/**
* Computes a hash code from attributes: {@code pattern}, {@code nonPattern}, {@code subTypeRestriction}, {@code doNotMatchSubClasses}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(pattern);
h += (h << 5) + Objects.hashCode(nonPattern);
h += (h << 5) + Objects.hashCode(subTypeRestriction);
h += (h << 5) + Booleans.hashCode(doNotMatchSubClasses);
return h;
}
/**
* Prints the immutable value {@code PointcutClassName} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("PointcutClassName")
.omitNullValues()
.add("pattern", pattern)
.add("nonPattern", nonPattern)
.add("subTypeRestriction", subTypeRestriction)
.add("doNotMatchSubClasses", doNotMatchSubClasses)
.toString();
}
/**
* Creates an immutable copy of a {@link Reweaving.PointcutClassName} 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 PointcutClassName instance
*/
public static ImmutablePointcutClassName copyOf(Reweaving.PointcutClassName instance) {
if (instance instanceof ImmutablePointcutClassName) {
return (ImmutablePointcutClassName) instance;
}
return ImmutablePointcutClassName.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutablePointcutClassName ImmutablePointcutClassName}.
*
* ImmutablePointcutClassName.builder()
* .pattern(regex.Pattern | null) // nullable {@link Reweaving.PointcutClassName#pattern() pattern}
* .nonPattern(String | null) // nullable {@link Reweaving.PointcutClassName#nonPattern() nonPattern}
* .subTypeRestriction(org.glowroot.instrumentation.engine.weaving.Reweaving.PointcutClassName | null) // nullable {@link Reweaving.PointcutClassName#subTypeRestriction() subTypeRestriction}
* .doNotMatchSubClasses(boolean) // required {@link Reweaving.PointcutClassName#doNotMatchSubClasses() doNotMatchSubClasses}
* .build();
*
* @return A new ImmutablePointcutClassName builder
*/
public static ImmutablePointcutClassName.Builder builder() {
return new ImmutablePointcutClassName.Builder();
}
/**
* Builds instances of type {@link ImmutablePointcutClassName ImmutablePointcutClassName}.
* 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 = "Reweaving.PointcutClassName", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_DO_NOT_MATCH_SUB_CLASSES = 0x1L;
private long initBits = 0x1L;
private Pattern pattern;
private String nonPattern;
private Reweaving.PointcutClassName subTypeRestriction;
private boolean doNotMatchSubClasses;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code PointcutClassName} 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(Reweaving.PointcutClassName instance) {
Preconditions.checkNotNull(instance, "instance");
@Nullable Pattern patternValue = instance.pattern();
if (patternValue != null) {
pattern(patternValue);
}
@Nullable String nonPatternValue = instance.nonPattern();
if (nonPatternValue != null) {
nonPattern(nonPatternValue);
}
@Nullable Reweaving.PointcutClassName subTypeRestrictionValue = instance.subTypeRestriction();
if (subTypeRestrictionValue != null) {
subTypeRestriction(subTypeRestrictionValue);
}
doNotMatchSubClasses(instance.doNotMatchSubClasses());
return this;
}
/**
* Initializes the value for the {@link Reweaving.PointcutClassName#pattern() pattern} attribute.
* @param pattern The value for pattern (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder pattern(@Nullable Pattern pattern) {
this.pattern = pattern;
return this;
}
/**
* Initializes the value for the {@link Reweaving.PointcutClassName#nonPattern() nonPattern} attribute.
* @param nonPattern The value for nonPattern (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder nonPattern(@Nullable String nonPattern) {
this.nonPattern = nonPattern;
return this;
}
/**
* Initializes the value for the {@link Reweaving.PointcutClassName#subTypeRestriction() subTypeRestriction} attribute.
* @param subTypeRestriction The value for subTypeRestriction (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder subTypeRestriction(@Nullable Reweaving.PointcutClassName subTypeRestriction) {
this.subTypeRestriction = subTypeRestriction;
return this;
}
/**
* Initializes the value for the {@link Reweaving.PointcutClassName#doNotMatchSubClasses() doNotMatchSubClasses} attribute.
* @param doNotMatchSubClasses The value for doNotMatchSubClasses
* @return {@code this} builder for use in a chained invocation
*/
public final Builder doNotMatchSubClasses(boolean doNotMatchSubClasses) {
this.doNotMatchSubClasses = doNotMatchSubClasses;
initBits &= ~INIT_BIT_DO_NOT_MATCH_SUB_CLASSES;
return this;
}
/**
* Builds a new {@link ImmutablePointcutClassName ImmutablePointcutClassName}.
* @return An immutable instance of PointcutClassName
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutablePointcutClassName build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutablePointcutClassName(pattern, nonPattern, subTypeRestriction, doNotMatchSubClasses);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_DO_NOT_MATCH_SUB_CLASSES) != 0) attributes.add("doNotMatchSubClasses");
return "Cannot build PointcutClassName, some of required attributes are not set " + attributes;
}
}
}