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

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

There is a newer version: 0.14.0-beta.3
Show newest version
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.collect.Lists;
import com.google.common.primitives.Longs;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
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 AgentDao.AgentInsertKey}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableAgentInsertKey.builder()}. * Use the static factory method to create immutable instances: * {@code ImmutableAgentInsertKey.of()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "AgentDao.AgentInsertKey"}) @Immutable @CheckReturnValue final class ImmutableAgentInsertKey implements AgentDao.AgentInsertKey { private final String agentId; private final long captureTime; private ImmutableAgentInsertKey(String agentId, long captureTime) { this.agentId = Objects.requireNonNull(agentId, "agentId"); this.captureTime = captureTime; } private ImmutableAgentInsertKey(ImmutableAgentInsertKey original, String agentId, long captureTime) { this.agentId = agentId; this.captureTime = captureTime; } /** * @return The value of the {@code agentId} attribute */ @JsonProperty("agentId") @Override public String agentId() { return agentId; } /** * @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 AgentDao.AgentInsertKey#agentId() agentId} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for agentId * @return A modified copy of the {@code this} object */ public final ImmutableAgentInsertKey withAgentId(String value) { if (this.agentId.equals(value)) return this; String newValue = Objects.requireNonNull(value, "agentId"); return new ImmutableAgentInsertKey(this, newValue, this.captureTime); } /** * Copy the current immutable object by setting a value for the {@link AgentDao.AgentInsertKey#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 ImmutableAgentInsertKey withCaptureTime(long value) { if (this.captureTime == value) return this; return new ImmutableAgentInsertKey(this, this.agentId, value); } /** * This instance is equal to all instances of {@code ImmutableAgentInsertKey} 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 ImmutableAgentInsertKey && equalTo((ImmutableAgentInsertKey) another); } private boolean equalTo(ImmutableAgentInsertKey another) { return agentId.equals(another.agentId) && captureTime == another.captureTime; } /** * Computes a hash code from attributes: {@code agentId}, {@code captureTime}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + agentId.hashCode(); h += (h << 5) + Longs.hashCode(captureTime); return h; } /** * Prints the immutable value {@code AgentInsertKey} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("AgentInsertKey") .omitNullValues() .add("agentId", agentId) .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 */ @Deprecated @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements AgentDao.AgentInsertKey { @Nullable String agentId; long captureTime; boolean captureTimeIsSet; @JsonProperty("agentId") public void setAgentId(String agentId) { this.agentId = agentId; } @JsonProperty("captureTime") public void setCaptureTime(long captureTime) { this.captureTime = captureTime; this.captureTimeIsSet = true; } @Override public String agentId() { 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 ImmutableAgentInsertKey fromJson(Json json) { ImmutableAgentInsertKey.Builder builder = ImmutableAgentInsertKey.builder(); if (json.agentId != null) { builder.agentId(json.agentId); } if (json.captureTimeIsSet) { builder.captureTime(json.captureTime); } return builder.build(); } /** * Construct a new immutable {@code AgentInsertKey} instance. * @param agentId The value for the {@code agentId} attribute * @param captureTime The value for the {@code captureTime} attribute * @return An immutable AgentInsertKey instance */ public static ImmutableAgentInsertKey of(String agentId, long captureTime) { return new ImmutableAgentInsertKey(agentId, captureTime); } /** * Creates an immutable copy of a {@link AgentDao.AgentInsertKey} 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 AgentInsertKey instance */ public static ImmutableAgentInsertKey copyOf(AgentDao.AgentInsertKey instance) { if (instance instanceof ImmutableAgentInsertKey) { return (ImmutableAgentInsertKey) instance; } return ImmutableAgentInsertKey.builder() .copyFrom(instance) .build(); } /** * Creates a builder for {@link ImmutableAgentInsertKey ImmutableAgentInsertKey}. * @return A new ImmutableAgentInsertKey builder */ public static ImmutableAgentInsertKey.Builder builder() { return new ImmutableAgentInsertKey.Builder(); } /** * Builds instances of type {@link ImmutableAgentInsertKey ImmutableAgentInsertKey}. * 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. */ @NotThreadSafe public static final class Builder { private static final long INIT_BIT_AGENT_ID = 0x1L; private static final long INIT_BIT_CAPTURE_TIME = 0x2L; private long initBits = 0x3L; private @Nullable String agentId; private long captureTime; private Builder() { } /** * Fill a builder with attribute values from the provided {@code AgentInsertKey} 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(AgentDao.AgentInsertKey instance) { Objects.requireNonNull(instance, "instance"); agentId(instance.agentId()); captureTime(instance.captureTime()); return this; } /** * Initializes the value for the {@link AgentDao.AgentInsertKey#agentId() agentId} attribute. * @param agentId The value for agentId * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder agentId(String agentId) { this.agentId = Objects.requireNonNull(agentId, "agentId"); initBits &= ~INIT_BIT_AGENT_ID; return this; } /** * Initializes the value for the {@link AgentDao.AgentInsertKey#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 ImmutableAgentInsertKey ImmutableAgentInsertKey}. * @return An immutable instance of AgentInsertKey * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableAgentInsertKey build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableAgentInsertKey(null, agentId, captureTime); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_AGENT_ID) != 0) attributes.add("agentId"); if ((initBits & INIT_BIT_CAPTURE_TIME) != 0) attributes.add("captureTime"); return "Cannot build AgentInsertKey, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy