com.hubspot.imap.ProxyConfig Maven / Gradle / Ivy
package com.hubspot.imap;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.net.HostAndPort;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
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 ProxyConfigIF}.
*
* Use the builder to create immutable instances:
* {@code ProxyConfig.builder()}.
*/
@Generated(from = "ProxyConfigIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ProxyConfig implements ProxyConfigIF {
private final HostAndPort proxyHost;
private final Optional proxyLocalIpAddress;
private final Optional proxyPublicIpAddress;
private ProxyConfig(ProxyConfig.Builder builder) {
this.proxyHost = builder.proxyHost;
if (builder.proxyLocalIpAddress != null) {
initShim.proxyLocalIpAddress(builder.proxyLocalIpAddress);
}
if (builder.proxyPublicIpAddress != null) {
initShim.proxyPublicIpAddress(builder.proxyPublicIpAddress);
}
this.proxyLocalIpAddress = initShim.proxyLocalIpAddress();
this.proxyPublicIpAddress = initShim.proxyPublicIpAddress();
this.initShim = null;
}
private ProxyConfig(
HostAndPort proxyHost,
Optional proxyLocalIpAddress,
Optional proxyPublicIpAddress) {
this.proxyHost = proxyHost;
this.proxyLocalIpAddress = proxyLocalIpAddress;
this.proxyPublicIpAddress = proxyPublicIpAddress;
this.initShim = null;
}
private static final byte STAGE_INITIALIZING = -1;
private static final byte STAGE_UNINITIALIZED = 0;
private static final byte STAGE_INITIALIZED = 1;
@SuppressWarnings("Immutable")
private transient volatile InitShim initShim = new InitShim();
@Generated(from = "ProxyConfigIF", generator = "Immutables")
private final class InitShim {
private byte proxyLocalIpAddressBuildStage = STAGE_UNINITIALIZED;
private Optional proxyLocalIpAddress;
Optional proxyLocalIpAddress() {
if (proxyLocalIpAddressBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (proxyLocalIpAddressBuildStage == STAGE_UNINITIALIZED) {
proxyLocalIpAddressBuildStage = STAGE_INITIALIZING;
this.proxyLocalIpAddress = Objects.requireNonNull(proxyLocalIpAddressInitialize(), "proxyLocalIpAddress");
proxyLocalIpAddressBuildStage = STAGE_INITIALIZED;
}
return this.proxyLocalIpAddress;
}
void proxyLocalIpAddress(Optional proxyLocalIpAddress) {
this.proxyLocalIpAddress = proxyLocalIpAddress;
proxyLocalIpAddressBuildStage = STAGE_INITIALIZED;
}
private byte proxyPublicIpAddressBuildStage = STAGE_UNINITIALIZED;
private Optional proxyPublicIpAddress;
Optional proxyPublicIpAddress() {
if (proxyPublicIpAddressBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (proxyPublicIpAddressBuildStage == STAGE_UNINITIALIZED) {
proxyPublicIpAddressBuildStage = STAGE_INITIALIZING;
this.proxyPublicIpAddress = Objects.requireNonNull(proxyPublicIpAddressInitialize(), "proxyPublicIpAddress");
proxyPublicIpAddressBuildStage = STAGE_INITIALIZED;
}
return this.proxyPublicIpAddress;
}
void proxyPublicIpAddress(Optional proxyPublicIpAddress) {
this.proxyPublicIpAddress = proxyPublicIpAddress;
proxyPublicIpAddressBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (proxyLocalIpAddressBuildStage == STAGE_INITIALIZING) attributes.add("proxyLocalIpAddress");
if (proxyPublicIpAddressBuildStage == STAGE_INITIALIZING) attributes.add("proxyPublicIpAddress");
return "Cannot build ProxyConfig, attribute initializers form cycle " + attributes;
}
}
private Optional proxyLocalIpAddressInitialize() {
return ProxyConfigIF.super.proxyLocalIpAddress();
}
private Optional proxyPublicIpAddressInitialize() {
return ProxyConfigIF.super.proxyPublicIpAddress();
}
/**
* @return The value of the {@code proxyHost} attribute
*/
@JsonProperty("proxyHost")
@Override
public HostAndPort proxyHost() {
return proxyHost;
}
/**
* @return The value of the {@code proxyLocalIpAddress} attribute
*/
@JsonProperty("proxyLocalIpAddress")
@Override
public Optional proxyLocalIpAddress() {
InitShim shim = this.initShim;
return shim != null
? shim.proxyLocalIpAddress()
: this.proxyLocalIpAddress;
}
/**
* @return The value of the {@code proxyPublicIpAddress} attribute
*/
@JsonProperty("proxyPublicIpAddress")
@Override
public Optional proxyPublicIpAddress() {
InitShim shim = this.initShim;
return shim != null
? shim.proxyPublicIpAddress()
: this.proxyPublicIpAddress;
}
/**
* Copy the current immutable object by setting a value for the {@link ProxyConfigIF#proxyHost() proxyHost} 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 proxyHost
* @return A modified copy of the {@code this} object
*/
public final ProxyConfig withProxyHost(HostAndPort value) {
if (this.proxyHost == value) return this;
HostAndPort newValue = Objects.requireNonNull(value, "proxyHost");
return new ProxyConfig(newValue, this.proxyLocalIpAddress, this.proxyPublicIpAddress);
}
/**
* Copy the current immutable object by setting a value for the {@link ProxyConfigIF#proxyLocalIpAddress() proxyLocalIpAddress} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for proxyLocalIpAddress
* @return A modified copy of the {@code this} object
*/
public final ProxyConfig withProxyLocalIpAddress(Optional value) {
Optional newValue = Objects.requireNonNull(value, "proxyLocalIpAddress");
if (this.proxyLocalIpAddress.equals(newValue)) return this;
return new ProxyConfig(this.proxyHost, newValue, this.proxyPublicIpAddress);
}
/**
* Copy the current immutable object by setting a value for the {@link ProxyConfigIF#proxyPublicIpAddress() proxyPublicIpAddress} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for proxyPublicIpAddress
* @return A modified copy of the {@code this} object
*/
public final ProxyConfig withProxyPublicIpAddress(Optional value) {
Optional newValue = Objects.requireNonNull(value, "proxyPublicIpAddress");
if (this.proxyPublicIpAddress.equals(newValue)) return this;
return new ProxyConfig(this.proxyHost, this.proxyLocalIpAddress, newValue);
}
/**
* This instance is equal to all instances of {@code ProxyConfig} 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 ProxyConfig
&& equalTo((ProxyConfig) another);
}
private boolean equalTo(ProxyConfig another) {
return proxyHost.equals(another.proxyHost)
&& proxyLocalIpAddress.equals(another.proxyLocalIpAddress)
&& proxyPublicIpAddress.equals(another.proxyPublicIpAddress);
}
/**
* Computes a hash code from attributes: {@code proxyHost}, {@code proxyLocalIpAddress}, {@code proxyPublicIpAddress}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + proxyHost.hashCode();
h += (h << 5) + proxyLocalIpAddress.hashCode();
h += (h << 5) + proxyPublicIpAddress.hashCode();
return h;
}
/**
* Prints the immutable value {@code ProxyConfig} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ProxyConfig")
.omitNullValues()
.add("proxyHost", proxyHost)
.add("proxyLocalIpAddress", proxyLocalIpAddress)
.add("proxyPublicIpAddress", proxyPublicIpAddress)
.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 = "ProxyConfigIF", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements ProxyConfigIF {
@Nullable HostAndPort proxyHost;
@Nullable Optional proxyLocalIpAddress;
@Nullable Optional proxyPublicIpAddress;
@JsonProperty("proxyHost")
public void setProxyHost(HostAndPort proxyHost) {
this.proxyHost = proxyHost;
}
@JsonProperty("proxyLocalIpAddress")
public void setProxyLocalIpAddress(Optional proxyLocalIpAddress) {
this.proxyLocalIpAddress = proxyLocalIpAddress;
}
@JsonProperty("proxyPublicIpAddress")
public void setProxyPublicIpAddress(Optional proxyPublicIpAddress) {
this.proxyPublicIpAddress = proxyPublicIpAddress;
}
@Override
public HostAndPort proxyHost() { throw new UnsupportedOperationException(); }
@Override
public Optional proxyLocalIpAddress() { throw new UnsupportedOperationException(); }
@Override
public Optional proxyPublicIpAddress() { 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 ProxyConfig fromJson(Json json) {
ProxyConfig.Builder builder = ProxyConfig.builder();
if (json.proxyHost != null) {
builder.proxyHost(json.proxyHost);
}
if (json.proxyLocalIpAddress != null) {
builder.proxyLocalIpAddress(json.proxyLocalIpAddress);
}
if (json.proxyPublicIpAddress != null) {
builder.proxyPublicIpAddress(json.proxyPublicIpAddress);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link ProxyConfigIF} 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 ProxyConfig instance
*/
public static ProxyConfig copyOf(ProxyConfigIF instance) {
if (instance instanceof ProxyConfig) {
return (ProxyConfig) instance;
}
return ProxyConfig.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ProxyConfig ProxyConfig}.
*
* ProxyConfig.builder()
* .proxyHost(com.google.common.net.HostAndPort) // required {@link ProxyConfigIF#proxyHost() proxyHost}
* .proxyLocalIpAddress(Optional<String>) // optional {@link ProxyConfigIF#proxyLocalIpAddress() proxyLocalIpAddress}
* .proxyPublicIpAddress(Optional<String>) // optional {@link ProxyConfigIF#proxyPublicIpAddress() proxyPublicIpAddress}
* .build();
*
* @return A new ProxyConfig builder
*/
public static ProxyConfig.Builder builder() {
return new ProxyConfig.Builder();
}
/**
* Builds instances of type {@link ProxyConfig ProxyConfig}.
* 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 = "ProxyConfigIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_PROXY_HOST = 0x1L;
private long initBits = 0x1L;
private @Nullable HostAndPort proxyHost;
private @Nullable Optional proxyLocalIpAddress;
private @Nullable Optional proxyPublicIpAddress;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ProxyConfigIF} 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 from(ProxyConfigIF instance) {
Objects.requireNonNull(instance, "instance");
proxyHost(instance.proxyHost());
proxyLocalIpAddress(instance.proxyLocalIpAddress());
proxyPublicIpAddress(instance.proxyPublicIpAddress());
return this;
}
/**
* Initializes the value for the {@link ProxyConfigIF#proxyHost() proxyHost} attribute.
* @param proxyHost The value for proxyHost
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("proxyHost")
public final Builder proxyHost(HostAndPort proxyHost) {
this.proxyHost = Objects.requireNonNull(proxyHost, "proxyHost");
initBits &= ~INIT_BIT_PROXY_HOST;
return this;
}
/**
* Initializes the value for the {@link ProxyConfigIF#proxyLocalIpAddress() proxyLocalIpAddress} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link ProxyConfigIF#proxyLocalIpAddress() proxyLocalIpAddress}.
* @param proxyLocalIpAddress The value for proxyLocalIpAddress
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("proxyLocalIpAddress")
public final Builder proxyLocalIpAddress(Optional proxyLocalIpAddress) {
this.proxyLocalIpAddress = Objects.requireNonNull(proxyLocalIpAddress, "proxyLocalIpAddress");
return this;
}
/**
* Initializes the value for the {@link ProxyConfigIF#proxyPublicIpAddress() proxyPublicIpAddress} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link ProxyConfigIF#proxyPublicIpAddress() proxyPublicIpAddress}.
* @param proxyPublicIpAddress The value for proxyPublicIpAddress
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("proxyPublicIpAddress")
public final Builder proxyPublicIpAddress(Optional proxyPublicIpAddress) {
this.proxyPublicIpAddress = Objects.requireNonNull(proxyPublicIpAddress, "proxyPublicIpAddress");
return this;
}
/**
* Builds a new {@link ProxyConfig ProxyConfig}.
* @return An immutable instance of ProxyConfig
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ProxyConfig build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ProxyConfig(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_PROXY_HOST) != 0) attributes.add("proxyHost");
return "Cannot build ProxyConfig, some of required attributes are not set " + attributes;
}
}
}