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

org.glowroot.storage.repo.ImmutableHeaderPlus Maven / Gradle / Ivy

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

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.common.live.LiveTraceRepository;
import org.glowroot.wire.api.model.TraceOuterClass;

/**
 * Immutable implementation of {@link TraceRepository.HeaderPlus}.
 * 

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





© 2015 - 2025 Weber Informatics LLC | Privacy Policy