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

org.glowroot.central.repo.ImmutableNeedsRollupKey Maven / Gradle / Ivy

package org.glowroot.central.repo;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.MoreObjects;
import com.google.common.primitives.Longs;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link GaugeValueDaoImpl.NeedsRollupKey}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableNeedsRollupKey.builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableNeedsRollupKey.of()}. */ @Generated(from = "GaugeValueDaoImpl.NeedsRollupKey", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue final class ImmutableNeedsRollupKey implements GaugeValueDaoImpl.NeedsRollupKey { private final String agentRollupId; private final long captureTime; private ImmutableNeedsRollupKey(String agentRollupId, long captureTime) { this.agentRollupId = Objects.requireNonNull(agentRollupId, "agentRollupId"); this.captureTime = captureTime; } private ImmutableNeedsRollupKey(ImmutableNeedsRollupKey original, String agentRollupId, long captureTime) { this.agentRollupId = agentRollupId; this.captureTime = captureTime; } /** * @return The value of the {@code agentRollupId} attribute */ @JsonProperty("agentRollupId") @Override public String agentRollupId() { return agentRollupId; } /** * @return The value of the {@code captureTime} attribute */ @JsonProperty("captureTime") @Override public long captureTime() { return captureTime; } /** * Copy the current immutable object by setting a value for the {@link GaugeValueDaoImpl.NeedsRollupKey#agentRollupId() agentRollupId} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for agentRollupId * @return A modified copy of the {@code this} object */ public final ImmutableNeedsRollupKey withAgentRollupId(String value) { String newValue = Objects.requireNonNull(value, "agentRollupId"); if (this.agentRollupId.equals(newValue)) return this; return new ImmutableNeedsRollupKey(this, newValue, this.captureTime); } /** * Copy the current immutable object by setting a value for the {@link GaugeValueDaoImpl.NeedsRollupKey#captureTime() captureTime} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for captureTime * @return A modified copy of the {@code this} object */ public final ImmutableNeedsRollupKey withCaptureTime(long value) { if (this.captureTime == value) return this; return new ImmutableNeedsRollupKey(this, this.agentRollupId, value); } /** * This instance is equal to all instances of {@code ImmutableNeedsRollupKey} that have 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 ImmutableNeedsRollupKey && equalTo((ImmutableNeedsRollupKey) another); } private boolean equalTo(ImmutableNeedsRollupKey another) { return agentRollupId.equals(another.agentRollupId) && captureTime == another.captureTime; } /** * Computes a hash code from attributes: {@code agentRollupId}, {@code captureTime}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + agentRollupId.hashCode(); h += (h << 5) + Longs.hashCode(captureTime); return h; } /** * Prints the immutable value {@code NeedsRollupKey} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("NeedsRollupKey") .omitNullValues() .add("agentRollupId", agentRollupId) .add("captureTime", captureTime) .toString(); } /** * Utility type used to correctly read immutable object from JSON representation. * @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure */ @Generated(from = "GaugeValueDaoImpl.NeedsRollupKey", generator = "Immutables") @Deprecated @SuppressWarnings("Immutable") @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements GaugeValueDaoImpl.NeedsRollupKey { @Nullable String agentRollupId; long captureTime; boolean captureTimeIsSet; @JsonProperty("agentRollupId") public void setAgentRollupId(String agentRollupId) { this.agentRollupId = agentRollupId; } @JsonProperty("captureTime") public void setCaptureTime(long captureTime) { this.captureTime = captureTime; this.captureTimeIsSet = true; } @Override public String agentRollupId() { throw new UnsupportedOperationException(); } @Override public long captureTime() { throw new UnsupportedOperationException(); } } /** * @param json A JSON-bindable data structure * @return An immutable value type * @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure */ @Deprecated @JsonCreator(mode = JsonCreator.Mode.DELEGATING) static ImmutableNeedsRollupKey fromJson(Json json) { ImmutableNeedsRollupKey.Builder builder = ImmutableNeedsRollupKey.builder(); if (json.agentRollupId != null) { builder.agentRollupId(json.agentRollupId); } if (json.captureTimeIsSet) { builder.captureTime(json.captureTime); } return builder.build(); } /** * Construct a new immutable {@code NeedsRollupKey} instance. * @param agentRollupId The value for the {@code agentRollupId} attribute * @param captureTime The value for the {@code captureTime} attribute * @return An immutable NeedsRollupKey instance */ public static ImmutableNeedsRollupKey of(String agentRollupId, long captureTime) { return new ImmutableNeedsRollupKey(agentRollupId, captureTime); } /** * Creates an immutable copy of a {@link GaugeValueDaoImpl.NeedsRollupKey} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable NeedsRollupKey instance */ public static ImmutableNeedsRollupKey copyOf(GaugeValueDaoImpl.NeedsRollupKey instance) { if (instance instanceof ImmutableNeedsRollupKey) { return (ImmutableNeedsRollupKey) instance; } return ImmutableNeedsRollupKey.builder() .copyFrom(instance) .build(); } /** * The serialized form captures the structural content of the value object, * providing the ability to reconstruct values with the capability to migrate * data. Uses optional, nullable, and provides flexible handling of * collection attributes. */ @Generated(from = "GaugeValueDaoImpl.NeedsRollupKey", generator = "Immutables") private static class SerialForm implements Serializable { private static final long serialVersionUID = 0L; private final String[] names; private final Object[] values; SerialForm(ImmutableNeedsRollupKey instance) { List names = new ArrayList<>(2); List values = new ArrayList<>(2); names.add("agentRollupId"); values.add(instance.agentRollupId()); names.add("captureTime"); values.add(instance.captureTime()); this.names = names.toArray(new String[names.size()]); this.values = values.toArray(); } Object readResolve() { ImmutableNeedsRollupKey.Builder builder = ImmutableNeedsRollupKey.builder(); for (int i = 0; i < names.length; i++) { String name = names[i]; if ("agentRollupId".equals(name)) { builder.agentRollupId((String) toSingle("agentRollupId", values[i])); continue; } if ("captureTime".equals(name)) { builder.captureTime((Long) toSingle("captureTime", values[i])); continue; } } return builder.build(); } private static Object toSingle(String attribute, Object value) { if (value instanceof Object[]) { Object[] elements = (Object[]) value; if (elements.length == 1) { return elements[0]; } throw new IllegalStateException("Cannot extract scalar value for attribute '" + attribute + "' from array of length " + elements.length); } return value; } } private Object writeReplace() { return new SerialForm(this); } /** * Creates a builder for {@link ImmutableNeedsRollupKey ImmutableNeedsRollupKey}. *
   * ImmutableNeedsRollupKey.builder()
   *    .agentRollupId(String) // required {@link GaugeValueDaoImpl.NeedsRollupKey#agentRollupId() agentRollupId}
   *    .captureTime(long) // required {@link GaugeValueDaoImpl.NeedsRollupKey#captureTime() captureTime}
   *    .build();
   * 
* @return A new ImmutableNeedsRollupKey builder */ public static ImmutableNeedsRollupKey.Builder builder() { return new ImmutableNeedsRollupKey.Builder(); } /** * Builds instances of type {@link ImmutableNeedsRollupKey ImmutableNeedsRollupKey}. * Initialize attributes and then invoke the {@link #build()} method to create an * immutable instance. *

{@code Builder} is not thread-safe and generally should not be stored in a field or collection, * but instead used immediately to create instances. */ @Generated(from = "GaugeValueDaoImpl.NeedsRollupKey", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_AGENT_ROLLUP_ID = 0x1L; private static final long INIT_BIT_CAPTURE_TIME = 0x2L; private long initBits = 0x3L; private @Nullable String agentRollupId; private long captureTime; private Builder() { } /** * Fill a builder with attribute values from the provided {@code NeedsRollupKey} instance. * Regular attribute values will be replaced with those from the given instance. * Absent optional values will not replace present values. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder copyFrom(GaugeValueDaoImpl.NeedsRollupKey instance) { Objects.requireNonNull(instance, "instance"); agentRollupId(instance.agentRollupId()); captureTime(instance.captureTime()); return this; } /** * Initializes the value for the {@link GaugeValueDaoImpl.NeedsRollupKey#agentRollupId() agentRollupId} attribute. * @param agentRollupId The value for agentRollupId * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder agentRollupId(String agentRollupId) { this.agentRollupId = Objects.requireNonNull(agentRollupId, "agentRollupId"); initBits &= ~INIT_BIT_AGENT_ROLLUP_ID; return this; } /** * Initializes the value for the {@link GaugeValueDaoImpl.NeedsRollupKey#captureTime() captureTime} attribute. * @param captureTime The value for captureTime * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder captureTime(long captureTime) { this.captureTime = captureTime; initBits &= ~INIT_BIT_CAPTURE_TIME; return this; } /** * Builds a new {@link ImmutableNeedsRollupKey ImmutableNeedsRollupKey}. * @return An immutable instance of NeedsRollupKey * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableNeedsRollupKey build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableNeedsRollupKey(null, agentRollupId, captureTime); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_AGENT_ROLLUP_ID) != 0) attributes.add("agentRollupId"); if ((initBits & INIT_BIT_CAPTURE_TIME) != 0) attributes.add("captureTime"); return "Cannot build NeedsRollupKey, some of required attributes are not set " + attributes; } } }