![JAR search and dependency download from the Maven repository](/logo.png)
org.glowroot.instrumentation.test.harness.ImmutableThrowableInfo Maven / Gradle / Ivy
package org.glowroot.instrumentation.test.harness;
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.errorprone.annotations.CanIgnoreReturnValue;
import org.glowroot.instrumentation.test.harness.shaded.com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link ThrowableInfo}.
*
* Use the builder to create immutable instances:
* {@code ImmutableThrowableInfo.builder()}.
*/
@Generated(from = "ThrowableInfo", generator = "Immutables")
@SuppressWarnings({"serial", "all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutableThrowableInfo extends ThrowableInfo {
private final Class> type;
private final @Nullable String message;
private final StackTraceElement[] stackTrace;
private final @Nullable ThrowableInfo cause;
private ImmutableThrowableInfo(
Class> type,
@Nullable String message,
StackTraceElement[] stackTrace,
@Nullable ThrowableInfo cause) {
this.type = type;
this.message = message;
this.stackTrace = stackTrace;
this.cause = cause;
}
/**
* @return The value of the {@code type} attribute
*/
@Override
public Class> type() {
return type;
}
/**
* @return The value of the {@code message} attribute
*/
@Override
public @Nullable String message() {
return message;
}
/**
* @return A cloned {@code stackTrace} array
*/
@Override
public StackTraceElement[] stackTrace() {
return stackTrace.clone();
}
/**
* @return The value of the {@code cause} attribute
*/
@Override
public @Nullable ThrowableInfo cause() {
return cause;
}
/**
* Copy the current immutable object by setting a value for the {@link ThrowableInfo#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 ImmutableThrowableInfo withType(Class> value) {
if (this.type == value) return this;
Class> newValue = Preconditions.checkNotNull(value, "type");
return new ImmutableThrowableInfo(newValue, this.message, this.stackTrace, this.cause);
}
/**
* Copy the current immutable object by setting a value for the {@link ThrowableInfo#message() message} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for message (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableThrowableInfo withMessage(@Nullable String value) {
if (Objects.equal(this.message, value)) return this;
return new ImmutableThrowableInfo(this.type, value, this.stackTrace, this.cause);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ThrowableInfo#stackTrace() stackTrace}.
* The array is cloned before being saved as attribute values.
* @param elements The non-null elements for stackTrace
* @return A modified copy of {@code this} object
*/
public final ImmutableThrowableInfo withStackTrace(StackTraceElement... elements) {
StackTraceElement[] newValue = elements.clone();
return new ImmutableThrowableInfo(this.type, this.message, newValue, this.cause);
}
/**
* Copy the current immutable object by setting a value for the {@link ThrowableInfo#cause() cause} 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 cause (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableThrowableInfo withCause(@Nullable ThrowableInfo value) {
if (this.cause == value) return this;
return new ImmutableThrowableInfo(this.type, this.message, this.stackTrace, value);
}
/**
* This instance is equal to all instances of {@code ImmutableThrowableInfo} 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 ImmutableThrowableInfo
&& equalTo((ImmutableThrowableInfo) another);
}
private boolean equalTo(ImmutableThrowableInfo another) {
return type.equals(another.type)
&& Objects.equal(message, another.message)
&& Arrays.equals(stackTrace, another.stackTrace)
&& Objects.equal(cause, another.cause);
}
/**
* Computes a hash code from attributes: {@code type}, {@code message}, {@code stackTrace}, {@code cause}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + type.hashCode();
h += (h << 5) + Objects.hashCode(message);
h += (h << 5) + Arrays.hashCode(stackTrace);
h += (h << 5) + Objects.hashCode(cause);
return h;
}
/**
* Prints the immutable value {@code ThrowableInfo} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ThrowableInfo")
.omitNullValues()
.add("type", type)
.add("message", message)
.add("stackTrace", Arrays.toString(stackTrace))
.add("cause", cause)
.toString();
}
/**
* Creates an immutable copy of a {@link ThrowableInfo} 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 ThrowableInfo instance
*/
public static ImmutableThrowableInfo copyOf(ThrowableInfo instance) {
if (instance instanceof ImmutableThrowableInfo) {
return (ImmutableThrowableInfo) instance;
}
return ImmutableThrowableInfo.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableThrowableInfo ImmutableThrowableInfo}.
*
* ImmutableThrowableInfo.builder()
* .type(Class<?>) // required {@link ThrowableInfo#type() type}
* .message(String | null) // nullable {@link ThrowableInfo#message() message}
* .stackTrace(StackTraceElement) // required {@link ThrowableInfo#stackTrace() stackTrace}
* .cause(org.glowroot.instrumentation.test.harness.ThrowableInfo | null) // nullable {@link ThrowableInfo#cause() cause}
* .build();
*
* @return A new ImmutableThrowableInfo builder
*/
public static ImmutableThrowableInfo.Builder builder() {
return new ImmutableThrowableInfo.Builder();
}
/**
* Builds instances of type {@link ImmutableThrowableInfo ImmutableThrowableInfo}.
* 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 = "ThrowableInfo", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_TYPE = 0x1L;
private static final long INIT_BIT_STACK_TRACE = 0x2L;
private long initBits = 0x3L;
private Class> type;
private String message;
private StackTraceElement[] stackTrace;
private ThrowableInfo cause;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ThrowableInfo} 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
*/
@CanIgnoreReturnValue
public final Builder from(ThrowableInfo instance) {
Preconditions.checkNotNull(instance, "instance");
type(instance.type());
@Nullable String messageValue = instance.message();
if (messageValue != null) {
message(messageValue);
}
stackTrace(instance.stackTrace());
@Nullable ThrowableInfo causeValue = instance.cause();
if (causeValue != null) {
cause(causeValue);
}
return this;
}
/**
* Initializes the value for the {@link ThrowableInfo#type() type} attribute.
* @param type The value for type
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder type(Class> type) {
this.type = Preconditions.checkNotNull(type, "type");
initBits &= ~INIT_BIT_TYPE;
return this;
}
/**
* Initializes the value for the {@link ThrowableInfo#message() message} attribute.
* @param message The value for message (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder message(@Nullable String message) {
this.message = message;
return this;
}
/**
* Initializes the value for the {@link ThrowableInfo#stackTrace() stackTrace} attribute.
* @param stackTrace The elements for stackTrace
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder stackTrace(StackTraceElement... stackTrace) {
this.stackTrace = stackTrace.clone();
initBits &= ~INIT_BIT_STACK_TRACE;
return this;
}
/**
* Initializes the value for the {@link ThrowableInfo#cause() cause} attribute.
* @param cause The value for cause (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder cause(@Nullable ThrowableInfo cause) {
this.cause = cause;
return this;
}
/**
* Builds a new {@link ImmutableThrowableInfo ImmutableThrowableInfo}.
* @return An immutable instance of ThrowableInfo
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableThrowableInfo build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableThrowableInfo(type, message, stackTrace, cause);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type");
if ((initBits & INIT_BIT_STACK_TRACE) != 0) attributes.add("stackTrace");
return "Cannot build ThrowableInfo, some of required attributes are not set " + attributes;
}
}
}