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

org.glowroot.instrumentation.test.harness.ImmutableIncomingSpan Maven / Gradle / Ivy

There is a newer version: 0.14.9
Show newest version
package org.glowroot.instrumentation.test.harness;

import org.glowroot.instrumentation.test.harness.shaded.com.google.errorprone.annotations.CanIgnoreReturnValue;
import org.glowroot.instrumentation.test.harness.shaded.com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.immutables.value.Generated;

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

* Use the builder to create immutable instances: * {@code ImmutableIncomingSpan.builder()}. */ @Generated(from = "IncomingSpan", generator = "Immutables") @SuppressWarnings({"all"}) @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") public final class ImmutableIncomingSpan implements IncomingSpan { private final long totalNanos; private final String message; private final Map detail; private final @Nullable Long locationStackTraceMillis; private final String transactionType; private final String transactionName; private final @Nullable IncomingSpan.IncomingSpanError error; private final String user; private final IncomingSpan.Timer mainThreadTimer; private final List auxThreadTimers; private final List asyncTimers; private final List childSpans; private final boolean resourceLeakDetected; private final boolean resourceLeakDetectedWithLocation; private ImmutableIncomingSpan( long totalNanos, String message, Map detail, @Nullable Long locationStackTraceMillis, String transactionType, String transactionName, @Nullable IncomingSpan.IncomingSpanError error, String user, IncomingSpan.Timer mainThreadTimer, List auxThreadTimers, List asyncTimers, List childSpans, boolean resourceLeakDetected, boolean resourceLeakDetectedWithLocation) { this.totalNanos = totalNanos; this.message = message; this.detail = detail; this.locationStackTraceMillis = locationStackTraceMillis; this.transactionType = transactionType; this.transactionName = transactionName; this.error = error; this.user = user; this.mainThreadTimer = mainThreadTimer; this.auxThreadTimers = auxThreadTimers; this.asyncTimers = asyncTimers; this.childSpans = childSpans; this.resourceLeakDetected = resourceLeakDetected; this.resourceLeakDetectedWithLocation = resourceLeakDetectedWithLocation; } /** * @return The value of the {@code totalNanos} attribute */ @Override public long totalNanos() { return totalNanos; } /** * @return The value of the {@code message} attribute */ @Override public String message() { return message; } /** * @return The value of the {@code detail} attribute */ @Override public Map detail() { return detail; } /** * @return The value of the {@code locationStackTraceMillis} attribute */ @Override public @Nullable Long locationStackTraceMillis() { return locationStackTraceMillis; } /** * @return The value of the {@code transactionType} attribute */ @Override public String transactionType() { return transactionType; } /** * @return The value of the {@code transactionName} attribute */ @Override public String transactionName() { return transactionName; } /** * @return The value of the {@code error} attribute */ @Override public @Nullable IncomingSpan.IncomingSpanError error() { return error; } /** * @return The value of the {@code user} attribute */ @Override public String user() { return user; } /** * @return The value of the {@code mainThreadTimer} attribute */ @Override public IncomingSpan.Timer mainThreadTimer() { return mainThreadTimer; } /** * @return The value of the {@code auxThreadTimers} attribute */ @Override public List auxThreadTimers() { return auxThreadTimers; } /** * @return The value of the {@code asyncTimers} attribute */ @Override public List asyncTimers() { return asyncTimers; } /** * @return The value of the {@code childSpans} attribute */ @Override public List childSpans() { return childSpans; } /** * @return The value of the {@code resourceLeakDetected} attribute */ @Override public boolean resourceLeakDetected() { return resourceLeakDetected; } /** * @return The value of the {@code resourceLeakDetectedWithLocation} attribute */ @Override public boolean resourceLeakDetectedWithLocation() { return resourceLeakDetectedWithLocation; } /** * Copy the current immutable object by setting a value for the {@link IncomingSpan#totalNanos() totalNanos} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for totalNanos * @return A modified copy of the {@code this} object */ public final ImmutableIncomingSpan withTotalNanos(long value) { if (this.totalNanos == value) return this; return new ImmutableIncomingSpan( value, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object by setting a value for the {@link IncomingSpan#message() message} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for message * @return A modified copy of the {@code this} object */ public final ImmutableIncomingSpan withMessage(String value) { String newValue = ImmutableIncomingSpan.requireNonNull(value, "message"); if (this.message.equals(newValue)) return this; return new ImmutableIncomingSpan( this.totalNanos, newValue, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object by replacing the {@link IncomingSpan#detail() detail} map with the specified map. * Nulls are not permitted as keys or values. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param entries The entries to be added to the detail map * @return A modified copy of {@code this} object */ public final ImmutableIncomingSpan withDetail(Map entries) { if (this.detail == entries) return this; Map newValue = createUnmodifiableMap(false, false, entries); return new ImmutableIncomingSpan( this.totalNanos, this.message, newValue, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object by setting a value for the {@link IncomingSpan#locationStackTraceMillis() locationStackTraceMillis} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for locationStackTraceMillis (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableIncomingSpan withLocationStackTraceMillis(@Nullable Long value) { if (ImmutableIncomingSpan.equals(this.locationStackTraceMillis, value)) return this; return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, value, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object by setting a value for the {@link IncomingSpan#transactionType() transactionType} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for transactionType * @return A modified copy of the {@code this} object */ public final ImmutableIncomingSpan withTransactionType(String value) { String newValue = ImmutableIncomingSpan.requireNonNull(value, "transactionType"); if (this.transactionType.equals(newValue)) return this; return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, newValue, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object by setting a value for the {@link IncomingSpan#transactionName() transactionName} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for transactionName * @return A modified copy of the {@code this} object */ public final ImmutableIncomingSpan withTransactionName(String value) { String newValue = ImmutableIncomingSpan.requireNonNull(value, "transactionName"); if (this.transactionName.equals(newValue)) return this; return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, newValue, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object by setting a value for the {@link IncomingSpan#error() error} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for error (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableIncomingSpan withError(@Nullable IncomingSpan.IncomingSpanError value) { if (this.error == value) return this; return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, value, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object by setting a value for the {@link IncomingSpan#user() user} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for user * @return A modified copy of the {@code this} object */ public final ImmutableIncomingSpan withUser(String value) { String newValue = ImmutableIncomingSpan.requireNonNull(value, "user"); if (this.user.equals(newValue)) return this; return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, newValue, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object by setting a value for the {@link IncomingSpan#mainThreadTimer() mainThreadTimer} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for mainThreadTimer * @return A modified copy of the {@code this} object */ public final ImmutableIncomingSpan withMainThreadTimer(IncomingSpan.Timer value) { if (this.mainThreadTimer == value) return this; IncomingSpan.Timer newValue = ImmutableIncomingSpan.requireNonNull(value, "mainThreadTimer"); return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, newValue, this.auxThreadTimers, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object with elements that replace the content of {@link IncomingSpan#auxThreadTimers() auxThreadTimers}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableIncomingSpan withAuxThreadTimers(IncomingSpan.Timer... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, newValue, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object with elements that replace the content of {@link IncomingSpan#auxThreadTimers() auxThreadTimers}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of auxThreadTimers elements to set * @return A modified copy of {@code this} object */ public final ImmutableIncomingSpan withAuxThreadTimers(Iterable elements) { if (this.auxThreadTimers == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, newValue, this.asyncTimers, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object with elements that replace the content of {@link IncomingSpan#asyncTimers() asyncTimers}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableIncomingSpan withAsyncTimers(IncomingSpan.Timer... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, newValue, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object with elements that replace the content of {@link IncomingSpan#asyncTimers() asyncTimers}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of asyncTimers elements to set * @return A modified copy of {@code this} object */ public final ImmutableIncomingSpan withAsyncTimers(Iterable elements) { if (this.asyncTimers == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, newValue, this.childSpans, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object with elements that replace the content of {@link IncomingSpan#childSpans() childSpans}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableIncomingSpan withChildSpans(Span... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, newValue, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object with elements that replace the content of {@link IncomingSpan#childSpans() childSpans}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of childSpans elements to set * @return A modified copy of {@code this} object */ public final ImmutableIncomingSpan withChildSpans(Iterable elements) { if (this.childSpans == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, newValue, this.resourceLeakDetected, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object by setting a value for the {@link IncomingSpan#resourceLeakDetected() resourceLeakDetected} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for resourceLeakDetected * @return A modified copy of the {@code this} object */ public final ImmutableIncomingSpan withResourceLeakDetected(boolean value) { if (this.resourceLeakDetected == value) return this; return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, this.childSpans, value, this.resourceLeakDetectedWithLocation); } /** * Copy the current immutable object by setting a value for the {@link IncomingSpan#resourceLeakDetectedWithLocation() resourceLeakDetectedWithLocation} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for resourceLeakDetectedWithLocation * @return A modified copy of the {@code this} object */ public final ImmutableIncomingSpan withResourceLeakDetectedWithLocation(boolean value) { if (this.resourceLeakDetectedWithLocation == value) return this; return new ImmutableIncomingSpan( this.totalNanos, this.message, this.detail, this.locationStackTraceMillis, this.transactionType, this.transactionName, this.error, this.user, this.mainThreadTimer, this.auxThreadTimers, this.asyncTimers, this.childSpans, this.resourceLeakDetected, value); } /** * This instance is equal to all instances of {@code ImmutableIncomingSpan} that have equal attribute values. * @return {@code true} if {@code this} is equal to {@code another} instance */ @Override public boolean equals(Object another) { if (this == another) return true; return another instanceof ImmutableIncomingSpan && equalTo((ImmutableIncomingSpan) another); } private boolean equalTo(ImmutableIncomingSpan another) { return totalNanos == another.totalNanos && message.equals(another.message) && detail.equals(another.detail) && ImmutableIncomingSpan.equals(locationStackTraceMillis, another.locationStackTraceMillis) && transactionType.equals(another.transactionType) && transactionName.equals(another.transactionName) && ImmutableIncomingSpan.equals(error, another.error) && user.equals(another.user) && mainThreadTimer.equals(another.mainThreadTimer) && auxThreadTimers.equals(another.auxThreadTimers) && asyncTimers.equals(another.asyncTimers) && childSpans.equals(another.childSpans) && resourceLeakDetected == another.resourceLeakDetected && resourceLeakDetectedWithLocation == another.resourceLeakDetectedWithLocation; } /** * Computes a hash code from attributes: {@code totalNanos}, {@code message}, {@code detail}, {@code locationStackTraceMillis}, {@code transactionType}, {@code transactionName}, {@code error}, {@code user}, {@code mainThreadTimer}, {@code auxThreadTimers}, {@code asyncTimers}, {@code childSpans}, {@code resourceLeakDetected}, {@code resourceLeakDetectedWithLocation}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + (int) (totalNanos ^ (totalNanos >>> 32)); h += (h << 5) + message.hashCode(); h += (h << 5) + detail.hashCode(); h += (h << 5) + ImmutableIncomingSpan.hashCode(locationStackTraceMillis); h += (h << 5) + transactionType.hashCode(); h += (h << 5) + transactionName.hashCode(); h += (h << 5) + ImmutableIncomingSpan.hashCode(error); h += (h << 5) + user.hashCode(); h += (h << 5) + mainThreadTimer.hashCode(); h += (h << 5) + auxThreadTimers.hashCode(); h += (h << 5) + asyncTimers.hashCode(); h += (h << 5) + childSpans.hashCode(); h += (h << 5) + (resourceLeakDetected ? 1231 : 1237); h += (h << 5) + (resourceLeakDetectedWithLocation ? 1231 : 1237); return h; } /** * Prints the immutable value {@code IncomingSpan} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "IncomingSpan{" + "totalNanos=" + totalNanos + ", message=" + message + ", detail=" + detail + ", locationStackTraceMillis=" + locationStackTraceMillis + ", transactionType=" + transactionType + ", transactionName=" + transactionName + ", error=" + error + ", user=" + user + ", mainThreadTimer=" + mainThreadTimer + ", auxThreadTimers=" + auxThreadTimers + ", asyncTimers=" + asyncTimers + ", childSpans=" + childSpans + ", resourceLeakDetected=" + resourceLeakDetected + ", resourceLeakDetectedWithLocation=" + resourceLeakDetectedWithLocation + "}"; } /** * Creates an immutable copy of a {@link IncomingSpan} 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 IncomingSpan instance */ public static ImmutableIncomingSpan copyOf(IncomingSpan instance) { if (instance instanceof ImmutableIncomingSpan) { return (ImmutableIncomingSpan) instance; } return ImmutableIncomingSpan.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableIncomingSpan ImmutableIncomingSpan}. *

   * ImmutableIncomingSpan.builder()
   *    .totalNanos(long) // required {@link IncomingSpan#totalNanos() totalNanos}
   *    .message(String) // required {@link IncomingSpan#message() message}
   *    .putDetail|putAllDetail(String => Object) // {@link IncomingSpan#detail() detail} mappings
   *    .locationStackTraceMillis(Long | null) // nullable {@link IncomingSpan#locationStackTraceMillis() locationStackTraceMillis}
   *    .transactionType(String) // required {@link IncomingSpan#transactionType() transactionType}
   *    .transactionName(String) // required {@link IncomingSpan#transactionName() transactionName}
   *    .error(org.glowroot.instrumentation.test.harness.IncomingSpan.IncomingSpanError | null) // nullable {@link IncomingSpan#error() error}
   *    .user(String) // required {@link IncomingSpan#user() user}
   *    .mainThreadTimer(org.glowroot.instrumentation.test.harness.IncomingSpan.Timer) // required {@link IncomingSpan#mainThreadTimer() mainThreadTimer}
   *    .addAuxThreadTimers|addAllAuxThreadTimers(org.glowroot.instrumentation.test.harness.IncomingSpan.Timer) // {@link IncomingSpan#auxThreadTimers() auxThreadTimers} elements
   *    .addAsyncTimers|addAllAsyncTimers(org.glowroot.instrumentation.test.harness.IncomingSpan.Timer) // {@link IncomingSpan#asyncTimers() asyncTimers} elements
   *    .addChildSpans|addAllChildSpans(org.glowroot.instrumentation.test.harness.Span) // {@link IncomingSpan#childSpans() childSpans} elements
   *    .resourceLeakDetected(boolean) // required {@link IncomingSpan#resourceLeakDetected() resourceLeakDetected}
   *    .resourceLeakDetectedWithLocation(boolean) // required {@link IncomingSpan#resourceLeakDetectedWithLocation() resourceLeakDetectedWithLocation}
   *    .build();
   * 
* @return A new ImmutableIncomingSpan builder */ public static ImmutableIncomingSpan.Builder builder() { return new ImmutableIncomingSpan.Builder(); } /** * Builds instances of type {@link ImmutableIncomingSpan ImmutableIncomingSpan}. * 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. */ @Generated(from = "IncomingSpan", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_TOTAL_NANOS = 0x1L; private static final long INIT_BIT_MESSAGE = 0x2L; private static final long INIT_BIT_TRANSACTION_TYPE = 0x4L; private static final long INIT_BIT_TRANSACTION_NAME = 0x8L; private static final long INIT_BIT_USER = 0x10L; private static final long INIT_BIT_MAIN_THREAD_TIMER = 0x20L; private static final long INIT_BIT_RESOURCE_LEAK_DETECTED = 0x40L; private static final long INIT_BIT_RESOURCE_LEAK_DETECTED_WITH_LOCATION = 0x80L; private long initBits = 0xffL; private long totalNanos; private String message; private Map detail = new LinkedHashMap(); private Long locationStackTraceMillis; private String transactionType; private String transactionName; private IncomingSpan.IncomingSpanError error; private String user; private IncomingSpan.Timer mainThreadTimer; private List auxThreadTimers = new ArrayList(); private List asyncTimers = new ArrayList(); private List childSpans = new ArrayList(); private boolean resourceLeakDetected; private boolean resourceLeakDetectedWithLocation; private Builder() { } /** * Fill a builder with attribute values from the provided {@code org.glowroot.instrumentation.test.harness.Span} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(Span instance) { ImmutableIncomingSpan.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code org.glowroot.instrumentation.test.harness.IncomingSpan} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder from(IncomingSpan instance) { ImmutableIncomingSpan.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { if (object instanceof Span) { Span instance = (Span) object; putAllDetail(instance.detail()); message(instance.message()); @Nullable Long locationStackTraceMillisValue = instance.locationStackTraceMillis(); if (locationStackTraceMillisValue != null) { locationStackTraceMillis(locationStackTraceMillisValue); } totalNanos(instance.totalNanos()); } if (object instanceof IncomingSpan) { IncomingSpan instance = (IncomingSpan) object; transactionType(instance.transactionType()); addAllAsyncTimers(instance.asyncTimers()); resourceLeakDetectedWithLocation(instance.resourceLeakDetectedWithLocation()); addAllChildSpans(instance.childSpans()); resourceLeakDetected(instance.resourceLeakDetected()); mainThreadTimer(instance.mainThreadTimer()); addAllAuxThreadTimers(instance.auxThreadTimers()); transactionName(instance.transactionName()); @Nullable IncomingSpan.IncomingSpanError errorValue = instance.error(); if (errorValue != null) { error(errorValue); } user(instance.user()); } } /** * Initializes the value for the {@link IncomingSpan#totalNanos() totalNanos} attribute. * @param totalNanos The value for totalNanos * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder totalNanos(long totalNanos) { this.totalNanos = totalNanos; initBits &= ~INIT_BIT_TOTAL_NANOS; return this; } /** * Initializes the value for the {@link IncomingSpan#message() message} attribute. * @param message The value for message * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder message(String message) { this.message = ImmutableIncomingSpan.requireNonNull(message, "message"); initBits &= ~INIT_BIT_MESSAGE; return this; } /** * Put one entry to the {@link IncomingSpan#detail() detail} map. * @param key The key in the detail map * @param value The associated value in the detail map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putDetail(String key, Object value) { this.detail.put(key, value); return this; } /** * Put one entry to the {@link IncomingSpan#detail() detail} map. Nulls are not permitted * @param entry The key and value entry * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putDetail(Map.Entry entry) { String k = entry.getKey(); Object v = entry.getValue(); this.detail.put(k, v); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link IncomingSpan#detail() detail} map. Nulls are not permitted * @param entries The entries that will be added to the detail map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder detail(Map entries) { this.detail.clear(); return putAllDetail(entries); } /** * Put all mappings from the specified map as entries to {@link IncomingSpan#detail() detail} map. Nulls are not permitted * @param entries The entries that will be added to the detail map * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder putAllDetail(Map entries) { for (Map.Entry e : entries.entrySet()) { String k = e.getKey(); Object v = e.getValue(); this.detail.put(k, v); } return this; } /** * Initializes the value for the {@link IncomingSpan#locationStackTraceMillis() locationStackTraceMillis} attribute. * @param locationStackTraceMillis The value for locationStackTraceMillis (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder locationStackTraceMillis(@Nullable Long locationStackTraceMillis) { this.locationStackTraceMillis = locationStackTraceMillis; return this; } /** * Initializes the value for the {@link IncomingSpan#transactionType() transactionType} attribute. * @param transactionType The value for transactionType * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder transactionType(String transactionType) { this.transactionType = ImmutableIncomingSpan.requireNonNull(transactionType, "transactionType"); initBits &= ~INIT_BIT_TRANSACTION_TYPE; return this; } /** * Initializes the value for the {@link IncomingSpan#transactionName() transactionName} attribute. * @param transactionName The value for transactionName * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder transactionName(String transactionName) { this.transactionName = ImmutableIncomingSpan.requireNonNull(transactionName, "transactionName"); initBits &= ~INIT_BIT_TRANSACTION_NAME; return this; } /** * Initializes the value for the {@link IncomingSpan#error() error} attribute. * @param error The value for error (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder error(@Nullable IncomingSpan.IncomingSpanError error) { this.error = error; return this; } /** * Initializes the value for the {@link IncomingSpan#user() user} attribute. * @param user The value for user * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder user(String user) { this.user = ImmutableIncomingSpan.requireNonNull(user, "user"); initBits &= ~INIT_BIT_USER; return this; } /** * Initializes the value for the {@link IncomingSpan#mainThreadTimer() mainThreadTimer} attribute. * @param mainThreadTimer The value for mainThreadTimer * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder mainThreadTimer(IncomingSpan.Timer mainThreadTimer) { this.mainThreadTimer = ImmutableIncomingSpan.requireNonNull(mainThreadTimer, "mainThreadTimer"); initBits &= ~INIT_BIT_MAIN_THREAD_TIMER; return this; } /** * Adds one element to {@link IncomingSpan#auxThreadTimers() auxThreadTimers} list. * @param element A auxThreadTimers element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAuxThreadTimers(IncomingSpan.Timer element) { this.auxThreadTimers.add(ImmutableIncomingSpan.requireNonNull(element, "auxThreadTimers element")); return this; } /** * Adds elements to {@link IncomingSpan#auxThreadTimers() auxThreadTimers} list. * @param elements An array of auxThreadTimers elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAuxThreadTimers(IncomingSpan.Timer... elements) { for (IncomingSpan.Timer element : elements) { this.auxThreadTimers.add(ImmutableIncomingSpan.requireNonNull(element, "auxThreadTimers element")); } return this; } /** * Sets or replaces all elements for {@link IncomingSpan#auxThreadTimers() auxThreadTimers} list. * @param elements An iterable of auxThreadTimers elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder auxThreadTimers(Iterable elements) { this.auxThreadTimers.clear(); return addAllAuxThreadTimers(elements); } /** * Adds elements to {@link IncomingSpan#auxThreadTimers() auxThreadTimers} list. * @param elements An iterable of auxThreadTimers elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllAuxThreadTimers(Iterable elements) { for (IncomingSpan.Timer element : elements) { this.auxThreadTimers.add(ImmutableIncomingSpan.requireNonNull(element, "auxThreadTimers element")); } return this; } /** * Adds one element to {@link IncomingSpan#asyncTimers() asyncTimers} list. * @param element A asyncTimers element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAsyncTimers(IncomingSpan.Timer element) { this.asyncTimers.add(ImmutableIncomingSpan.requireNonNull(element, "asyncTimers element")); return this; } /** * Adds elements to {@link IncomingSpan#asyncTimers() asyncTimers} list. * @param elements An array of asyncTimers elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAsyncTimers(IncomingSpan.Timer... elements) { for (IncomingSpan.Timer element : elements) { this.asyncTimers.add(ImmutableIncomingSpan.requireNonNull(element, "asyncTimers element")); } return this; } /** * Sets or replaces all elements for {@link IncomingSpan#asyncTimers() asyncTimers} list. * @param elements An iterable of asyncTimers elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder asyncTimers(Iterable elements) { this.asyncTimers.clear(); return addAllAsyncTimers(elements); } /** * Adds elements to {@link IncomingSpan#asyncTimers() asyncTimers} list. * @param elements An iterable of asyncTimers elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllAsyncTimers(Iterable elements) { for (IncomingSpan.Timer element : elements) { this.asyncTimers.add(ImmutableIncomingSpan.requireNonNull(element, "asyncTimers element")); } return this; } /** * Adds one element to {@link IncomingSpan#childSpans() childSpans} list. * @param element A childSpans element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addChildSpans(Span element) { this.childSpans.add(ImmutableIncomingSpan.requireNonNull(element, "childSpans element")); return this; } /** * Adds elements to {@link IncomingSpan#childSpans() childSpans} list. * @param elements An array of childSpans elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addChildSpans(Span... elements) { for (Span element : elements) { this.childSpans.add(ImmutableIncomingSpan.requireNonNull(element, "childSpans element")); } return this; } /** * Sets or replaces all elements for {@link IncomingSpan#childSpans() childSpans} list. * @param elements An iterable of childSpans elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder childSpans(Iterable elements) { this.childSpans.clear(); return addAllChildSpans(elements); } /** * Adds elements to {@link IncomingSpan#childSpans() childSpans} list. * @param elements An iterable of childSpans elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllChildSpans(Iterable elements) { for (Span element : elements) { this.childSpans.add(ImmutableIncomingSpan.requireNonNull(element, "childSpans element")); } return this; } /** * Initializes the value for the {@link IncomingSpan#resourceLeakDetected() resourceLeakDetected} attribute. * @param resourceLeakDetected The value for resourceLeakDetected * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder resourceLeakDetected(boolean resourceLeakDetected) { this.resourceLeakDetected = resourceLeakDetected; initBits &= ~INIT_BIT_RESOURCE_LEAK_DETECTED; return this; } /** * Initializes the value for the {@link IncomingSpan#resourceLeakDetectedWithLocation() resourceLeakDetectedWithLocation} attribute. * @param resourceLeakDetectedWithLocation The value for resourceLeakDetectedWithLocation * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder resourceLeakDetectedWithLocation(boolean resourceLeakDetectedWithLocation) { this.resourceLeakDetectedWithLocation = resourceLeakDetectedWithLocation; initBits &= ~INIT_BIT_RESOURCE_LEAK_DETECTED_WITH_LOCATION; return this; } /** * Builds a new {@link ImmutableIncomingSpan ImmutableIncomingSpan}. * @return An immutable instance of IncomingSpan * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableIncomingSpan build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableIncomingSpan( totalNanos, message, createUnmodifiableMap(false, false, detail), locationStackTraceMillis, transactionType, transactionName, error, user, mainThreadTimer, createUnmodifiableList(true, auxThreadTimers), createUnmodifiableList(true, asyncTimers), createUnmodifiableList(true, childSpans), resourceLeakDetected, resourceLeakDetectedWithLocation); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList(); if ((initBits & INIT_BIT_TOTAL_NANOS) != 0) attributes.add("totalNanos"); if ((initBits & INIT_BIT_MESSAGE) != 0) attributes.add("message"); if ((initBits & INIT_BIT_TRANSACTION_TYPE) != 0) attributes.add("transactionType"); if ((initBits & INIT_BIT_TRANSACTION_NAME) != 0) attributes.add("transactionName"); if ((initBits & INIT_BIT_USER) != 0) attributes.add("user"); if ((initBits & INIT_BIT_MAIN_THREAD_TIMER) != 0) attributes.add("mainThreadTimer"); if ((initBits & INIT_BIT_RESOURCE_LEAK_DETECTED) != 0) attributes.add("resourceLeakDetected"); if ((initBits & INIT_BIT_RESOURCE_LEAK_DETECTED_WITH_LOCATION) != 0) attributes.add("resourceLeakDetectedWithLocation"); return "Cannot build IncomingSpan, some of required attributes are not set " + attributes; } } private static T requireNonNull(T object, String message) { if (object == null) throw new NullPointerException(message); return object; } private static int hashCode(Object object) { return object != null ? object.hashCode() : 0; } private static boolean equals(Object left, Object right) { return left == right || (left != null && left.equals(right)); } private static List createSafeList(Iterable iterable, boolean checkNulls, boolean skipNulls) { ArrayList list; if (iterable instanceof Collection) { int size = ((Collection) iterable).size(); if (size == 0) return Collections.emptyList(); list = new ArrayList(); } else { list = new ArrayList(); } for (T element : iterable) { if (skipNulls && element == null) continue; if (checkNulls) ImmutableIncomingSpan.requireNonNull(element, "element"); list.add(element); } return list; } private static List createUnmodifiableList(boolean clone, List list) { switch(list.size()) { case 0: return Collections.emptyList(); case 1: return Collections.singletonList(list.get(0)); default: if (clone) { return Collections.unmodifiableList(new ArrayList(list)); } else { if (list instanceof ArrayList) { ((ArrayList) list).trimToSize(); } return Collections.unmodifiableList(list); } } } private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, Map map) { switch (map.size()) { case 0: return Collections.emptyMap(); case 1: { Map.Entry e = map.entrySet().iterator().next(); K k = e.getKey(); V v = e.getValue(); if (checkNulls) { ImmutableIncomingSpan.requireNonNull(k, "key"); ImmutableIncomingSpan.requireNonNull(v, "value"); } if (skipNulls && (k == null || v == null)) { return Collections.emptyMap(); } return Collections.singletonMap(k, v); } default: { Map linkedMap = new LinkedHashMap(map.size()); if (skipNulls || checkNulls) { for (Map.Entry e : map.entrySet()) { K k = e.getKey(); V v = e.getValue(); if (skipNulls) { if (k == null || v == null) continue; } else if (checkNulls) { ImmutableIncomingSpan.requireNonNull(k, "key"); ImmutableIncomingSpan.requireNonNull(v, "value"); } linkedMap.put(k, v); } } else { linkedMap.putAll(map); } return Collections.unmodifiableMap(linkedMap); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy