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

org.glowroot.storage.simplerepo.ImmutableGaugeKey Maven / Gradle / Ivy

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

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 GaugeMetaDao.GaugeKey}.
 * 

* Use builder to create immutable instances: * {@code ImmutableGaugeKey.builder()}. * Use static factory method to create immutable instances: * {@code ImmutableGaugeKey.of()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "GaugeMetaDao.GaugeKey"}) @Immutable final class ImmutableGaugeKey implements GaugeMetaDao.GaugeKey { private final String serverRollup; private final String gaugeName; private ImmutableGaugeKey(String serverRollup, String gaugeName) { this.serverRollup = Preconditions.checkNotNull(serverRollup); this.gaugeName = Preconditions.checkNotNull(gaugeName); } private ImmutableGaugeKey(ImmutableGaugeKey original, String serverRollup, String gaugeName) { this.serverRollup = serverRollup; this.gaugeName = gaugeName; } /** * @return value of {@code serverRollup} attribute */ @JsonProperty @Override public String serverRollup() { return serverRollup; } /** * @return value of {@code gaugeName} attribute */ @JsonProperty @Override public String gaugeName() { return gaugeName; } /** * Copy current immutable object by setting value for {@link GaugeMetaDao.GaugeKey#serverRollup() serverRollup}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for serverRollup * @return modified copy of the {@code this} object */ public final ImmutableGaugeKey withServerRollup(String value) { if (this.serverRollup == value) return this; String newValue = Preconditions.checkNotNull(value); return new ImmutableGaugeKey(this, newValue, this.gaugeName); } /** * Copy current immutable object by setting value for {@link GaugeMetaDao.GaugeKey#gaugeName() gaugeName}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for gaugeName * @return modified copy of the {@code this} object */ public final ImmutableGaugeKey withGaugeName(String value) { if (this.gaugeName == value) return this; String newValue = Preconditions.checkNotNull(value); return new ImmutableGaugeKey(this, this.serverRollup, newValue); } /** * This instance is equal to instances of {@code ImmutableGaugeKey} 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 ImmutableGaugeKey && equalTo((ImmutableGaugeKey) another); } private boolean equalTo(ImmutableGaugeKey another) { return serverRollup.equals(another.serverRollup) && gaugeName.equals(another.gaugeName); } /** * Computes hash code from attributes: {@code serverRollup}, {@code gaugeName}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + serverRollup.hashCode(); h = h * 17 + gaugeName.hashCode(); return h; } /** * Prints immutable value {@code GaugeKey...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("GaugeKey") .add("serverRollup", serverRollup) .add("gaugeName", gaugeName) .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 String serverRollup; @JsonProperty @Nullable String gaugeName; } /** * @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 ImmutableGaugeKey fromJson(Json json) { ImmutableGaugeKey.Builder builder = ImmutableGaugeKey.builder(); if (json.serverRollup != null) { builder.serverRollup(json.serverRollup); } if (json.gaugeName != null) { builder.gaugeName(json.gaugeName); } return builder.build(); } /** * Construct new immutable {@code GaugeKey} instance. * @param serverRollup value for {@code serverRollup} * @param gaugeName value for {@code gaugeName} * @return immutable GaugeKey instance */ public static ImmutableGaugeKey of(String serverRollup, String gaugeName) { return new ImmutableGaugeKey(serverRollup, gaugeName); } /** * Creates immutable copy of {@link GaugeMetaDao.GaugeKey}. * 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 GaugeKey instance */ static ImmutableGaugeKey copyOf(GaugeMetaDao.GaugeKey instance) { if (instance instanceof ImmutableGaugeKey) { return (ImmutableGaugeKey) instance; } return ImmutableGaugeKey.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.storage.simplerepo.ImmutableGaugeKey ImmutableGaugeKey}. * @return new ImmutableGaugeKey builder */ static ImmutableGaugeKey.Builder builder() { return new ImmutableGaugeKey.Builder(); } /** * Builds instances of {@link org.glowroot.storage.simplerepo.ImmutableGaugeKey ImmutableGaugeKey}. * 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_SERVER_ROLLUP = 0x1L; private static final long INIT_BIT_GAUGE_NAME = 0x2L; private long initBits = 0x3; private @Nullable String serverRollup; private @Nullable String gaugeName; private Builder() {} /** * Fill builder with attribute values from provided {@link GaugeMetaDao.GaugeKey} 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(GaugeMetaDao.GaugeKey instance) { Preconditions.checkNotNull(instance); serverRollup(instance.serverRollup()); gaugeName(instance.gaugeName()); return this; } /** * Initializes value for {@link GaugeMetaDao.GaugeKey#serverRollup() serverRollup}. * @param serverRollup value for serverRollup * @return {@code this} builder for chained invocation */ public final Builder serverRollup(String serverRollup) { this.serverRollup = Preconditions.checkNotNull(serverRollup); initBits &= ~INIT_BIT_SERVER_ROLLUP; return this; } /** * Initializes value for {@link GaugeMetaDao.GaugeKey#gaugeName() gaugeName}. * @param gaugeName value for gaugeName * @return {@code this} builder for chained invocation */ public final Builder gaugeName(String gaugeName) { this.gaugeName = Preconditions.checkNotNull(gaugeName); initBits &= ~INIT_BIT_GAUGE_NAME; return this; } /** * Builds new {@link org.glowroot.storage.simplerepo.ImmutableGaugeKey ImmutableGaugeKey}. * @return immutable instance of GaugeKey * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutableGaugeKey build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutableGaugeKey(null, serverRollup, gaugeName); } private boolean serverRollupIsSet() { return (initBits & INIT_BIT_SERVER_ROLLUP) == 0; } private boolean gaugeNameIsSet() { return (initBits & INIT_BIT_GAUGE_NAME) == 0; } private void checkRequiredAttributes() throws IllegalStateException { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if (!serverRollupIsSet()) attributes.add("serverRollup"); if (!gaugeNameIsSet()) attributes.add("gaugeName"); return "Cannot build GaugeKey, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy