org.glowroot.central.repo.ImmutableAgentConfigUpdate 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.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
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;
import org.glowroot.wire.api.model.AgentConfigOuterClass;
/**
* Immutable implementation of {@link AgentDao.AgentConfigUpdate}.
*
* Use the builder to create immutable instances:
* {@code ImmutableAgentConfigUpdate.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "AgentDao.AgentConfigUpdate"})
@Immutable
@CheckReturnValue
public final class ImmutableAgentConfigUpdate implements AgentDao.AgentConfigUpdate {
private final AgentConfigOuterClass.AgentConfig config;
private final UUID configUpdateToken;
private ImmutableAgentConfigUpdate(
AgentConfigOuterClass.AgentConfig config,
UUID configUpdateToken) {
this.config = config;
this.configUpdateToken = configUpdateToken;
}
/**
* @return The value of the {@code config} attribute
*/
@JsonProperty("config")
@Override
public AgentConfigOuterClass.AgentConfig config() {
return config;
}
/**
* @return The value of the {@code configUpdateToken} attribute
*/
@JsonProperty("configUpdateToken")
@Override
public UUID configUpdateToken() {
return configUpdateToken;
}
/**
* Copy the current immutable object by setting a value for the {@link AgentDao.AgentConfigUpdate#config() config} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for config
* @return A modified copy of the {@code this} object
*/
public final ImmutableAgentConfigUpdate withConfig(AgentConfigOuterClass.AgentConfig value) {
if (this.config == value) return this;
AgentConfigOuterClass.AgentConfig newValue = Objects.requireNonNull(value, "config");
return new ImmutableAgentConfigUpdate(newValue, this.configUpdateToken);
}
/**
* Copy the current immutable object by setting a value for the {@link AgentDao.AgentConfigUpdate#configUpdateToken() configUpdateToken} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for configUpdateToken
* @return A modified copy of the {@code this} object
*/
public final ImmutableAgentConfigUpdate withConfigUpdateToken(UUID value) {
if (this.configUpdateToken == value) return this;
UUID newValue = Objects.requireNonNull(value, "configUpdateToken");
return new ImmutableAgentConfigUpdate(this.config, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableAgentConfigUpdate} 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 ImmutableAgentConfigUpdate
&& equalTo((ImmutableAgentConfigUpdate) another);
}
private boolean equalTo(ImmutableAgentConfigUpdate another) {
return config.equals(another.config)
&& configUpdateToken.equals(another.configUpdateToken);
}
/**
* Computes a hash code from attributes: {@code config}, {@code configUpdateToken}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + config.hashCode();
h += (h << 5) + configUpdateToken.hashCode();
return h;
}
/**
* Prints the immutable value {@code AgentConfigUpdate} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("AgentConfigUpdate")
.omitNullValues()
.add("config", config)
.add("configUpdateToken", configUpdateToken)
.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.AgentConfigUpdate {
@Nullable AgentConfigOuterClass.AgentConfig config;
@Nullable UUID configUpdateToken;
@JsonProperty("config")
public void setConfig(AgentConfigOuterClass.AgentConfig config) {
this.config = config;
}
@JsonProperty("configUpdateToken")
public void setConfigUpdateToken(UUID configUpdateToken) {
this.configUpdateToken = configUpdateToken;
}
@Override
public AgentConfigOuterClass.AgentConfig config() { throw new UnsupportedOperationException(); }
@Override
public UUID configUpdateToken() { 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 ImmutableAgentConfigUpdate fromJson(Json json) {
ImmutableAgentConfigUpdate.Builder builder = ImmutableAgentConfigUpdate.builder();
if (json.config != null) {
builder.config(json.config);
}
if (json.configUpdateToken != null) {
builder.configUpdateToken(json.configUpdateToken);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link AgentDao.AgentConfigUpdate} 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 AgentConfigUpdate instance
*/
public static ImmutableAgentConfigUpdate copyOf(AgentDao.AgentConfigUpdate instance) {
if (instance instanceof ImmutableAgentConfigUpdate) {
return (ImmutableAgentConfigUpdate) instance;
}
return ImmutableAgentConfigUpdate.builder()
.copyFrom(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableAgentConfigUpdate ImmutableAgentConfigUpdate}.
* @return A new ImmutableAgentConfigUpdate builder
*/
public static ImmutableAgentConfigUpdate.Builder builder() {
return new ImmutableAgentConfigUpdate.Builder();
}
/**
* Builds instances of type {@link ImmutableAgentConfigUpdate ImmutableAgentConfigUpdate}.
* 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_CONFIG = 0x1L;
private static final long INIT_BIT_CONFIG_UPDATE_TOKEN = 0x2L;
private long initBits = 0x3L;
private @Nullable AgentConfigOuterClass.AgentConfig config;
private @Nullable UUID configUpdateToken;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code AgentConfigUpdate} 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.AgentConfigUpdate instance) {
Objects.requireNonNull(instance, "instance");
config(instance.config());
configUpdateToken(instance.configUpdateToken());
return this;
}
/**
* Initializes the value for the {@link AgentDao.AgentConfigUpdate#config() config} attribute.
* @param config The value for config
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder config(AgentConfigOuterClass.AgentConfig config) {
this.config = Objects.requireNonNull(config, "config");
initBits &= ~INIT_BIT_CONFIG;
return this;
}
/**
* Initializes the value for the {@link AgentDao.AgentConfigUpdate#configUpdateToken() configUpdateToken} attribute.
* @param configUpdateToken The value for configUpdateToken
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder configUpdateToken(UUID configUpdateToken) {
this.configUpdateToken = Objects.requireNonNull(configUpdateToken, "configUpdateToken");
initBits &= ~INIT_BIT_CONFIG_UPDATE_TOKEN;
return this;
}
/**
* Builds a new {@link ImmutableAgentConfigUpdate ImmutableAgentConfigUpdate}.
* @return An immutable instance of AgentConfigUpdate
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableAgentConfigUpdate build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableAgentConfigUpdate(config, configUpdateToken);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_CONFIG) != 0) attributes.add("config");
if ((initBits & INIT_BIT_CONFIG_UPDATE_TOKEN) != 0) attributes.add("configUpdateToken");
return "Cannot build AgentConfigUpdate, some of required attributes are not set " + attributes;
}
}
}