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

org.glowroot.storage.simplerepo.ImmutableMutableTransactionAggregate 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;
import org.glowroot.storage.repo.MutableAggregate;

/**
 * Immutable implementation of {@link AggregateDao.MutableTransactionAggregate}.
 * 

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy