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

org.glowroot.agent.model.ImmutableTimerNameImpl Maven / Gradle / Ivy

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

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.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 TimerNameImpl}.
 * 

* Use builder to create immutable instances: * {@code ImmutableTimerNameImpl.builder()}. * Use static factory method to create immutable instances: * {@code ImmutableTimerNameImpl.of()}. */ @SuppressWarnings("all") @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "TimerNameImpl"}) @Immutable public final class ImmutableTimerNameImpl extends TimerNameImpl { private final String name; private final boolean extended; private final @Nullable TimerNameImpl extendedTimer; private final int specialHashCode; private ImmutableTimerNameImpl(String name, boolean extended) { this.name = Preconditions.checkNotNull(name); this.extended = extended; this.extendedTimer = initShim.extendedTimer(); this.specialHashCode = initShim.specialHashCode(); 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 TimerNameImpl extendedTimer; private byte extendedTimerStage; TimerNameImpl extendedTimer() { if (extendedTimerStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (extendedTimerStage == STAGE_UNINITIALIZED) { extendedTimerStage = STAGE_INITIALIZING; this.extendedTimer = ImmutableTimerNameImpl.super.extendedTimer(); extendedTimerStage = STAGE_INITIALIZED; } return extendedTimer; } private int specialHashCode; private byte specialHashCodeStage; int specialHashCode() { if (specialHashCodeStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (specialHashCodeStage == STAGE_UNINITIALIZED) { specialHashCodeStage = STAGE_INITIALIZING; this.specialHashCode = ImmutableTimerNameImpl.super.specialHashCode(); specialHashCodeStage = STAGE_INITIALIZED; } return specialHashCode; } private String formatInitCycleMessage() { ArrayList attributes = Lists.newArrayList();; if (extendedTimerStage == STAGE_INITIALIZING) attributes.add("extendedTimer"); if (specialHashCodeStage == STAGE_INITIALIZING) attributes.add("specialHashCode"); return "Cannot build TimerNameImpl, attribute initializers form cycle" + attributes; } } private ImmutableTimerNameImpl(ImmutableTimerNameImpl original, String name, boolean extended) { this.name = name; this.extended = extended; this.extendedTimer = super.extendedTimer(); this.specialHashCode = super.specialHashCode(); this.initShim = null; } /** * @return value of {@code name} attribute */ @JsonProperty @Override public String name() { return name; } /** * @return value of {@code extended} attribute */ @JsonProperty @Override public boolean extended() { return extended; } /** * @return computed at construction value of {@code extendedTimer} attribute */ @JsonProperty @Override public @Nullable TimerNameImpl extendedTimer() { return initShim != null ? initShim.extendedTimer() : extendedTimer; } /** * @return computed at construction value of {@code specialHashCode} attribute */ @JsonProperty @Override public int specialHashCode() { return initShim != null ? initShim.specialHashCode() : specialHashCode; } /** * Copy current immutable object by setting value for {@link TimerNameImpl#name() name}. * Shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for name * @return modified copy of the {@code this} object */ public final ImmutableTimerNameImpl withName(String value) { if (this.name == value) return this; String newValue = Preconditions.checkNotNull(value); return new ImmutableTimerNameImpl(this, newValue, this.extended); } /** * Copy current immutable object by setting value for {@link TimerNameImpl#extended() extended}. * Value equality check is used to prevent copying of the same value by returning {@code this}. * @param value new value for extended * @return modified copy of the {@code this} object */ public final ImmutableTimerNameImpl withExtended(boolean value) { if (this.extended == value) return this; boolean newValue = value; return new ImmutableTimerNameImpl(this, this.name, newValue); } /** * This instance is equal to instances of {@code ImmutableTimerNameImpl} 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 ImmutableTimerNameImpl && equalTo((ImmutableTimerNameImpl) another); } private boolean equalTo(ImmutableTimerNameImpl another) { return name.equals(another.name) && extended == another.extended && Objects.equal(extendedTimer, another.extendedTimer) && specialHashCode == another.specialHashCode; } /** * Computes hash code from attributes: {@code name}, {@code extended}, {@code extendedTimer}, {@code specialHashCode}. * @return hashCode value */ @Override public int hashCode() { int h = 31; h = h * 17 + name.hashCode(); h = h * 17 + Booleans.hashCode(extended); h = h * 17 + Objects.hashCode(extendedTimer); h = h * 17 + specialHashCode; return h; } /** * Prints immutable value {@code TimerNameImpl...} with attribute values, * excluding any non-generated and auxiliary attributes. * @return string representation of value */ @Override public String toString() { return MoreObjects.toStringHelper("TimerNameImpl") .add("name", name) .add("extended", extended) .add("extendedTimer", extendedTimer) .add("specialHashCode", specialHashCode) .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 name; @JsonProperty @Nullable Boolean extended; @JsonProperty @Nullable TimerNameImpl extendedTimer; @JsonProperty @Nullable Integer specialHashCode; } /** * @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 ImmutableTimerNameImpl fromJson(Json json) { ImmutableTimerNameImpl.Builder builder = ImmutableTimerNameImpl.builder(); if (json.name != null) { builder.name(json.name); } if (json.extended != null) { builder.extended(json.extended); } return builder.build(); } /** * Construct new immutable {@code TimerNameImpl} instance. * @param name value for {@code name} * @param extended value for {@code extended} * @return immutable TimerNameImpl instance */ public static ImmutableTimerNameImpl of(String name, boolean extended) { return new ImmutableTimerNameImpl(name, extended); } /** * Creates immutable copy of {@link TimerNameImpl}. * 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 TimerNameImpl instance */ public static ImmutableTimerNameImpl copyOf(TimerNameImpl instance) { if (instance instanceof ImmutableTimerNameImpl) { return (ImmutableTimerNameImpl) instance; } return ImmutableTimerNameImpl.builder() .copyFrom(instance) .build(); } /** * Creates builder for {@link org.glowroot.agent.model.ImmutableTimerNameImpl ImmutableTimerNameImpl}. * @return new ImmutableTimerNameImpl builder */ public static ImmutableTimerNameImpl.Builder builder() { return new ImmutableTimerNameImpl.Builder(); } /** * Builds instances of {@link org.glowroot.agent.model.ImmutableTimerNameImpl ImmutableTimerNameImpl}. * 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_NAME = 0x1L; private static final long INIT_BIT_EXTENDED = 0x2L; private long initBits = 0x3; private @Nullable String name; private boolean extended; private Builder() {} /** * Fill builder with attribute values from provided {@link TimerNameImpl} 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(TimerNameImpl instance) { Preconditions.checkNotNull(instance); name(instance.name()); extended(instance.extended()); return this; } /** * Initializes value for {@link TimerNameImpl#name() name}. * @param name value for name * @return {@code this} builder for chained invocation */ public final Builder name(String name) { this.name = Preconditions.checkNotNull(name); initBits &= ~INIT_BIT_NAME; return this; } /** * Initializes value for {@link TimerNameImpl#extended() extended}. * @param extended value for extended * @return {@code this} builder for chained invocation */ public final Builder extended(boolean extended) { this.extended = extended; initBits &= ~INIT_BIT_EXTENDED; return this; } /** * Builds new {@link org.glowroot.agent.model.ImmutableTimerNameImpl ImmutableTimerNameImpl}. * @return immutable instance of TimerNameImpl * @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing */ public ImmutableTimerNameImpl build() throws IllegalStateException { checkRequiredAttributes(); return new ImmutableTimerNameImpl(null, name, extended); } private boolean nameIsSet() { return (initBits & INIT_BIT_NAME) == 0; } private boolean extendedIsSet() { return (initBits & INIT_BIT_EXTENDED) == 0; } private void checkRequiredAttributes() throws IllegalStateException { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if (!nameIsSet()) attributes.add("name"); if (!extendedIsSet()) attributes.add("extended"); return "Cannot build TimerNameImpl, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy