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

org.glowroot.agent.model.ImmutableErrorMessage Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
package org.glowroot.agent.model;

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.Objects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
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;
import org.glowroot.wire.api.model.TraceOuterClass;

/**
 * Immutable implementation of {@link ErrorMessage}.
 * 

* Use builder to create immutable instances: * {@code ImmutableErrorMessage.builder()}. * Use static factory method to create immutable instances: * {@code ImmutableErrorMessage.of()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "ErrorMessage"}) @Immutable public final class ImmutableErrorMessage extends ErrorMessage { private final String message; private final @Nullable TraceOuterClass.Trace.Throwable throwable; private ImmutableErrorMessage( String message, @Nullable TraceOuterClass.Trace.Throwable throwable) { this.message = Preconditions.checkNotNull(message); this.throwable = throwable; } private ImmutableErrorMessage( ImmutableErrorMessage original, String message, @Nullable TraceOuterClass.Trace.Throwable throwable) { this.message = message; this.throwable = throwable; } /** * @return value of {@code message} attribute */ @JsonProperty @Override public String message() { return message; } /** * @return value of {@code throwable} attribute */ @JsonProperty @Override public @Nullable TraceOuterClass.Trace.Throwable throwable() { return throwable; } /** * Copy current immutable object by setting value for {@link ErrorMessage#message() message}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for message * @return modified copy of the {@code this} object */ public final ImmutableErrorMessage withMessage(String value) { if (this.message == value) return this; String newValue = Preconditions.checkNotNull(value); return new ImmutableErrorMessage(this, newValue, this.throwable); } /** * Copy current immutable object by setting value for {@link ErrorMessage#throwable() throwable}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for throwable, can be {@code null} * @return modified copy of the {@code this} object */ public final ImmutableErrorMessage withThrowable(@Nullable TraceOuterClass.Trace.Throwable value) { if (this.throwable == value) return this; @Nullable TraceOuterClass.Trace.Throwable newValue = value; return new ImmutableErrorMessage(this, this.message, newValue); } /** * This instance is equal to instances of {@code ImmutableErrorMessage} 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 ImmutableErrorMessage && equalTo((ImmutableErrorMessage) another); } private boolean equalTo(ImmutableErrorMessage another) { return message.equals(another.message) && Objects.equal(throwable, another.throwable); } /** * Computes hash code from attributes: {@code message}, {@code throwable}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + message.hashCode(); h = h * 17 + Objects.hashCode(throwable); return h; } /** * Prints immutable value {@code ErrorMessage...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("ErrorMessage") .add("message", message) .add("throwable", throwable) .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 message; @JsonProperty @Nullable TraceOuterClass.Trace.Throwable throwable; } /** * @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 ImmutableErrorMessage fromJson(Json json) { ImmutableErrorMessage.Builder builder = ImmutableErrorMessage.builder(); if (json.message != null) { builder.message(json.message); } if (json.throwable != null) { builder.throwable(json.throwable); } return builder.build(); } /** * Construct new immutable {@code ErrorMessage} instance. * @param message value for {@code message} * @param throwable value for {@code throwable} * @return immutable ErrorMessage instance */ public static ImmutableErrorMessage of(String message, @Nullable TraceOuterClass.Trace.Throwable throwable) { return new ImmutableErrorMessage(message, throwable); } /** * Creates immutable copy of {@link ErrorMessage}. * 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 ErrorMessage instance */ public static ImmutableErrorMessage copyOf(ErrorMessage instance) { if (instance instanceof ImmutableErrorMessage) { return (ImmutableErrorMessage) instance; } return ImmutableErrorMessage.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.agent.model.ImmutableErrorMessage ImmutableErrorMessage}. * @return new ImmutableErrorMessage builder */ public static ImmutableErrorMessage.Builder builder() { return new ImmutableErrorMessage.Builder(); } /** * Builds instances of {@link org.glowroot.agent.model.ImmutableErrorMessage ImmutableErrorMessage}. * 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_MESSAGE = 0x1L; private long initBits = 0x1; private @Nullable String message; private @Nullable TraceOuterClass.Trace.Throwable throwable; private Builder() {} /** * Fill builder with attribute values from provided {@link ErrorMessage} instance. * Regular attribute values will be replaced with ones of an instance. * Instance's absent optional values will not replace present values. * @param instance instance to copy values from * @return {@code this} builder for chained invocation */ public final Builder copyFrom(ErrorMessage instance) { Preconditions.checkNotNull(instance); message(instance.message()); @Nullable TraceOuterClass.Trace.Throwable throwableValue = instance.throwable(); if (throwableValue != null) { throwable(throwableValue); } return this; } /** * Initializes value for {@link ErrorMessage#message() message}. * @param message value for message * @return {@code this} builder for chained invocation */ public final Builder message(String message) { this.message = Preconditions.checkNotNull(message); initBits &= ~INIT_BIT_MESSAGE; return this; } /** * Initializes value for {@link ErrorMessage#throwable() throwable}. * @param throwable value for throwable, can be {@code null} * @return {@code this} builder for chained invocation */ public final Builder throwable(@Nullable TraceOuterClass.Trace.Throwable throwable) { this.throwable = throwable; return this; } /** * Builds new {@link org.glowroot.agent.model.ImmutableErrorMessage ImmutableErrorMessage}. * @return immutable instance of ErrorMessage * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutableErrorMessage build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutableErrorMessage(null, message, throwable); } private boolean messageIsSet() { return (initBits & INIT_BIT_MESSAGE) == 0; } private void checkRequiredAttributes() throws IllegalStateException { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if (!messageIsSet()) attributes.add("message"); return "Cannot build ErrorMessage, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy