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

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

There is a newer version: 0.9.28
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 org.glowroot.agent.shaded.google.common.base.MoreObjects;
import org.glowroot.agent.shaded.google.common.base.Objects;
import org.glowroot.agent.shaded.google.common.base.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.ImmutableList;
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 LiveJvmService.AllThreads}.
 * 

* Use builder to create immutable instances: * {@code ImmutableAllThreads.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "LiveJvmService.AllThreads"}) @Immutable public final class ImmutableAllThreads implements LiveJvmService.AllThreads { private final ImmutableList matchedThreads; private final ImmutableList unmatchedThreads; private final @Nullable LiveJvmService.OneThread currentThread; private ImmutableAllThreads( ImmutableList matchedThreads, ImmutableList unmatchedThreads, @Nullable LiveJvmService.OneThread currentThread) { this.matchedThreads = matchedThreads; this.unmatchedThreads = unmatchedThreads; this.currentThread = currentThread; } /** * @return value of {@code matchedThreads} attribute */ @JsonProperty @Override public ImmutableList matchedThreads() { return matchedThreads; } /** * @return value of {@code unmatchedThreads} attribute */ @JsonProperty @Override public ImmutableList unmatchedThreads() { return unmatchedThreads; } /** * @return value of {@code currentThread} attribute */ @JsonProperty @Override public @Nullable LiveJvmService.OneThread currentThread() { return currentThread; } /** * Copy current immutable object with elements that replace content of {@link LiveJvmService.AllThreads#matchedThreads() matchedThreads}. * @param elements elements to set * @return modified copy of {@code this} object */ public final ImmutableAllThreads withMatchedThreads(LiveJvmService.OneThread... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableAllThreads(newValue, this.unmatchedThreads, this.currentThread); } /** * Copy current immutable object with elements that replace content of {@link LiveJvmService.AllThreads#matchedThreads() matchedThreads}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements iterable of matchedThreads elements to set * @return modified copy of {@code this} object */ public final ImmutableAllThreads withMatchedThreads(Iterable elements) { if (this.matchedThreads == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableAllThreads(newValue, this.unmatchedThreads, this.currentThread); } /** * Copy current immutable object with elements that replace content of {@link LiveJvmService.AllThreads#unmatchedThreads() unmatchedThreads}. * @param elements elements to set * @return modified copy of {@code this} object */ public final ImmutableAllThreads withUnmatchedThreads(LiveJvmService.OneThread... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableAllThreads(this.matchedThreads, newValue, this.currentThread); } /** * Copy current immutable object with elements that replace content of {@link LiveJvmService.AllThreads#unmatchedThreads() unmatchedThreads}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements iterable of unmatchedThreads elements to set * @return modified copy of {@code this} object */ public final ImmutableAllThreads withUnmatchedThreads(Iterable elements) { if (this.unmatchedThreads == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableAllThreads(this.matchedThreads, newValue, this.currentThread); } /** * Copy current immutable object by setting value for {@link LiveJvmService.AllThreads#currentThread() currentThread}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for currentThread, can be {@code null} * @return modified copy of the {@code this} object */ public final ImmutableAllThreads withCurrentThread(@Nullable LiveJvmService.OneThread value) { if (this.currentThread == value) return this; @Nullable LiveJvmService.OneThread newValue = value; return new ImmutableAllThreads(this.matchedThreads, this.unmatchedThreads, newValue); } /** * This instance is equal to instances of {@code ImmutableAllThreads} 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 ImmutableAllThreads && equalTo((ImmutableAllThreads) another); } private boolean equalTo(ImmutableAllThreads another) { return matchedThreads.equals(another.matchedThreads) && unmatchedThreads.equals(another.unmatchedThreads) && Objects.equal(currentThread, another.currentThread); } /** * Computes hash code from attributes: {@code matchedThreads}, {@code unmatchedThreads}, {@code currentThread}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + matchedThreads.hashCode(); h = h * 17 + unmatchedThreads.hashCode(); h = h * 17 + Objects.hashCode(currentThread); return h; } /** * Prints immutable value {@code AllThreads...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("AllThreads") .add("matchedThreads", matchedThreads) .add("unmatchedThreads", unmatchedThreads) .add("currentThread", currentThread) .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 List matchedThreads; @JsonProperty @Nullable List unmatchedThreads; @JsonProperty @Nullable LiveJvmService.OneThread currentThread; } /** * @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 ImmutableAllThreads fromJson(Json json) { ImmutableAllThreads.Builder builder = ImmutableAllThreads.builder(); if (json.matchedThreads != null) { builder.addAllMatchedThreads(json.matchedThreads); } if (json.unmatchedThreads != null) { builder.addAllUnmatchedThreads(json.unmatchedThreads); } if (json.currentThread != null) { builder.currentThread(json.currentThread); } return builder.build(); } /** * Creates immutable copy of {@link LiveJvmService.AllThreads}. * 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 AllThreads instance */ public static ImmutableAllThreads copyOf(LiveJvmService.AllThreads instance) { if (instance instanceof ImmutableAllThreads) { return (ImmutableAllThreads) instance; } return ImmutableAllThreads.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.common.live.ImmutableAllThreads ImmutableAllThreads}. * @return new ImmutableAllThreads builder */ public static ImmutableAllThreads.Builder builder() { return new ImmutableAllThreads.Builder(); } /** * Builds instances of {@link org.glowroot.common.live.ImmutableAllThreads ImmutableAllThreads}. * 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 ImmutableList.Builder matchedThreadsBuilder = ImmutableList.builder(); private ImmutableList.Builder unmatchedThreadsBuilder = ImmutableList.builder(); private @Nullable LiveJvmService.OneThread currentThread; private Builder() {} /** * Fill builder with attribute values from provided {@link LiveJvmService.AllThreads} instance. * Regular attribute values will be replaced with ones of an instance. * Instance's absent optional values will not replace present values. * Collection elements and entries will be added, not replaced. * @param instance instance to copy values from * @return {@code this} builder for chained invocation */ public final Builder copyFrom(LiveJvmService.AllThreads instance) { Preconditions.checkNotNull(instance); addAllMatchedThreads(instance.matchedThreads()); addAllUnmatchedThreads(instance.unmatchedThreads()); @Nullable LiveJvmService.OneThread currentThreadValue = instance.currentThread(); if (currentThreadValue != null) { currentThread(currentThreadValue); } return this; } /** * Adds one element to {@link LiveJvmService.AllThreads#matchedThreads() matchedThreads} list. * @param element matchedThreads element * @return {@code this} builder for chained invocation */ public final Builder addMatchedThreads(LiveJvmService.OneThread element) { matchedThreadsBuilder.add(element); return this; } /** * Adds elements to {@link LiveJvmService.AllThreads#matchedThreads() matchedThreads} list. * @param elements array of matchedThreads elements * @return {@code this} builder for chained invocation */ public final Builder addMatchedThreads(LiveJvmService.OneThread... elements) { matchedThreadsBuilder.add(elements); return this; } /** * Sets or replaces all elements for {@link LiveJvmService.AllThreads#matchedThreads() matchedThreads} list. * @param elements iterable of matchedThreads elements * @return {@code this} builder for chained invocation */ public final Builder matchedThreads(Iterable elements) { matchedThreadsBuilder = ImmutableList.builder(); return addAllMatchedThreads(elements); } /** * Adds elements to {@link LiveJvmService.AllThreads#matchedThreads() matchedThreads} list. * @param elements iterable of matchedThreads elements * @return {@code this} builder for chained invocation */ public final Builder addAllMatchedThreads(Iterable elements) { matchedThreadsBuilder.addAll(elements); return this; } /** * Adds one element to {@link LiveJvmService.AllThreads#unmatchedThreads() unmatchedThreads} list. * @param element unmatchedThreads element * @return {@code this} builder for chained invocation */ public final Builder addUnmatchedThreads(LiveJvmService.OneThread element) { unmatchedThreadsBuilder.add(element); return this; } /** * Adds elements to {@link LiveJvmService.AllThreads#unmatchedThreads() unmatchedThreads} list. * @param elements array of unmatchedThreads elements * @return {@code this} builder for chained invocation */ public final Builder addUnmatchedThreads(LiveJvmService.OneThread... elements) { unmatchedThreadsBuilder.add(elements); return this; } /** * Sets or replaces all elements for {@link LiveJvmService.AllThreads#unmatchedThreads() unmatchedThreads} list. * @param elements iterable of unmatchedThreads elements * @return {@code this} builder for chained invocation */ public final Builder unmatchedThreads(Iterable elements) { unmatchedThreadsBuilder = ImmutableList.builder(); return addAllUnmatchedThreads(elements); } /** * Adds elements to {@link LiveJvmService.AllThreads#unmatchedThreads() unmatchedThreads} list. * @param elements iterable of unmatchedThreads elements * @return {@code this} builder for chained invocation */ public final Builder addAllUnmatchedThreads(Iterable elements) { unmatchedThreadsBuilder.addAll(elements); return this; } /** * Initializes value for {@link LiveJvmService.AllThreads#currentThread() currentThread}. * @param currentThread value for currentThread, can be {@code null} * @return {@code this} builder for chained invocation */ public final Builder currentThread(@Nullable LiveJvmService.OneThread currentThread) { this.currentThread = currentThread; return this; } /** * Builds new {@link org.glowroot.common.live.ImmutableAllThreads ImmutableAllThreads}. * @return immutable instance of AllThreads * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutableAllThreads build() throws IllegalStateException { return new ImmutableAllThreads(matchedThreadsBuilder.build(), unmatchedThreadsBuilder.build(), currentThread); } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy