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

org.glowroot.common.live.ImmutableOverallSummary Maven / Gradle / Ivy

There is a newer version: 0.9.24
Show newest version
package org.glowroot.common.live;

import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonCreator;
import org.glowroot.agent.shaded.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import com.google.common.primitives.Doubles;
import com.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 LiveAggregateRepository.OverallSummary}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableOverallSummary.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "LiveAggregateRepository.OverallSummary"}) @Immutable public final class ImmutableOverallSummary implements LiveAggregateRepository.OverallSummary { private final double totalDurationNanos; private final long transactionCount; private ImmutableOverallSummary(double totalDurationNanos, long transactionCount) { this.totalDurationNanos = totalDurationNanos; this.transactionCount = transactionCount; } /** * @return The value of the {@code totalDurationNanos} attribute */ @JsonProperty @Override public double totalDurationNanos() { return totalDurationNanos; } /** * @return The value of the {@code transactionCount} attribute */ @JsonProperty @Override public long transactionCount() { return transactionCount; } /** * Copy the current immutable object by setting a value for the {@link LiveAggregateRepository.OverallSummary#totalDurationNanos() totalDurationNanos} attribute. * A value strict bits equality used to prevent copying of the same value by returning {@code this}. * @param value A new value for totalDurationNanos * @return A modified copy of the {@code this} object */ public final ImmutableOverallSummary withTotalDurationNanos(double value) { if (Double.doubleToLongBits(this.totalDurationNanos) == Double.doubleToLongBits(value)) return this; return new ImmutableOverallSummary(value, this.transactionCount); } /** * Copy the current immutable object by setting a value for the {@link LiveAggregateRepository.OverallSummary#transactionCount() transactionCount} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for transactionCount * @return A modified copy of the {@code this} object */ public final ImmutableOverallSummary withTransactionCount(long value) { if (this.transactionCount == value) return this; return new ImmutableOverallSummary(this.totalDurationNanos, value); } /** * This instance is equal to all instances of {@code ImmutableOverallSummary} that have 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 ImmutableOverallSummary && equalTo((ImmutableOverallSummary) another); } private boolean equalTo(ImmutableOverallSummary another) { return Double.doubleToLongBits(totalDurationNanos) == Double.doubleToLongBits(another.totalDurationNanos) && transactionCount == another.transactionCount; } /** * Computes a hash code from attributes: {@code totalDurationNanos}, {@code transactionCount}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + Doubles.hashCode(totalDurationNanos); h = h * 17 + Longs.hashCode(transactionCount); return h; } /** * Prints the immutable value {@code OverallSummary...} with all non-generated * and non-auxiliary attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("OverallSummary") .add("totalDurationNanos", totalDurationNanos) .add("transactionCount", transactionCount) .toString(); } /** * Utility type used to correctly read immutable object from JSON representation. * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure */ @Deprecated static final class Json implements LiveAggregateRepository.OverallSummary { @Nullable Double totalDurationNanos; @Nullable Long transactionCount; @JsonProperty public void setTotalDurationNanos(double totalDurationNanos) { this.totalDurationNanos = totalDurationNanos; } @JsonProperty public void setTransactionCount(long transactionCount) { this.transactionCount = transactionCount; } @Override public double totalDurationNanos() { throw new UnsupportedOperationException(); } @Override public long transactionCount() { throw new UnsupportedOperationException(); } } /** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonCreator static ImmutableOverallSummary fromJson(Json json) { ImmutableOverallSummary.Builder builder = ImmutableOverallSummary.builder(); if (json.totalDurationNanos != null) { builder.totalDurationNanos(json.totalDurationNanos); } if (json.transactionCount != null) { builder.transactionCount(json.transactionCount); } return builder.build(); } /** * Creates an immutable copy of a {@link LiveAggregateRepository.OverallSummary} 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 OverallSummary instance */ public static ImmutableOverallSummary copyOf(LiveAggregateRepository.OverallSummary instance) { if (instance instanceof ImmutableOverallSummary) { return (ImmutableOverallSummary) instance; } return ImmutableOverallSummary.builder() .copyFrom(instance) .build(); } /** * Creates a builder for {@link ImmutableOverallSummary ImmutableOverallSummary}. * @return A new ImmutableOverallSummary builder */ public static ImmutableOverallSummary.Builder builder() { return new ImmutableOverallSummary.Builder(); } /** * Builds instances of type {@link ImmutableOverallSummary ImmutableOverallSummary}. * 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. */ @NotThreadSafe public static final class Builder { private static final long INIT_BIT_TOTAL_DURATION_NANOS = 0x1L; private static final long INIT_BIT_TRANSACTION_COUNT = 0x2L; private long initBits = 0x3; private double totalDurationNanos; private long transactionCount; private Builder() { } /** * Fill a builder with attribute values from the provided {@code OverallSummary} 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 copyFrom(LiveAggregateRepository.OverallSummary instance) { Preconditions.checkNotNull(instance, "instance"); totalDurationNanos(instance.totalDurationNanos()); transactionCount(instance.transactionCount()); return this; } /** * Initializes the value for the {@link LiveAggregateRepository.OverallSummary#totalDurationNanos() totalDurationNanos} attribute. * @param totalDurationNanos The value for totalDurationNanos * @return {@code this} builder for use in a chained invocation */ public final Builder totalDurationNanos(double totalDurationNanos) { this.totalDurationNanos = totalDurationNanos; initBits &= ~INIT_BIT_TOTAL_DURATION_NANOS; return this; } /** * Initializes the value for the {@link LiveAggregateRepository.OverallSummary#transactionCount() transactionCount} attribute. * @param transactionCount The value for transactionCount * @return {@code this} builder for use in a chained invocation */ public final Builder transactionCount(long transactionCount) { this.transactionCount = transactionCount; initBits &= ~INIT_BIT_TRANSACTION_COUNT; return this; } /** * Builds a new {@link ImmutableOverallSummary ImmutableOverallSummary}. * @return An immutable instance of OverallSummary * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableOverallSummary build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableOverallSummary(totalDurationNanos, transactionCount); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_TOTAL_DURATION_NANOS) != 0) attributes.add("totalDurationNanos"); if ((initBits & INIT_BIT_TRANSACTION_COUNT) != 0) attributes.add("transactionCount"); return "Cannot build OverallSummary, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy