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

org.glowroot.common.live.ImmutableCapabilities 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.Preconditions;
import org.glowroot.agent.shaded.google.common.collect.Lists;
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.Capabilities}.
 * 

* Use builder to create immutable instances: * {@code ImmutableCapabilities.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "LiveJvmService.Capabilities"}) @Immutable public final class ImmutableCapabilities implements LiveJvmService.Capabilities { private final LiveJvmService.Availability threadCpuTime; private final LiveJvmService.Availability threadContentionTime; private final LiveJvmService.Availability threadAllocatedBytes; private ImmutableCapabilities( LiveJvmService.Availability threadCpuTime, LiveJvmService.Availability threadContentionTime, LiveJvmService.Availability threadAllocatedBytes) { this.threadCpuTime = threadCpuTime; this.threadContentionTime = threadContentionTime; this.threadAllocatedBytes = threadAllocatedBytes; } /** * @return value of {@code threadCpuTime} attribute */ @JsonProperty @Override public LiveJvmService.Availability threadCpuTime() { return threadCpuTime; } /** * @return value of {@code threadContentionTime} attribute */ @JsonProperty @Override public LiveJvmService.Availability threadContentionTime() { return threadContentionTime; } /** * @return value of {@code threadAllocatedBytes} attribute */ @JsonProperty @Override public LiveJvmService.Availability threadAllocatedBytes() { return threadAllocatedBytes; } /** * Copy current immutable object by setting value for {@link LiveJvmService.Capabilities#threadCpuTime() threadCpuTime}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for threadCpuTime * @return modified copy of the {@code this} object */ public final ImmutableCapabilities withThreadCpuTime(LiveJvmService.Availability value) { if (this.threadCpuTime == value) return this; LiveJvmService.Availability newValue = Preconditions.checkNotNull(value); return new ImmutableCapabilities(newValue, this.threadContentionTime, this.threadAllocatedBytes); } /** * Copy current immutable object by setting value for {@link LiveJvmService.Capabilities#threadContentionTime() threadContentionTime}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for threadContentionTime * @return modified copy of the {@code this} object */ public final ImmutableCapabilities withThreadContentionTime(LiveJvmService.Availability value) { if (this.threadContentionTime == value) return this; LiveJvmService.Availability newValue = Preconditions.checkNotNull(value); return new ImmutableCapabilities(this.threadCpuTime, newValue, this.threadAllocatedBytes); } /** * Copy current immutable object by setting value for {@link LiveJvmService.Capabilities#threadAllocatedBytes() threadAllocatedBytes}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for threadAllocatedBytes * @return modified copy of the {@code this} object */ public final ImmutableCapabilities withThreadAllocatedBytes(LiveJvmService.Availability value) { if (this.threadAllocatedBytes == value) return this; LiveJvmService.Availability newValue = Preconditions.checkNotNull(value); return new ImmutableCapabilities(this.threadCpuTime, this.threadContentionTime, newValue); } /** * This instance is equal to instances of {@code ImmutableCapabilities} 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 ImmutableCapabilities && equalTo((ImmutableCapabilities) another); } private boolean equalTo(ImmutableCapabilities another) { return threadCpuTime.equals(another.threadCpuTime) && threadContentionTime.equals(another.threadContentionTime) && threadAllocatedBytes.equals(another.threadAllocatedBytes); } /** * Computes hash code from attributes: {@code threadCpuTime}, {@code threadContentionTime}, {@code threadAllocatedBytes}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + threadCpuTime.hashCode(); h = h * 17 + threadContentionTime.hashCode(); h = h * 17 + threadAllocatedBytes.hashCode(); return h; } /** * Prints immutable value {@code Capabilities...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("Capabilities") .add("threadCpuTime", threadCpuTime) .add("threadContentionTime", threadContentionTime) .add("threadAllocatedBytes", threadAllocatedBytes) .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 LiveJvmService.Availability threadCpuTime; @JsonProperty @Nullable LiveJvmService.Availability threadContentionTime; @JsonProperty @Nullable LiveJvmService.Availability threadAllocatedBytes; } /** * @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 ImmutableCapabilities fromJson(Json json) { ImmutableCapabilities.Builder builder = ImmutableCapabilities.builder(); if (json.threadCpuTime != null) { builder.threadCpuTime(json.threadCpuTime); } if (json.threadContentionTime != null) { builder.threadContentionTime(json.threadContentionTime); } if (json.threadAllocatedBytes != null) { builder.threadAllocatedBytes(json.threadAllocatedBytes); } return builder.build(); } /** * Creates immutable copy of {@link LiveJvmService.Capabilities}. * 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 Capabilities instance */ public static ImmutableCapabilities copyOf(LiveJvmService.Capabilities instance) { if (instance instanceof ImmutableCapabilities) { return (ImmutableCapabilities) instance; } return ImmutableCapabilities.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.common.live.ImmutableCapabilities ImmutableCapabilities}. * @return new ImmutableCapabilities builder */ public static ImmutableCapabilities.Builder builder() { return new ImmutableCapabilities.Builder(); } /** * Builds instances of {@link org.glowroot.common.live.ImmutableCapabilities ImmutableCapabilities}. * 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 static final long INIT_BIT_THREAD_CPU_TIME = 0x1L; private static final long INIT_BIT_THREAD_CONTENTION_TIME = 0x2L; private static final long INIT_BIT_THREAD_ALLOCATED_BYTES = 0x4L; private long initBits = 0x7; private @Nullable LiveJvmService.Availability threadCpuTime; private @Nullable LiveJvmService.Availability threadContentionTime; private @Nullable LiveJvmService.Availability threadAllocatedBytes; private Builder() {} /** * Fill builder with attribute values from provided {@link LiveJvmService.Capabilities} instance. * Regular attribute values will be replaced with ones of an instance. * Instance's absent optional values will not replace present values. * @param instance instance to copy values from * @return {@code this} builder for chained invocation */ public final Builder copyFrom(LiveJvmService.Capabilities instance) { Preconditions.checkNotNull(instance); threadCpuTime(instance.threadCpuTime()); threadContentionTime(instance.threadContentionTime()); threadAllocatedBytes(instance.threadAllocatedBytes()); return this; } /** * Initializes value for {@link LiveJvmService.Capabilities#threadCpuTime() threadCpuTime}. * @param threadCpuTime value for threadCpuTime * @return {@code this} builder for chained invocation */ public final Builder threadCpuTime(LiveJvmService.Availability threadCpuTime) { this.threadCpuTime = Preconditions.checkNotNull(threadCpuTime); initBits &= ~INIT_BIT_THREAD_CPU_TIME; return this; } /** * Initializes value for {@link LiveJvmService.Capabilities#threadContentionTime() threadContentionTime}. * @param threadContentionTime value for threadContentionTime * @return {@code this} builder for chained invocation */ public final Builder threadContentionTime(LiveJvmService.Availability threadContentionTime) { this.threadContentionTime = Preconditions.checkNotNull(threadContentionTime); initBits &= ~INIT_BIT_THREAD_CONTENTION_TIME; return this; } /** * Initializes value for {@link LiveJvmService.Capabilities#threadAllocatedBytes() threadAllocatedBytes}. * @param threadAllocatedBytes value for threadAllocatedBytes * @return {@code this} builder for chained invocation */ public final Builder threadAllocatedBytes(LiveJvmService.Availability threadAllocatedBytes) { this.threadAllocatedBytes = Preconditions.checkNotNull(threadAllocatedBytes); initBits &= ~INIT_BIT_THREAD_ALLOCATED_BYTES; return this; } /** * Builds new {@link org.glowroot.common.live.ImmutableCapabilities ImmutableCapabilities}. * @return immutable instance of Capabilities * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutableCapabilities build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutableCapabilities(threadCpuTime, threadContentionTime, threadAllocatedBytes); } private boolean threadCpuTimeIsSet() { return (initBits & INIT_BIT_THREAD_CPU_TIME) == 0; } private boolean threadContentionTimeIsSet() { return (initBits & INIT_BIT_THREAD_CONTENTION_TIME) == 0; } private boolean threadAllocatedBytesIsSet() { return (initBits & INIT_BIT_THREAD_ALLOCATED_BYTES) == 0; } private void checkRequiredAttributes() throws IllegalStateException { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if (!threadCpuTimeIsSet()) attributes.add("threadCpuTime"); if (!threadContentionTimeIsSet()) attributes.add("threadContentionTime"); if (!threadAllocatedBytesIsSet()) attributes.add("threadAllocatedBytes"); return "Cannot build Capabilities, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy