org.glowroot.central.ImmutableSyntheticMonitorUniqueKey Maven / Gradle / Ivy
package org.glowroot.central;
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.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 SyntheticMonitorService.SyntheticMonitorUniqueKey}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSyntheticMonitorUniqueKey.builder()}.
* Use the static factory method to create immutable instances:
* {@code ImmutableSyntheticMonitorUniqueKey.of()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "SyntheticMonitorService.SyntheticMonitorUniqueKey"})
@Immutable
@CheckReturnValue
final class ImmutableSyntheticMonitorUniqueKey
implements SyntheticMonitorService.SyntheticMonitorUniqueKey {
private final String agentRollupId;
private final String syntheticMonitorId;
private ImmutableSyntheticMonitorUniqueKey(String agentRollupId, String syntheticMonitorId) {
this.agentRollupId = Objects.requireNonNull(agentRollupId, "agentRollupId");
this.syntheticMonitorId = Objects.requireNonNull(syntheticMonitorId, "syntheticMonitorId");
}
private ImmutableSyntheticMonitorUniqueKey(
ImmutableSyntheticMonitorUniqueKey original,
String agentRollupId,
String syntheticMonitorId) {
this.agentRollupId = agentRollupId;
this.syntheticMonitorId = syntheticMonitorId;
}
/**
* @return The value of the {@code agentRollupId} attribute
*/
@JsonProperty("agentRollupId")
@Override
public String agentRollupId() {
return agentRollupId;
}
/**
* @return The value of the {@code syntheticMonitorId} attribute
*/
@JsonProperty("syntheticMonitorId")
@Override
public String syntheticMonitorId() {
return syntheticMonitorId;
}
/**
* Copy the current immutable object by setting a value for the {@link SyntheticMonitorService.SyntheticMonitorUniqueKey#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 ImmutableSyntheticMonitorUniqueKey withAgentRollupId(String value) {
if (this.agentRollupId.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "agentRollupId");
return new ImmutableSyntheticMonitorUniqueKey(this, newValue, this.syntheticMonitorId);
}
/**
* Copy the current immutable object by setting a value for the {@link SyntheticMonitorService.SyntheticMonitorUniqueKey#syntheticMonitorId() syntheticMonitorId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for syntheticMonitorId
* @return A modified copy of the {@code this} object
*/
public final ImmutableSyntheticMonitorUniqueKey withSyntheticMonitorId(String value) {
if (this.syntheticMonitorId.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "syntheticMonitorId");
return new ImmutableSyntheticMonitorUniqueKey(this, this.agentRollupId, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableSyntheticMonitorUniqueKey} 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 ImmutableSyntheticMonitorUniqueKey
&& equalTo((ImmutableSyntheticMonitorUniqueKey) another);
}
private boolean equalTo(ImmutableSyntheticMonitorUniqueKey another) {
return agentRollupId.equals(another.agentRollupId)
&& syntheticMonitorId.equals(another.syntheticMonitorId);
}
/**
* Computes a hash code from attributes: {@code agentRollupId}, {@code syntheticMonitorId}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + agentRollupId.hashCode();
h += (h << 5) + syntheticMonitorId.hashCode();
return h;
}
/**
* Prints the immutable value {@code SyntheticMonitorUniqueKey} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SyntheticMonitorUniqueKey")
.omitNullValues()
.add("agentRollupId", agentRollupId)
.add("syntheticMonitorId", syntheticMonitorId)
.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 SyntheticMonitorService.SyntheticMonitorUniqueKey {
@Nullable String agentRollupId;
@Nullable String syntheticMonitorId;
@JsonProperty("agentRollupId")
public void setAgentRollupId(String agentRollupId) {
this.agentRollupId = agentRollupId;
}
@JsonProperty("syntheticMonitorId")
public void setSyntheticMonitorId(String syntheticMonitorId) {
this.syntheticMonitorId = syntheticMonitorId;
}
@Override
public String agentRollupId() { throw new UnsupportedOperationException(); }
@Override
public String syntheticMonitorId() { 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 ImmutableSyntheticMonitorUniqueKey fromJson(Json json) {
ImmutableSyntheticMonitorUniqueKey.Builder builder = ImmutableSyntheticMonitorUniqueKey.builder();
if (json.agentRollupId != null) {
builder.agentRollupId(json.agentRollupId);
}
if (json.syntheticMonitorId != null) {
builder.syntheticMonitorId(json.syntheticMonitorId);
}
return builder.build();
}
/**
* Construct a new immutable {@code SyntheticMonitorUniqueKey} instance.
* @param agentRollupId The value for the {@code agentRollupId} attribute
* @param syntheticMonitorId The value for the {@code syntheticMonitorId} attribute
* @return An immutable SyntheticMonitorUniqueKey instance
*/
public static ImmutableSyntheticMonitorUniqueKey of(String agentRollupId, String syntheticMonitorId) {
return new ImmutableSyntheticMonitorUniqueKey(agentRollupId, syntheticMonitorId);
}
/**
* Creates an immutable copy of a {@link SyntheticMonitorService.SyntheticMonitorUniqueKey} 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 SyntheticMonitorUniqueKey instance
*/
public static ImmutableSyntheticMonitorUniqueKey copyOf(SyntheticMonitorService.SyntheticMonitorUniqueKey instance) {
if (instance instanceof ImmutableSyntheticMonitorUniqueKey) {
return (ImmutableSyntheticMonitorUniqueKey) instance;
}
return ImmutableSyntheticMonitorUniqueKey.builder()
.copyFrom(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableSyntheticMonitorUniqueKey ImmutableSyntheticMonitorUniqueKey}.
* @return A new ImmutableSyntheticMonitorUniqueKey builder
*/
public static ImmutableSyntheticMonitorUniqueKey.Builder builder() {
return new ImmutableSyntheticMonitorUniqueKey.Builder();
}
/**
* Builds instances of type {@link ImmutableSyntheticMonitorUniqueKey ImmutableSyntheticMonitorUniqueKey}.
* 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_ROLLUP_ID = 0x1L;
private static final long INIT_BIT_SYNTHETIC_MONITOR_ID = 0x2L;
private long initBits = 0x3L;
private @Nullable String agentRollupId;
private @Nullable String syntheticMonitorId;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code SyntheticMonitorUniqueKey} 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(SyntheticMonitorService.SyntheticMonitorUniqueKey instance) {
Objects.requireNonNull(instance, "instance");
agentRollupId(instance.agentRollupId());
syntheticMonitorId(instance.syntheticMonitorId());
return this;
}
/**
* Initializes the value for the {@link SyntheticMonitorService.SyntheticMonitorUniqueKey#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 SyntheticMonitorService.SyntheticMonitorUniqueKey#syntheticMonitorId() syntheticMonitorId} attribute.
* @param syntheticMonitorId The value for syntheticMonitorId
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder syntheticMonitorId(String syntheticMonitorId) {
this.syntheticMonitorId = Objects.requireNonNull(syntheticMonitorId, "syntheticMonitorId");
initBits &= ~INIT_BIT_SYNTHETIC_MONITOR_ID;
return this;
}
/**
* Builds a new {@link ImmutableSyntheticMonitorUniqueKey ImmutableSyntheticMonitorUniqueKey}.
* @return An immutable instance of SyntheticMonitorUniqueKey
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSyntheticMonitorUniqueKey build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableSyntheticMonitorUniqueKey(null, agentRollupId, syntheticMonitorId);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_AGENT_ROLLUP_ID) != 0) attributes.add("agentRollupId");
if ((initBits & INIT_BIT_SYNTHETIC_MONITOR_ID) != 0) attributes.add("syntheticMonitorId");
return "Cannot build SyntheticMonitorUniqueKey, some of required attributes are not set " + attributes;
}
}
}