
org.glowroot.ui.ImmutableSmtpConfigResponse Maven / Gradle / Ivy
package org.glowroot.ui;
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;
/**
* Immutable implementation of {@link ConfigJsonService.SmtpConfigResponse}.
*
* Use builder to create immutable instances:
* {@code ImmutableSmtpConfigResponse.builder()}.
*/
@SuppressWarnings("all")
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ConfigJsonService.SmtpConfigResponse"})
@Immutable
final class ImmutableSmtpConfigResponse implements ConfigJsonService.SmtpConfigResponse {
private final ConfigJsonService.SmtpConfigDto config;
private final String localServerName;
private ImmutableSmtpConfigResponse(ConfigJsonService.SmtpConfigDto config, String localServerName) {
this.config = config;
this.localServerName = localServerName;
}
/**
* @return value of {@code config} attribute
*/
@JsonProperty
@Override
public ConfigJsonService.SmtpConfigDto config() {
return config;
}
/**
* @return value of {@code localServerName} attribute
*/
@JsonProperty
@Override
public String localServerName() {
return localServerName;
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.SmtpConfigResponse#config() config}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for config
* @return modified copy of the {@code this} object
*/
public final ImmutableSmtpConfigResponse withConfig(ConfigJsonService.SmtpConfigDto value) {
if (this.config == value) return this;
ConfigJsonService.SmtpConfigDto newValue = Preconditions.checkNotNull(value);
return new ImmutableSmtpConfigResponse(newValue, this.localServerName);
}
/**
* Copy current immutable object by setting value for {@link ConfigJsonService.SmtpConfigResponse#localServerName() localServerName}.
* Shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value new value for localServerName
* @return modified copy of the {@code this} object
*/
public final ImmutableSmtpConfigResponse withLocalServerName(String value) {
if (this.localServerName == value) return this;
String newValue = Preconditions.checkNotNull(value);
return new ImmutableSmtpConfigResponse(this.config, newValue);
}
/**
* This instance is equal to instances of {@code ImmutableSmtpConfigResponse} 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 ImmutableSmtpConfigResponse
&& equalTo((ImmutableSmtpConfigResponse) another);
}
private boolean equalTo(ImmutableSmtpConfigResponse another) {
return config.equals(another.config)
&& localServerName.equals(another.localServerName);
}
/**
* Computes hash code from attributes: {@code config}, {@code localServerName}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + config.hashCode();
h = h * 17 + localServerName.hashCode();
return h;
}
/**
* Prints immutable value {@code SmtpConfigResponse...} with attribute values,
* excluding any non-generated and auxiliary attributes.
* @return string representation of value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SmtpConfigResponse")
.add("config", config)
.add("localServerName", localServerName)
.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 ConfigJsonService.SmtpConfigDto config;
@JsonProperty
@Nullable String localServerName;
}
/**
* @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 ImmutableSmtpConfigResponse fromJson(Json json) {
ImmutableSmtpConfigResponse.Builder builder = ImmutableSmtpConfigResponse.builder();
if (json.config != null) {
builder.config(json.config);
}
if (json.localServerName != null) {
builder.localServerName(json.localServerName);
}
return builder.build();
}
/**
* Creates immutable copy of {@link ConfigJsonService.SmtpConfigResponse}.
* 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 SmtpConfigResponse instance
*/
static ImmutableSmtpConfigResponse copyOf(ConfigJsonService.SmtpConfigResponse instance) {
if (instance instanceof ImmutableSmtpConfigResponse) {
return (ImmutableSmtpConfigResponse) instance;
}
return ImmutableSmtpConfigResponse.builder()
.copyFrom(instance)
.build();
}
/**
* Creates builder for {@link org.glowroot.ui.ImmutableSmtpConfigResponse ImmutableSmtpConfigResponse}.
* @return new ImmutableSmtpConfigResponse builder
*/
static ImmutableSmtpConfigResponse.Builder builder() {
return new ImmutableSmtpConfigResponse.Builder();
}
/**
* Builds instances of {@link org.glowroot.ui.ImmutableSmtpConfigResponse ImmutableSmtpConfigResponse}.
* 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
static final class Builder {
private static final long INIT_BIT_CONFIG = 0x1L;
private static final long INIT_BIT_LOCAL_SERVER_NAME = 0x2L;
private long initBits = 0x3;
private @Nullable ConfigJsonService.SmtpConfigDto config;
private @Nullable String localServerName;
private Builder() {}
/**
* Fill builder with attribute values from provided {@link ConfigJsonService.SmtpConfigResponse} 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(ConfigJsonService.SmtpConfigResponse instance) {
Preconditions.checkNotNull(instance);
config(instance.config());
localServerName(instance.localServerName());
return this;
}
/**
* Initializes value for {@link ConfigJsonService.SmtpConfigResponse#config() config}.
* @param config value for config
* @return {@code this} builder for chained invocation
*/
public final Builder config(ConfigJsonService.SmtpConfigDto config) {
this.config = Preconditions.checkNotNull(config);
initBits &= ~INIT_BIT_CONFIG;
return this;
}
/**
* Initializes value for {@link ConfigJsonService.SmtpConfigResponse#localServerName() localServerName}.
* @param localServerName value for localServerName
* @return {@code this} builder for chained invocation
*/
public final Builder localServerName(String localServerName) {
this.localServerName = Preconditions.checkNotNull(localServerName);
initBits &= ~INIT_BIT_LOCAL_SERVER_NAME;
return this;
}
/**
* Builds new {@link org.glowroot.ui.ImmutableSmtpConfigResponse ImmutableSmtpConfigResponse}.
* @return immutable instance of SmtpConfigResponse
* @throws exception {@code java.lang.IllegalStateException} if any required attributes are missing
*/
public ImmutableSmtpConfigResponse build()
throws IllegalStateException {
checkRequiredAttributes(); return new ImmutableSmtpConfigResponse(config, localServerName);
}
private boolean configIsSet() {
return (initBits & INIT_BIT_CONFIG) == 0;
}
private boolean localServerNameIsSet() {
return (initBits & INIT_BIT_LOCAL_SERVER_NAME) == 0;
}
private void checkRequiredAttributes() throws IllegalStateException {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if (!configIsSet()) attributes.add("config");
if (!localServerNameIsSet()) attributes.add("localServerName");
return "Cannot build SmtpConfigResponse, some of required attributes are not set " + attributes;
}
}
}