
org.kiwiproject.consul.model.query.ImmutableFailover Maven / Gradle / Ivy
package org.kiwiproject.consul.model.query;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import jakarta.annotation.Nullable;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link Failover}.
*
* Use the builder to create immutable instances:
* {@code ImmutableFailover.builder()}.
*/
@Generated(from = "Failover", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@JsonIgnoreProperties(ignoreUnknown = true)
public final class ImmutableFailover extends Failover {
private final @Nullable Integer nearestN;
private final @Nullable List datacenters;
private ImmutableFailover(
@Nullable Integer nearestN,
@Nullable List datacenters) {
this.nearestN = nearestN;
this.datacenters = datacenters;
}
/**
* @return The value of the {@code nearestN} attribute
*/
@JsonProperty("NearestN")
@Override
public Optional getNearestN() {
return Optional.ofNullable(nearestN);
}
/**
* @return The value of the {@code datacenters} attribute
*/
@JsonProperty("Datacenters")
@Override
public Optional> datacenters() {
return Optional.ofNullable(datacenters);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Failover#getNearestN() nearestN} attribute.
* @param value The value for nearestN
* @return A modified copy of {@code this} object
*/
public final ImmutableFailover withNearestN(int value) {
@Nullable Integer newValue = value;
if (Objects.equals(this.nearestN, newValue)) return this;
return new ImmutableFailover(newValue, this.datacenters);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Failover#getNearestN() nearestN} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for nearestN
* @return A modified copy of {@code this} object
*/
public final ImmutableFailover withNearestN(Optional optional) {
@Nullable Integer value = optional.orElse(null);
if (Objects.equals(this.nearestN, value)) return this;
return new ImmutableFailover(value, this.datacenters);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Failover#datacenters() datacenters} attribute.
* @param value The value for datacenters
* @return A modified copy of {@code this} object
*/
public final ImmutableFailover withDatacenters(List value) {
List newValue = Objects.requireNonNull(value, "datacenters");
if (this.datacenters == newValue) return this;
return new ImmutableFailover(this.nearestN, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Failover#datacenters() datacenters} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for datacenters
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final ImmutableFailover withDatacenters(Optional extends List> optional) {
@Nullable List value = optional.orElse(null);
if (this.datacenters == value) return this;
return new ImmutableFailover(this.nearestN, value);
}
/**
* This instance is equal to all instances of {@code ImmutableFailover} 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 ImmutableFailover
&& equalTo(0, (ImmutableFailover) another);
}
private boolean equalTo(int synthetic, ImmutableFailover another) {
return Objects.equals(nearestN, another.nearestN)
&& Objects.equals(datacenters, another.datacenters);
}
/**
* Computes a hash code from attributes: {@code nearestN}, {@code datacenters}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(nearestN);
h += (h << 5) + Objects.hashCode(datacenters);
return h;
}
/**
* Prints the immutable value {@code Failover} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Failover")
.omitNullValues()
.add("nearestN", nearestN)
.add("datacenters", datacenters)
.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 = "Failover", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends Failover {
@Nullable Optional nearestN = Optional.empty();
@Nullable Optional> datacenters = Optional.empty();
@JsonProperty("NearestN")
public void setNearestN(Optional nearestN) {
this.nearestN = nearestN;
}
@JsonProperty("Datacenters")
public void setDatacenters(Optional> datacenters) {
this.datacenters = datacenters;
}
@Override
public Optional getNearestN() { throw new UnsupportedOperationException(); }
@Override
public Optional> datacenters() { 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 ImmutableFailover fromJson(Json json) {
ImmutableFailover.Builder builder = ImmutableFailover.builder();
if (json.nearestN != null) {
builder.nearestN(json.nearestN);
}
if (json.datacenters != null) {
builder.datacenters(json.datacenters);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link Failover} 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 Failover instance
*/
public static ImmutableFailover copyOf(Failover instance) {
if (instance instanceof ImmutableFailover) {
return (ImmutableFailover) instance;
}
return ImmutableFailover.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableFailover ImmutableFailover}.
*
* ImmutableFailover.builder()
* .nearestN(Integer) // optional {@link Failover#getNearestN() nearestN}
* .datacenters(List<String>) // optional {@link Failover#datacenters() datacenters}
* .build();
*
* @return A new ImmutableFailover builder
*/
public static ImmutableFailover.Builder builder() {
return new ImmutableFailover.Builder();
}
/**
* Builds instances of type {@link ImmutableFailover ImmutableFailover}.
* 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 = "Failover", generator = "Immutables")
public static final class Builder {
private @Nullable Integer nearestN;
private @Nullable List datacenters;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Failover} 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(Failover instance) {
Objects.requireNonNull(instance, "instance");
Optional nearestNOptional = instance.getNearestN();
if (nearestNOptional.isPresent()) {
nearestN(nearestNOptional);
}
Optional> datacentersOptional = instance.datacenters();
if (datacentersOptional.isPresent()) {
datacenters(datacentersOptional);
}
return this;
}
/**
* Initializes the optional value {@link Failover#getNearestN() nearestN} to nearestN.
* @param nearestN The value for nearestN
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder nearestN(int nearestN) {
this.nearestN = nearestN;
return this;
}
/**
* Initializes the optional value {@link Failover#getNearestN() nearestN} to nearestN.
* @param nearestN The value for nearestN
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("NearestN")
public final Builder nearestN(Optional nearestN) {
this.nearestN = nearestN.orElse(null);
return this;
}
/**
* Initializes the optional value {@link Failover#datacenters() datacenters} to datacenters.
* @param datacenters The value for datacenters
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder datacenters(List datacenters) {
this.datacenters = Objects.requireNonNull(datacenters, "datacenters");
return this;
}
/**
* Initializes the optional value {@link Failover#datacenters() datacenters} to datacenters.
* @param datacenters The value for datacenters
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("Datacenters")
public final Builder datacenters(Optional extends List> datacenters) {
this.datacenters = datacenters.orElse(null);
return this;
}
/**
* Builds a new {@link ImmutableFailover ImmutableFailover}.
* @return An immutable instance of Failover
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableFailover build() {
return new ImmutableFailover(nearestN, datacenters);
}
}
}