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

org.glowroot.ui.ImmutableGaugeResponse Maven / Gradle / Ivy

There is a newer version: 0.9.28
Show newest version
package org.glowroot.ui;

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.ImmutableList;
import org.glowroot.agent.shaded.google.common.collect.Lists;
import org.glowroot.agent.shaded.google.common.primitives.Booleans;
import java.util.ArrayList;
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 GaugeConfigJsonService.GaugeResponse}.
 * 

* Use builder to create immutable instances: * {@code ImmutableGaugeResponse.builder()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "GaugeConfigJsonService.GaugeResponse"}) @Immutable final class ImmutableGaugeResponse extends GaugeConfigJsonService.GaugeResponse { private final GaugeConfigJsonService.GaugeConfigDto config; private final boolean mbeanUnavailable; private final boolean mbeanUnmatched; private final ImmutableList mbeanAvailableAttributeNames; private ImmutableGaugeResponse(ImmutableGaugeResponse.Builder builder) { this.config = builder.config; this.mbeanAvailableAttributeNames = builder.mbeanAvailableAttributeNamesBuilder.build(); if (builder.mbeanUnavailableIsSet()) { initShim.mbeanUnavailable(builder.mbeanUnavailable); } if (builder.mbeanUnmatchedIsSet()) { initShim.mbeanUnmatched(builder.mbeanUnmatched); } this.mbeanUnavailable = initShim.mbeanUnavailable(); this.mbeanUnmatched = initShim.mbeanUnmatched(); this.initShim = null; } private static final int STAGE_INITIALIZING = -1; private static final int STAGE_UNINITIALIZED = 0; private static final int STAGE_INITIALIZED = 1; private volatile InitShim initShim = new InitShim(); private final class InitShim { private boolean mbeanUnavailable; private byte mbeanUnavailableStage; boolean mbeanUnavailable() { if (mbeanUnavailableStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (mbeanUnavailableStage == STAGE_UNINITIALIZED) { mbeanUnavailableStage = STAGE_INITIALIZING; this.mbeanUnavailable = ImmutableGaugeResponse.super.mbeanUnavailable(); mbeanUnavailableStage = STAGE_INITIALIZED; } return mbeanUnavailable; } boolean mbeanUnavailable(boolean value) { this.mbeanUnavailable = value; mbeanUnavailableStage = STAGE_INITIALIZED; return value; } private boolean mbeanUnmatched; private byte mbeanUnmatchedStage; boolean mbeanUnmatched() { if (mbeanUnmatchedStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (mbeanUnmatchedStage == STAGE_UNINITIALIZED) { mbeanUnmatchedStage = STAGE_INITIALIZING; this.mbeanUnmatched = ImmutableGaugeResponse.super.mbeanUnmatched(); mbeanUnmatchedStage = STAGE_INITIALIZED; } return mbeanUnmatched; } boolean mbeanUnmatched(boolean value) { this.mbeanUnmatched = value; mbeanUnmatchedStage = STAGE_INITIALIZED; return value; } private String formatInitCycleMessage() { ArrayList attributes = Lists.newArrayList();; if (mbeanUnavailableStage == STAGE_INITIALIZING) attributes.add("mbeanUnavailable"); if (mbeanUnmatchedStage == STAGE_INITIALIZING) attributes.add("mbeanUnmatched"); return "Cannot build GaugeResponse, attribute initializers form cycle" + attributes; } } private ImmutableGaugeResponse( GaugeConfigJsonService.GaugeConfigDto config, boolean mbeanUnavailable, boolean mbeanUnmatched, ImmutableList mbeanAvailableAttributeNames) { this.config = config; this.mbeanUnavailable = mbeanUnavailable; this.mbeanUnmatched = mbeanUnmatched; this.mbeanAvailableAttributeNames = mbeanAvailableAttributeNames; this.initShim = null; } /** * @return value of {@code config} attribute */ @JsonProperty @Override GaugeConfigJsonService.GaugeConfigDto config() { return config; } /** * @return value of {@code mbeanUnavailable} attribute */ @JsonProperty @Override boolean mbeanUnavailable() { return initShim != null ? initShim.mbeanUnavailable() : mbeanUnavailable; } /** * @return value of {@code mbeanUnmatched} attribute */ @JsonProperty @Override boolean mbeanUnmatched() { return initShim != null ? initShim.mbeanUnmatched() : mbeanUnmatched; } /** * @return value of {@code mbeanAvailableAttributeNames} attribute */ @JsonProperty @Override ImmutableList mbeanAvailableAttributeNames() { return mbeanAvailableAttributeNames; } /** * Copy current immutable object by setting value for {@link GaugeConfigJsonService.GaugeResponse#config() config}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for config * @return modified copy of the {@code this} object */ public final ImmutableGaugeResponse withConfig(GaugeConfigJsonService.GaugeConfigDto value) { if (this.config == value) return this; GaugeConfigJsonService.GaugeConfigDto newValue = Preconditions.checkNotNull(value); return new ImmutableGaugeResponse(newValue, this.mbeanUnavailable, this.mbeanUnmatched, this.mbeanAvailableAttributeNames); } /** * Copy current immutable object by setting value for {@link GaugeConfigJsonService.GaugeResponse#mbeanUnavailable() mbeanUnavailable}. * Value equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for mbeanUnavailable * @return modified copy of the {@code this} object */ public final ImmutableGaugeResponse withMbeanUnavailable(boolean value) { if (this.mbeanUnavailable == value) return this; boolean newValue = value; return new ImmutableGaugeResponse(this.config, newValue, this.mbeanUnmatched, this.mbeanAvailableAttributeNames); } /** * Copy current immutable object by setting value for {@link GaugeConfigJsonService.GaugeResponse#mbeanUnmatched() mbeanUnmatched}. * Value equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for mbeanUnmatched * @return modified copy of the {@code this} object */ public final ImmutableGaugeResponse withMbeanUnmatched(boolean value) { if (this.mbeanUnmatched == value) return this; boolean newValue = value; return new ImmutableGaugeResponse(this.config, this.mbeanUnavailable, newValue, this.mbeanAvailableAttributeNames); } /** * Copy current immutable object with elements that replace content of {@link GaugeConfigJsonService.GaugeResponse#mbeanAvailableAttributeNames() mbeanAvailableAttributeNames}. * @param elements elements to set * @return modified copy of {@code this} object */ public final ImmutableGaugeResponse withMbeanAvailableAttributeNames(String... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableGaugeResponse(this.config, this.mbeanUnavailable, this.mbeanUnmatched, newValue); } /** * Copy current immutable object with elements that replace content of {@link GaugeConfigJsonService.GaugeResponse#mbeanAvailableAttributeNames() mbeanAvailableAttributeNames}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements iterable of mbeanAvailableAttributeNames elements to set * @return modified copy of {@code this} object */ public final ImmutableGaugeResponse withMbeanAvailableAttributeNames(Iterable elements) { if (this.mbeanAvailableAttributeNames == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableGaugeResponse(this.config, this.mbeanUnavailable, this.mbeanUnmatched, newValue); } /** * This instance is equal to instances of {@code ImmutableGaugeResponse} 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 ImmutableGaugeResponse && equalTo((ImmutableGaugeResponse) another); } private boolean equalTo(ImmutableGaugeResponse another) { return config.equals(another.config) && mbeanUnavailable == another.mbeanUnavailable && mbeanUnmatched == another.mbeanUnmatched && mbeanAvailableAttributeNames.equals(another.mbeanAvailableAttributeNames); } /** * Computes hash code from attributes: {@code config}, {@code mbeanUnavailable}, {@code mbeanUnmatched}, {@code mbeanAvailableAttributeNames}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + config.hashCode(); h = h * 17 + Booleans.hashCode(mbeanUnavailable); h = h * 17 + Booleans.hashCode(mbeanUnmatched); h = h * 17 + mbeanAvailableAttributeNames.hashCode(); return h; } /** * Prints immutable value {@code GaugeResponse...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("GaugeResponse") .add("config", config) .add("mbeanUnavailable", mbeanUnavailable) .add("mbeanUnmatched", mbeanUnmatched) .add("mbeanAvailableAttributeNames", mbeanAvailableAttributeNames) .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 GaugeConfigJsonService.GaugeConfigDto config; @JsonProperty @Nullable Boolean mbeanUnavailable; @JsonProperty @Nullable Boolean mbeanUnmatched; @JsonProperty @Nullable ImmutableList mbeanAvailableAttributeNames; } /** * @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 ImmutableGaugeResponse fromJson(Json json) { ImmutableGaugeResponse.Builder builder = ImmutableGaugeResponse.builder(); if (json.config != null) { builder.config(json.config); } if (json.mbeanUnavailable != null) { builder.mbeanUnavailable(json.mbeanUnavailable); } if (json.mbeanUnmatched != null) { builder.mbeanUnmatched(json.mbeanUnmatched); } if (json.mbeanAvailableAttributeNames != null) { builder.addAllMbeanAvailableAttributeNames(json.mbeanAvailableAttributeNames); } return builder.build(); } /** * Creates immutable copy of {@link GaugeConfigJsonService.GaugeResponse}. * 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 GaugeResponse instance */ static ImmutableGaugeResponse copyOf(GaugeConfigJsonService.GaugeResponse instance) { if (instance instanceof ImmutableGaugeResponse) { return (ImmutableGaugeResponse) instance; } return ImmutableGaugeResponse.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.ui.ImmutableGaugeResponse ImmutableGaugeResponse}. * @return new ImmutableGaugeResponse builder */ static ImmutableGaugeResponse.Builder builder() { return new ImmutableGaugeResponse.Builder(); } /** * Builds instances of {@link org.glowroot.ui.ImmutableGaugeResponse ImmutableGaugeResponse}. * 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 static final class Builder { private static final long INIT_BIT_CONFIG = 0x1L; private static final long OPT_BIT_MBEAN_UNAVAILABLE = 0x1L; private static final long OPT_BIT_MBEAN_UNMATCHED = 0x2L; private long initBits = 0x1; private long optBits; private @Nullable GaugeConfigJsonService.GaugeConfigDto config; private boolean mbeanUnavailable; private boolean mbeanUnmatched; private ImmutableList.Builder mbeanAvailableAttributeNamesBuilder = ImmutableList.builder(); private Builder() {} /** * Fill builder with attribute values from provided {@link GaugeConfigJsonService.GaugeResponse} 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(GaugeConfigJsonService.GaugeResponse instance) { Preconditions.checkNotNull(instance); config(instance.config()); mbeanUnavailable(instance.mbeanUnavailable()); mbeanUnmatched(instance.mbeanUnmatched()); addAllMbeanAvailableAttributeNames(instance.mbeanAvailableAttributeNames()); return this; } /** * Initializes value for {@link GaugeConfigJsonService.GaugeResponse#config() config}. * @param config value for config * @return {@code this} builder for chained invocation */ public final Builder config(GaugeConfigJsonService.GaugeConfigDto config) { this.config = Preconditions.checkNotNull(config); initBits &= ~INIT_BIT_CONFIG; return this; } /** * Initializes value for {@link GaugeConfigJsonService.GaugeResponse#mbeanUnavailable() mbeanUnavailable}. *

If not set, this attribute will have default value returned by initializer of {@link GaugeConfigJsonService.GaugeResponse#mbeanUnavailable() mbeanUnavailable}. * @param mbeanUnavailable value for mbeanUnavailable * @return {@code this} builder for chained invocation */ public final Builder mbeanUnavailable(boolean mbeanUnavailable) { this.mbeanUnavailable = mbeanUnavailable; optBits |= OPT_BIT_MBEAN_UNAVAILABLE; return this; } /** * Initializes value for {@link GaugeConfigJsonService.GaugeResponse#mbeanUnmatched() mbeanUnmatched}. *

If not set, this attribute will have default value returned by initializer of {@link GaugeConfigJsonService.GaugeResponse#mbeanUnmatched() mbeanUnmatched}. * @param mbeanUnmatched value for mbeanUnmatched * @return {@code this} builder for chained invocation */ public final Builder mbeanUnmatched(boolean mbeanUnmatched) { this.mbeanUnmatched = mbeanUnmatched; optBits |= OPT_BIT_MBEAN_UNMATCHED; return this; } /** * Adds one element to {@link GaugeConfigJsonService.GaugeResponse#mbeanAvailableAttributeNames() mbeanAvailableAttributeNames} list. * @param element mbeanAvailableAttributeNames element * @return {@code this} builder for chained invocation */ public final Builder addMbeanAvailableAttributeNames(String element) { mbeanAvailableAttributeNamesBuilder.add(element); return this; } /** * Adds elements to {@link GaugeConfigJsonService.GaugeResponse#mbeanAvailableAttributeNames() mbeanAvailableAttributeNames} list. * @param elements array of mbeanAvailableAttributeNames elements * @return {@code this} builder for chained invocation */ public final Builder addMbeanAvailableAttributeNames(String... elements) { mbeanAvailableAttributeNamesBuilder.add(elements); return this; } /** * Sets or replaces all elements for {@link GaugeConfigJsonService.GaugeResponse#mbeanAvailableAttributeNames() mbeanAvailableAttributeNames} list. * @param elements iterable of mbeanAvailableAttributeNames elements * @return {@code this} builder for chained invocation */ public final Builder mbeanAvailableAttributeNames(Iterable elements) { mbeanAvailableAttributeNamesBuilder = ImmutableList.builder(); return addAllMbeanAvailableAttributeNames(elements); } /** * Adds elements to {@link GaugeConfigJsonService.GaugeResponse#mbeanAvailableAttributeNames() mbeanAvailableAttributeNames} list. * @param elements iterable of mbeanAvailableAttributeNames elements * @return {@code this} builder for chained invocation */ public final Builder addAllMbeanAvailableAttributeNames(Iterable elements) { mbeanAvailableAttributeNamesBuilder.addAll(elements); return this; } /** * Builds new {@link org.glowroot.ui.ImmutableGaugeResponse ImmutableGaugeResponse}. * @return immutable instance of GaugeResponse * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutableGaugeResponse build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutableGaugeResponse(this); } private boolean mbeanUnavailableIsSet() { return (optBits & OPT_BIT_MBEAN_UNAVAILABLE) != 0; } private boolean mbeanUnmatchedIsSet() { return (optBits & OPT_BIT_MBEAN_UNMATCHED) != 0; } private boolean configIsSet() { return (initBits & INIT_BIT_CONFIG) == 0; } private void checkRequiredAttributes() throws IllegalStateException { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if (!configIsSet()) attributes.add("config"); return "Cannot build GaugeResponse, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy