
org.glowroot.storage.repo.ImmutableErrorMessageCount Maven / Gradle / Ivy
package org.glowroot.storage.repo;
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.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Longs;
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 TraceRepository.ErrorMessageCount}.
*
* Use builder to create immutable instances:
* {@code ImmutableErrorMessageCount.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "TraceRepository.ErrorMessageCount"})
@Immutable
public final class ImmutableErrorMessageCount
implements TraceRepository.ErrorMessageCount {
private final String message;
private final long count;
private ImmutableErrorMessageCount(String message, long count) {
this.message = message;
this.count = count;
}
/**
* @return value of {@code message} attribute
*/
@JsonProperty
@Override
public String message() {
return message;
}
/**
* @return value of {@code count} attribute
*/
@JsonProperty
@Override
public long count() {
return count;
}
/**
* Copy current immutable object by setting value for {@link TraceRepository.ErrorMessageCount#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 ImmutableErrorMessageCount withMessage(String value) {
if (this.message == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableErrorMessageCount(newValue, this.count);
}
/**
* Copy current immutable object by setting value for {@link TraceRepository.ErrorMessageCount#count() count}.
* Value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for count
* @return modified copy of the {@code this} object
*/
public final ImmutableErrorMessageCount withCount(long value) {
if (this.count == value) return this;
long newValue = value;
return new ImmutableErrorMessageCount(this.message, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableErrorMessageCount} 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 ImmutableErrorMessageCount
&& equalTo((ImmutableErrorMessageCount) another);
}
private boolean equalTo(ImmutableErrorMessageCount another) {
return message.equals(another.message)
&& count == another.count;
}
/**
* Computes hash code from attributes: {@code message}, {@code count}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + message.hashCode();
h = h * 17 + Longs.hashCode(count);
return h;
}
/**
* Prints immutable value {@code ErrorMessageCount...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ErrorMessageCount")
.add("message", message)
.add("count", count)
.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 Long count;
}
/**
* @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 ImmutableErrorMessageCount fromJson(Json json) {
ImmutableErrorMessageCount.Builder builder = ImmutableErrorMessageCount.builder();
if (json.message != null) {
builder.message(json.message);
}
if (json.count != null) {
builder.count(json.count);
}
return builder.build();
}
/**
* Creates immutable copy of {@link TraceRepository.ErrorMessageCount}.
* 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 ErrorMessageCount instance
*/
public static ImmutableErrorMessageCount copyOf(TraceRepository.ErrorMessageCount instance) {
if (instance instanceof ImmutableErrorMessageCount) {
return (ImmutableErrorMessageCount) instance;
}
return ImmutableErrorMessageCount.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.storage.repo.ImmutableErrorMessageCount ImmutableErrorMessageCount}.
* @return new ImmutableErrorMessageCount builder
*/
public static ImmutableErrorMessageCount.Builder builder() {
return new ImmutableErrorMessageCount.Builder();
}
/**
* Builds instances of {@link org.glowroot.storage.repo.ImmutableErrorMessageCount ImmutableErrorMessageCount}.
* 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 static final long INIT_BIT_COUNT = 0x2L;
private long initBits = 0x3;
private @Nullable String message;
private long count;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link TraceRepository.ErrorMessageCount} 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(TraceRepository.ErrorMessageCount instance) {
Preconditions.checkNotNull(instance);
message(instance.message());
count(instance.count());
return this;
}
/**
* Initializes value for {@link TraceRepository.ErrorMessageCount#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 TraceRepository.ErrorMessageCount#count() count}.
* @param count value for count
* @return {@code this} builder for chained invocation
*/
public final Builder count(long count) {
this.count = count;
initBits &= ~INIT_BIT_COUNT;
return this;
}
/**
* Builds new {@link org.glowroot.storage.repo.ImmutableErrorMessageCount ImmutableErrorMessageCount}.
* @return immutable instance of ErrorMessageCount
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableErrorMessageCount build()
throws IllegalStateException {
checkRequiredAttributes(); return new ImmutableErrorMessageCount(message, count);
}
private boolean messageIsSet() {
return (initBits & INIT_BIT_MESSAGE) == 0;
}
private boolean countIsSet() {
return (initBits & INIT_BIT_COUNT) == 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");
if (!countIsSet()) attributes.add("count");
return "Cannot build ErrorMessageCount, some of required attributes are not set " + attributes;
}
}
}