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

org.glowroot.local.store.TracePoint Maven / Gradle / Ivy

The newest version!
package org.glowroot.local.store;

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.base.Preconditions;
import org.glowroot.shaded.google.common.collect.Lists;
import org.glowroot.shaded.google.common.primitives.Booleans;
import org.glowroot.shaded.google.common.primitives.Doubles;
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 TracePointBase}.
 * 

* Use builder to create immutable instances: * {@code TracePoint.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "TracePointBase"}) @Immutable public final class TracePoint extends TracePointBase { private final String id; private final long captureTime; private final double duration; private final boolean error; private TracePoint(String id, long captureTime, double duration, boolean error) { this.id = id; this.captureTime = captureTime; this.duration = duration; this.error = error; } /** * {@inheritDoc} * @return value of {@code id} attribute */ @JsonProperty("id") @Override public String id() { return id; } /** * {@inheritDoc} * @return value of {@code captureTime} attribute */ @JsonProperty("captureTime") @Override public long captureTime() { return captureTime; } /** * {@inheritDoc} * @return value of {@code duration} attribute */ @JsonProperty("duration") @Override public double duration() { return duration; } /** * {@inheritDoc} * @return value of {@code error} attribute */ @JsonProperty("error") @Override public boolean error() { return error; } /** * Copy current immutable object by setting value for {@link TracePointBase#id() id}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for id * @return modified copy of the {@code this} object */ public final TracePoint withId(String value) { if (this.id == value) { return this; } String newValue = Preconditions.checkNotNull(value); return new TracePoint(newValue, this.captureTime, this.duration, this.error); } /** * Copy current immutable object by setting value for {@link TracePointBase#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 TracePoint withCaptureTime(long value) { if (this.captureTime == value) { return this; } long newValue = value; return new TracePoint(this.id, newValue, this.duration, this.error); } /** * Copy current immutable object by setting value for {@link TracePointBase#duration() duration}. * @param value new value for duration * @return modified copy of the {@code this} object */ public final TracePoint withDuration(double value) { double newValue = value; return new TracePoint(this.id, this.captureTime, newValue, this.error); } /** * Copy current immutable object by setting value for {@link TracePointBase#error() error}. * Value equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for error * @return modified copy of the {@code this} object */ public final TracePoint withError(boolean value) { if (this.error == value) { return this; } boolean newValue = value; return new TracePoint(this.id, this.captureTime, this.duration, newValue); } /** * This instance is equal to instances of {@code TracePoint} 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 TracePoint && equalTo((TracePoint) another)); } private boolean equalTo(TracePoint another) { return id.equals(another.id) && captureTime == another.captureTime && Double.doubleToLongBits(duration) == Double.doubleToLongBits(another.duration) && error == another.error; } /** * Computes hash code from attributes: {@code id}, {@code captureTime}, {@code duration}, {@code error}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + id.hashCode(); h = h * 17 + Longs.hashCode(captureTime); h = h * 17 + Doubles.hashCode(duration); h = h * 17 + Booleans.hashCode(error); return h; } /** * Prints immutable value {@code TracePoint{...}} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("TracePoint") .add("id", id) .add("captureTime", captureTime) .add("duration", duration) .add("error", error) .toString(); } @JsonCreator public static TracePoint fromAllAttributes( @JsonProperty("id") @Nullable String id, @JsonProperty("captureTime") @Nullable Long captureTime, @JsonProperty("duration") @Nullable java.lang.Double duration, @JsonProperty("error") @Nullable Boolean error) { TracePoint.Builder builder = TracePoint.builder(); if (id != null) { builder.id(id); } if (captureTime != null) { builder.captureTime(captureTime); } if (duration != null) { builder.duration(duration); } if (error != null) { builder.error(error); } return builder.build(); } /** * Creates immutable copy of {@link TracePointBase}. * 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 TracePoint instance */ public static TracePoint copyOf(TracePointBase instance) { if (instance instanceof TracePoint) { return (TracePoint) instance; } return TracePoint.builder() .id(instance.id()) .captureTime(instance.captureTime()) .duration(instance.duration()) .error(instance.error()) .build(); } /** * Creates builder for {@link org.glowroot.local.store.TracePoint}. * @return new TracePoint builder */ public static TracePoint.Builder builder() { return new TracePoint.Builder(); } /** * Builds instances of {@link org.glowroot.local.store.TracePoint}. * 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 = 0xf; private static final long INITIALIZED_BIT_ID = 0x1L; private static final long INITIALIZED_BIT_CAPTURE_TIME = 0x2L; private static final long INITIALIZED_BIT_DURATION = 0x4L; private static final long INITIALIZED_BIT_ERROR = 0x8L; private long initializedBitset; private @Nullable String id; private long captureTime; private double duration; private boolean error; private Builder() {} /** * Initializes value for {@link TracePointBase#id() id}. * @param id value for id * @return {@code this} builder for chained invocation */ public final Builder id(String id) { checkNotIsSet(idIsSet(), "id"); this.id = Preconditions.checkNotNull(id); initializedBitset |= INITIALIZED_BIT_ID; return this; } /** * Initializes value for {@link TracePointBase#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 TracePointBase#duration() duration}. * @param duration value for duration * @return {@code this} builder for chained invocation */ public final Builder duration(double duration) { checkNotIsSet(durationIsSet(), "duration"); this.duration = duration; initializedBitset |= INITIALIZED_BIT_DURATION; return this; } /** * Initializes value for {@link TracePointBase#error() error}. * @param error value for error * @return {@code this} builder for chained invocation */ public final Builder error(boolean error) { checkNotIsSet(errorIsSet(), "error"); this.error = error; initializedBitset |= INITIALIZED_BIT_ERROR; return this; } /** * Builds new {@link org.glowroot.local.store.TracePoint}. * @return immutable instance of TracePoint */ public TracePoint build() { checkRequiredAttributes(); return new TracePoint(id, captureTime, duration, error); } private boolean idIsSet() { return (initializedBitset & INITIALIZED_BIT_ID) != 0; } private boolean captureTimeIsSet() { return (initializedBitset & INITIALIZED_BIT_CAPTURE_TIME) != 0; } private boolean durationIsSet() { return (initializedBitset & INITIALIZED_BIT_DURATION) != 0; } private boolean errorIsSet() { return (initializedBitset & INITIALIZED_BIT_ERROR) != 0; } private void checkNotIsSet(boolean isSet, String name) { if (isSet) { throw new IllegalStateException("Builder of TracePoint 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 (!idIsSet()) { attributes.add("id"); } if (!captureTimeIsSet()) { attributes.add("captureTime"); } if (!durationIsSet()) { attributes.add("duration"); } if (!errorIsSet()) { attributes.add("error"); } return "Cannot build TracePoint, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy