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

org.glowroot.collector.ErrorPoint Maven / Gradle / Ivy

The newest version!
package org.glowroot.collector;

import org.glowroot.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.shaded.fasterxml.jackson.annotation.JsonProperty;
import org.glowroot.shaded.google.common.base.MoreObjects;
import org.glowroot.shaded.google.common.collect.Lists;
import org.glowroot.shaded.google.common.primitives.Longs;
import java.util.Collection;
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 ErrorPointBase}.
 * 

* Use builder to create immutable instances: * {@code ErrorPoint.builder()}. * Use static factory method to create immutable instances: * {@code ErrorPoint.of()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "ErrorPointBase"}) @Immutable public final class ErrorPoint extends ErrorPointBase { private final long captureTime; private final long errorCount; private final long transactionCount; private ErrorPoint(long captureTime, long errorCount, long transactionCount) { this.captureTime = captureTime; this.errorCount = errorCount; this.transactionCount = transactionCount; } /** * {@inheritDoc} * @return value of {@code captureTime} attribute */ @JsonProperty("captureTime") @Override public long captureTime() { return captureTime; } /** * {@inheritDoc} * @return value of {@code errorCount} attribute */ @JsonProperty("errorCount") @Override public long errorCount() { return errorCount; } /** * {@inheritDoc} * @return value of {@code transactionCount} attribute */ @JsonProperty("transactionCount") @Override public long transactionCount() { return transactionCount; } /** * Copy current immutable object by setting value for {@link ErrorPointBase#captureTime() captureTime}. * Value equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for captureTime * @return modified copy of the {@code this} object */ public final ErrorPoint withCaptureTime(long value) { if (this.captureTime == value) { return this; } long newValue = value; return new ErrorPoint(newValue, this.errorCount, this.transactionCount); } /** * Copy current immutable object by setting value for {@link ErrorPointBase#errorCount() errorCount}. * Value equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for errorCount * @return modified copy of the {@code this} object */ public final ErrorPoint withErrorCount(long value) { if (this.errorCount == value) { return this; } long newValue = value; return new ErrorPoint(this.captureTime, newValue, this.transactionCount); } /** * Copy current immutable object by setting value for {@link ErrorPointBase#transactionCount() transactionCount}. * Value equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for transactionCount * @return modified copy of the {@code this} object */ public final ErrorPoint withTransactionCount(long value) { if (this.transactionCount == value) { return this; } long newValue = value; return new ErrorPoint(this.captureTime, this.errorCount, newValue); } /** * This instance is equal to instances of {@code ErrorPoint} with equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(@Nullable Object another) { return this == another || (another instanceof ErrorPoint && equalTo((ErrorPoint) another)); } private boolean equalTo(ErrorPoint another) { return captureTime == another.captureTime && errorCount == another.errorCount && transactionCount == another.transactionCount; } /** * Computes hash code from attributes: {@code captureTime}, {@code errorCount}, {@code transactionCount}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + Longs.hashCode(captureTime); h = h * 17 + Longs.hashCode(errorCount); h = h * 17 + Longs.hashCode(transactionCount); return h; } /** * Prints immutable value {@code ErrorPoint{...}} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("ErrorPoint") .add("captureTime", captureTime) .add("errorCount", errorCount) .add("transactionCount", transactionCount) .toString(); } @JsonCreator public static ErrorPoint fromAllAttributes( @JsonProperty("captureTime") @Nullable Long captureTime, @JsonProperty("errorCount") @Nullable Long errorCount, @JsonProperty("transactionCount") @Nullable Long transactionCount) { ErrorPoint.Builder builder = ErrorPoint.builder(); if (captureTime != null) { builder.captureTime(captureTime); } if (errorCount != null) { builder.errorCount(errorCount); } if (transactionCount != null) { builder.transactionCount(transactionCount); } return builder.build(); } /** * Construct new immutable {@code ErrorPoint} instance. * @param captureTime value for {@code captureTime} * @param errorCount value for {@code errorCount} * @param transactionCount value for {@code transactionCount} * @return immutable ErrorPoint instance */ public static org.glowroot.collector.ErrorPoint of(long captureTime, long errorCount, long transactionCount) { return new ErrorPoint(captureTime, errorCount, transactionCount); } /** * Creates immutable copy of {@link ErrorPointBase}. * 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 ErrorPoint instance */ public static ErrorPoint copyOf(ErrorPointBase instance) { if (instance instanceof ErrorPoint) { return (ErrorPoint) instance; } return ErrorPoint.builder() .captureTime(instance.captureTime()) .errorCount(instance.errorCount()) .transactionCount(instance.transactionCount()) .build(); } /** * Creates builder for {@link org.glowroot.collector.ErrorPoint}. * @return new ErrorPoint builder */ public static ErrorPoint.Builder builder() { return new ErrorPoint.Builder(); } /** * Builds instances of {@link org.glowroot.collector.ErrorPoint}. * Initialized attributes and then invoke {@link #build()} method to create * immutable instance. *

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 INITIALIZED_BITSET_ALL = 0x7; private static final long INITIALIZED_BIT_CAPTURE_TIME = 0x1L; private static final long INITIALIZED_BIT_ERROR_COUNT = 0x2L; private static final long INITIALIZED_BIT_TRANSACTION_COUNT = 0x4L; private long initializedBitset; private long captureTime; private long errorCount; private long transactionCount; private Builder() {} /** * Initializes value for {@link ErrorPointBase#captureTime() captureTime}. * @param captureTime value for captureTime * @return {@code this} builder for chained invocation */ public final Builder captureTime(long captureTime) { checkNotIsSet(captureTimeIsSet(), "captureTime"); this.captureTime = captureTime; initializedBitset |= INITIALIZED_BIT_CAPTURE_TIME; return this; } /** * Initializes value for {@link ErrorPointBase#errorCount() errorCount}. * @param errorCount value for errorCount * @return {@code this} builder for chained invocation */ public final Builder errorCount(long errorCount) { checkNotIsSet(errorCountIsSet(), "errorCount"); this.errorCount = errorCount; initializedBitset |= INITIALIZED_BIT_ERROR_COUNT; return this; } /** * Initializes value for {@link ErrorPointBase#transactionCount() transactionCount}. * @param transactionCount value for transactionCount * @return {@code this} builder for chained invocation */ public final Builder transactionCount(long transactionCount) { checkNotIsSet(transactionCountIsSet(), "transactionCount"); this.transactionCount = transactionCount; initializedBitset |= INITIALIZED_BIT_TRANSACTION_COUNT; return this; } /** * Builds new {@link org.glowroot.collector.ErrorPoint}. * @return immutable instance of ErrorPoint */ public ErrorPoint build() { checkRequiredAttributes(); return new ErrorPoint(captureTime, errorCount, transactionCount); } private boolean captureTimeIsSet() { return (initializedBitset & INITIALIZED_BIT_CAPTURE_TIME) != 0; } private boolean errorCountIsSet() { return (initializedBitset & INITIALIZED_BIT_ERROR_COUNT) != 0; } private boolean transactionCountIsSet() { return (initializedBitset & INITIALIZED_BIT_TRANSACTION_COUNT) != 0; } private void checkNotIsSet(boolean isSet, String name) { if (isSet) { throw new IllegalStateException("Builder of ErrorPoint is strict, attribute is already set: ".concat(name)); } } private void checkRequiredAttributes() { if (initializedBitset != INITIALIZED_BITSET_ALL) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { Collection attributes = Lists.newArrayList(); if (!captureTimeIsSet()) { attributes.add("captureTime"); } if (!errorCountIsSet()) { attributes.add("errorCount"); } if (!transactionCountIsSet()) { attributes.add("transactionCount"); } return "Cannot build ErrorPoint, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy