
org.kiwiproject.consul.option.ImmutablePutOptions Maven / Gradle / Ivy
package org.kiwiproject.consul.option;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import jakarta.annotation.Nullable;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link PutOptions}.
*
* Use the builder to create immutable instances:
* {@code ImmutablePutOptions.builder()}.
*/
@Generated(from = "PutOptions", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutablePutOptions extends PutOptions {
private final ImmutableList toQueryParameters;
private final ImmutableMap toHeaders;
private final @Nullable Long cas;
private final @Nullable String acquire;
private final @Nullable String release;
private final @Nullable String dc;
private final @Nullable String token;
private ImmutablePutOptions(
ImmutableList toQueryParameters,
ImmutableMap toHeaders,
@Nullable Long cas,
@Nullable String acquire,
@Nullable String release,
@Nullable String dc,
@Nullable String token) {
this.toQueryParameters = toQueryParameters;
this.toHeaders = toHeaders;
this.cas = cas;
this.acquire = acquire;
this.release = release;
this.dc = dc;
this.token = token;
}
/**
* @return The value of the {@code toQueryParameters} attribute
*/
@Override
public ImmutableList toQueryParameters() {
return toQueryParameters;
}
/**
* @return The value of the {@code toHeaders} attribute
*/
@Override
public ImmutableMap toHeaders() {
return toHeaders;
}
/**
* @return The value of the {@code cas} attribute
*/
@Override
public Optional getCas() {
return Optional.ofNullable(cas);
}
/**
* @return The value of the {@code acquire} attribute
*/
@Override
public Optional getAcquire() {
return Optional.ofNullable(acquire);
}
/**
* @return The value of the {@code release} attribute
*/
@Override
public Optional getRelease() {
return Optional.ofNullable(release);
}
/**
* @return The value of the {@code dc} attribute
*/
@Override
public Optional getDc() {
return Optional.ofNullable(dc);
}
/**
* @return The value of the {@code token} attribute
*/
@Override
public Optional getToken() {
return Optional.ofNullable(token);
}
/**
* Copy the current immutable object with elements that replace the content of {@link PutOptions#toQueryParameters() toQueryParameters}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withToQueryParameters(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePutOptions(newValue, this.toHeaders, this.cas, this.acquire, this.release, this.dc, this.token);
}
/**
* Copy the current immutable object with elements that replace the content of {@link PutOptions#toQueryParameters() toQueryParameters}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of toQueryParameters elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withToQueryParameters(Iterable elements) {
if (this.toQueryParameters == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutablePutOptions(newValue, this.toHeaders, this.cas, this.acquire, this.release, this.dc, this.token);
}
/**
* Copy the current immutable object by replacing the {@link PutOptions#toHeaders() toHeaders} map with the specified map.
* Nulls are not permitted as keys or values.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param entries The entries to be added to the toHeaders map
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withToHeaders(Map entries) {
if (this.toHeaders == entries) return this;
ImmutableMap newValue = ImmutableMap.copyOf(entries);
return new ImmutablePutOptions(this.toQueryParameters, newValue, this.cas, this.acquire, this.release, this.dc, this.token);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link PutOptions#getCas() cas} attribute.
* @param value The value for cas
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withCas(long value) {
@Nullable Long newValue = value;
if (Objects.equals(this.cas, newValue)) return this;
return new ImmutablePutOptions(
this.toQueryParameters,
this.toHeaders,
newValue,
this.acquire,
this.release,
this.dc,
this.token);
}
/**
* Copy the current immutable object by setting an optional value for the {@link PutOptions#getCas() cas} 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 cas
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withCas(Optional optional) {
@Nullable Long value = optional.orElse(null);
if (Objects.equals(this.cas, value)) return this;
return new ImmutablePutOptions(this.toQueryParameters, this.toHeaders, value, this.acquire, this.release, this.dc, this.token);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link PutOptions#getAcquire() acquire} attribute.
* @param value The value for acquire
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withAcquire(String value) {
String newValue = Objects.requireNonNull(value, "acquire");
if (Objects.equals(this.acquire, newValue)) return this;
return new ImmutablePutOptions(this.toQueryParameters, this.toHeaders, this.cas, newValue, this.release, this.dc, this.token);
}
/**
* Copy the current immutable object by setting an optional value for the {@link PutOptions#getAcquire() acquire} 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 acquire
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withAcquire(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.acquire, value)) return this;
return new ImmutablePutOptions(this.toQueryParameters, this.toHeaders, this.cas, value, this.release, this.dc, this.token);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link PutOptions#getRelease() release} attribute.
* @param value The value for release
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withRelease(String value) {
String newValue = Objects.requireNonNull(value, "release");
if (Objects.equals(this.release, newValue)) return this;
return new ImmutablePutOptions(this.toQueryParameters, this.toHeaders, this.cas, this.acquire, newValue, this.dc, this.token);
}
/**
* Copy the current immutable object by setting an optional value for the {@link PutOptions#getRelease() release} 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 release
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withRelease(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.release, value)) return this;
return new ImmutablePutOptions(this.toQueryParameters, this.toHeaders, this.cas, this.acquire, value, this.dc, this.token);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link PutOptions#getDc() dc} attribute.
* @param value The value for dc
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withDc(String value) {
String newValue = Objects.requireNonNull(value, "dc");
if (Objects.equals(this.dc, newValue)) return this;
return new ImmutablePutOptions(
this.toQueryParameters,
this.toHeaders,
this.cas,
this.acquire,
this.release,
newValue,
this.token);
}
/**
* Copy the current immutable object by setting an optional value for the {@link PutOptions#getDc() dc} 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 dc
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withDc(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.dc, value)) return this;
return new ImmutablePutOptions(this.toQueryParameters, this.toHeaders, this.cas, this.acquire, this.release, value, this.token);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link PutOptions#getToken() token} attribute.
* @param value The value for token
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withToken(String value) {
String newValue = Objects.requireNonNull(value, "token");
if (Objects.equals(this.token, newValue)) return this;
return new ImmutablePutOptions(this.toQueryParameters, this.toHeaders, this.cas, this.acquire, this.release, this.dc, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link PutOptions#getToken() token} 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 token
* @return A modified copy of {@code this} object
*/
public final ImmutablePutOptions withToken(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.token, value)) return this;
return new ImmutablePutOptions(this.toQueryParameters, this.toHeaders, this.cas, this.acquire, this.release, this.dc, value);
}
/**
* This instance is equal to all instances of {@code ImmutablePutOptions} 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 ImmutablePutOptions
&& equalTo(0, (ImmutablePutOptions) another);
}
private boolean equalTo(int synthetic, ImmutablePutOptions another) {
return toQueryParameters.equals(another.toQueryParameters)
&& toHeaders.equals(another.toHeaders)
&& Objects.equals(cas, another.cas)
&& Objects.equals(acquire, another.acquire)
&& Objects.equals(release, another.release)
&& Objects.equals(dc, another.dc)
&& Objects.equals(token, another.token);
}
/**
* Computes a hash code from attributes: {@code toQueryParameters}, {@code toHeaders}, {@code cas}, {@code acquire}, {@code release}, {@code dc}, {@code token}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + toQueryParameters.hashCode();
h += (h << 5) + toHeaders.hashCode();
h += (h << 5) + Objects.hashCode(cas);
h += (h << 5) + Objects.hashCode(acquire);
h += (h << 5) + Objects.hashCode(release);
h += (h << 5) + Objects.hashCode(dc);
h += (h << 5) + Objects.hashCode(token);
return h;
}
/**
* Prints the immutable value {@code PutOptions} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("PutOptions")
.omitNullValues()
.add("toQueryParameters", toQueryParameters)
.add("toHeaders", toHeaders)
.add("cas", cas)
.add("acquire", acquire)
.add("release", release)
.add("dc", dc)
.add("token", token)
.toString();
}
/**
* Creates an immutable copy of a {@link PutOptions} 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 PutOptions instance
*/
public static ImmutablePutOptions copyOf(PutOptions instance) {
if (instance instanceof ImmutablePutOptions) {
return (ImmutablePutOptions) instance;
}
return ImmutablePutOptions.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutablePutOptions ImmutablePutOptions}.
*
* ImmutablePutOptions.builder()
* .addToQueryParameters|addAllToQueryParameters(String) // {@link PutOptions#toQueryParameters() toQueryParameters} elements
* .putToHeaders|putAllToHeaders(String => String) // {@link PutOptions#toHeaders() toHeaders} mappings
* .cas(Long) // optional {@link PutOptions#getCas() cas}
* .acquire(String) // optional {@link PutOptions#getAcquire() acquire}
* .release(String) // optional {@link PutOptions#getRelease() release}
* .dc(String) // optional {@link PutOptions#getDc() dc}
* .token(String) // optional {@link PutOptions#getToken() token}
* .build();
*
* @return A new ImmutablePutOptions builder
*/
public static ImmutablePutOptions.Builder builder() {
return new ImmutablePutOptions.Builder();
}
/**
* Builds instances of type {@link ImmutablePutOptions ImmutablePutOptions}.
* 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 = "PutOptions", generator = "Immutables")
public static final class Builder {
private ImmutableList.Builder toQueryParameters = ImmutableList.builder();
private ImmutableMap.Builder toHeaders = ImmutableMap.builder();
private @Nullable Long cas;
private @Nullable String acquire;
private @Nullable String release;
private @Nullable String dc;
private @Nullable String token;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code org.kiwiproject.consul.option.ParamAdder} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(ParamAdder instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code org.kiwiproject.consul.option.PutOptions} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(PutOptions instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
private void from(short _unused, Object object) {
if (object instanceof ParamAdder) {
ParamAdder instance = (ParamAdder) object;
addAllToQueryParameters(instance.toQueryParameters());
putAllToHeaders(instance.toHeaders());
}
if (object instanceof PutOptions) {
PutOptions instance = (PutOptions) object;
Optional casOptional = instance.getCas();
if (casOptional.isPresent()) {
cas(casOptional);
}
Optional acquireOptional = instance.getAcquire();
if (acquireOptional.isPresent()) {
acquire(acquireOptional);
}
Optional releaseOptional = instance.getRelease();
if (releaseOptional.isPresent()) {
release(releaseOptional);
}
Optional tokenOptional = instance.getToken();
if (tokenOptional.isPresent()) {
token(tokenOptional);
}
Optional dcOptional = instance.getDc();
if (dcOptional.isPresent()) {
dc(dcOptional);
}
}
}
/**
* Adds one element to {@link PutOptions#toQueryParameters() toQueryParameters} list.
* @param element A toQueryParameters element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addToQueryParameters(String element) {
this.toQueryParameters.add(element);
return this;
}
/**
* Adds elements to {@link PutOptions#toQueryParameters() toQueryParameters} list.
* @param elements An array of toQueryParameters elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addToQueryParameters(String... elements) {
this.toQueryParameters.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link PutOptions#toQueryParameters() toQueryParameters} list.
* @param elements An iterable of toQueryParameters elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder toQueryParameters(Iterable elements) {
this.toQueryParameters = ImmutableList.builder();
return addAllToQueryParameters(elements);
}
/**
* Adds elements to {@link PutOptions#toQueryParameters() toQueryParameters} list.
* @param elements An iterable of toQueryParameters elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllToQueryParameters(Iterable elements) {
this.toQueryParameters.addAll(elements);
return this;
}
/**
* Put one entry to the {@link PutOptions#toHeaders() toHeaders} map.
* @param key The key in the toHeaders map
* @param value The associated value in the toHeaders map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putToHeaders(String key, String value) {
this.toHeaders.put(key, value);
return this;
}
/**
* Put one entry to the {@link PutOptions#toHeaders() toHeaders} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putToHeaders(Map.Entry entry) {
this.toHeaders.put(entry);
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link PutOptions#toHeaders() toHeaders} map. Nulls are not permitted
* @param entries The entries that will be added to the toHeaders map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder toHeaders(Map entries) {
this.toHeaders = ImmutableMap.builder();
return putAllToHeaders(entries);
}
/**
* Put all mappings from the specified map as entries to {@link PutOptions#toHeaders() toHeaders} map. Nulls are not permitted
* @param entries The entries that will be added to the toHeaders map
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder putAllToHeaders(Map entries) {
this.toHeaders.putAll(entries);
return this;
}
/**
* Initializes the optional value {@link PutOptions#getCas() cas} to cas.
* @param cas The value for cas
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder cas(long cas) {
this.cas = cas;
return this;
}
/**
* Initializes the optional value {@link PutOptions#getCas() cas} to cas.
* @param cas The value for cas
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder cas(Optional cas) {
this.cas = cas.orElse(null);
return this;
}
/**
* Initializes the optional value {@link PutOptions#getAcquire() acquire} to acquire.
* @param acquire The value for acquire
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder acquire(String acquire) {
this.acquire = Objects.requireNonNull(acquire, "acquire");
return this;
}
/**
* Initializes the optional value {@link PutOptions#getAcquire() acquire} to acquire.
* @param acquire The value for acquire
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder acquire(Optional acquire) {
this.acquire = acquire.orElse(null);
return this;
}
/**
* Initializes the optional value {@link PutOptions#getRelease() release} to release.
* @param release The value for release
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder release(String release) {
this.release = Objects.requireNonNull(release, "release");
return this;
}
/**
* Initializes the optional value {@link PutOptions#getRelease() release} to release.
* @param release The value for release
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder release(Optional release) {
this.release = release.orElse(null);
return this;
}
/**
* Initializes the optional value {@link PutOptions#getDc() dc} to dc.
* @param dc The value for dc
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder dc(String dc) {
this.dc = Objects.requireNonNull(dc, "dc");
return this;
}
/**
* Initializes the optional value {@link PutOptions#getDc() dc} to dc.
* @param dc The value for dc
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder dc(Optional dc) {
this.dc = dc.orElse(null);
return this;
}
/**
* Initializes the optional value {@link PutOptions#getToken() token} to token.
* @param token The value for token
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder token(String token) {
this.token = Objects.requireNonNull(token, "token");
return this;
}
/**
* Initializes the optional value {@link PutOptions#getToken() token} to token.
* @param token The value for token
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder token(Optional token) {
this.token = token.orElse(null);
return this;
}
/**
* Builds a new {@link ImmutablePutOptions ImmutablePutOptions}.
* @return An immutable instance of PutOptions
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutablePutOptions build() {
return new ImmutablePutOptions(toQueryParameters.build(), toHeaders.build(), cas, acquire, release, dc, token);
}
}
}