
com.sap.cloudfoundry.client.facade.domain.ImmutableRouteDestination Maven / Gradle / Ivy
Show all versions of cloudfoundry-client-facade Show documentation
package com.sap.cloudfoundry.client.facade.domain;
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.sap.cloudfoundry.client.facade.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import org.cloudfoundry.client.v3.Metadata;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link RouteDestination}.
*
* Use the builder to create immutable instances:
* {@code ImmutableRouteDestination.builder()}.
*/
@Generated(from = "RouteDestination", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutableRouteDestination
extends RouteDestination {
private final @Nullable String name;
private final @Nullable CloudMetadata metadata;
private final @Nullable Metadata v3Metadata;
private final UUID applicationGuid;
private final @Nullable Integer port;
private final @Nullable Integer weight;
private final String protocol;
private ImmutableRouteDestination(
@Nullable String name,
@Nullable CloudMetadata metadata,
@Nullable Metadata v3Metadata,
UUID applicationGuid,
@Nullable Integer port,
@Nullable Integer weight,
String protocol) {
this.name = name;
this.metadata = metadata;
this.v3Metadata = v3Metadata;
this.applicationGuid = applicationGuid;
this.port = port;
this.weight = weight;
this.protocol = protocol;
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public @Nullable String getName() {
return name;
}
/**
* @return The value of the {@code metadata} attribute
*/
@JsonProperty("metadata")
@Override
public @Nullable CloudMetadata getMetadata() {
return metadata;
}
/**
* @return The value of the {@code v3Metadata} attribute
*/
@JsonProperty("v3Metadata")
@Override
public @Nullable Metadata getV3Metadata() {
return v3Metadata;
}
/**
* @return The value of the {@code applicationGuid} attribute
*/
@JsonProperty("applicationGuid")
@Override
public UUID getApplicationGuid() {
return applicationGuid;
}
/**
* @return The value of the {@code port} attribute
*/
@JsonProperty("port")
@Override
public @Nullable Integer getPort() {
return port;
}
/**
* @return The value of the {@code weight} attribute
*/
@JsonProperty("weight")
@Override
public @Nullable Integer getWeight() {
return weight;
}
/**
* @return The value of the {@code protocol} attribute
*/
@JsonProperty("protocol")
@Override
public String getProtocol() {
return protocol;
}
/**
* Copy the current immutable object by setting a value for the {@link RouteDestination#getName() name} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for name (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableRouteDestination withName(@Nullable String value) {
if (Objects.equals(this.name, value)) return this;
return new ImmutableRouteDestination(
value,
this.metadata,
this.v3Metadata,
this.applicationGuid,
this.port,
this.weight,
this.protocol);
}
/**
* Copy the current immutable object by setting a value for the {@link RouteDestination#getMetadata() metadata} 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 metadata (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableRouteDestination withMetadata(@Nullable CloudMetadata value) {
if (this.metadata == value) return this;
return new ImmutableRouteDestination(this.name, value, this.v3Metadata, this.applicationGuid, this.port, this.weight, this.protocol);
}
/**
* Copy the current immutable object by setting a value for the {@link RouteDestination#getV3Metadata() v3Metadata} 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 v3Metadata (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableRouteDestination withV3Metadata(@Nullable Metadata value) {
if (this.v3Metadata == value) return this;
return new ImmutableRouteDestination(this.name, this.metadata, value, this.applicationGuid, this.port, this.weight, this.protocol);
}
/**
* Copy the current immutable object by setting a value for the {@link RouteDestination#getApplicationGuid() applicationGuid} 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 applicationGuid
* @return A modified copy of the {@code this} object
*/
public final ImmutableRouteDestination withApplicationGuid(UUID value) {
if (this.applicationGuid == value) return this;
UUID newValue = Objects.requireNonNull(value, "applicationGuid");
return new ImmutableRouteDestination(this.name, this.metadata, this.v3Metadata, newValue, this.port, this.weight, this.protocol);
}
/**
* Copy the current immutable object by setting a value for the {@link RouteDestination#getPort() port} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for port (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableRouteDestination withPort(@Nullable Integer value) {
if (Objects.equals(this.port, value)) return this;
return new ImmutableRouteDestination(
this.name,
this.metadata,
this.v3Metadata,
this.applicationGuid,
value,
this.weight,
this.protocol);
}
/**
* Copy the current immutable object by setting a value for the {@link RouteDestination#getWeight() weight} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for weight (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableRouteDestination withWeight(@Nullable Integer value) {
if (Objects.equals(this.weight, value)) return this;
return new ImmutableRouteDestination(
this.name,
this.metadata,
this.v3Metadata,
this.applicationGuid,
this.port,
value,
this.protocol);
}
/**
* Copy the current immutable object by setting a value for the {@link RouteDestination#getProtocol() protocol} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for protocol
* @return A modified copy of the {@code this} object
*/
public final ImmutableRouteDestination withProtocol(String value) {
String newValue = Objects.requireNonNull(value, "protocol");
if (this.protocol.equals(newValue)) return this;
return new ImmutableRouteDestination(
this.name,
this.metadata,
this.v3Metadata,
this.applicationGuid,
this.port,
this.weight,
newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableRouteDestination} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(Object another) {
if (this == another) return true;
return another instanceof ImmutableRouteDestination
&& equalTo(0, (ImmutableRouteDestination) another);
}
private boolean equalTo(int synthetic, ImmutableRouteDestination another) {
return Objects.equals(name, another.name)
&& Objects.equals(metadata, another.metadata)
&& Objects.equals(v3Metadata, another.v3Metadata)
&& applicationGuid.equals(another.applicationGuid)
&& Objects.equals(port, another.port)
&& Objects.equals(weight, another.weight)
&& protocol.equals(another.protocol);
}
/**
* Computes a hash code from attributes: {@code name}, {@code metadata}, {@code v3Metadata}, {@code applicationGuid}, {@code port}, {@code weight}, {@code protocol}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + Objects.hashCode(metadata);
h += (h << 5) + Objects.hashCode(v3Metadata);
h += (h << 5) + applicationGuid.hashCode();
h += (h << 5) + Objects.hashCode(port);
h += (h << 5) + Objects.hashCode(weight);
h += (h << 5) + protocol.hashCode();
return h;
}
/**
* Prints the immutable value {@code RouteDestination} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "RouteDestination{"
+ "name=" + name
+ ", metadata=" + metadata
+ ", v3Metadata=" + v3Metadata
+ ", applicationGuid=" + applicationGuid
+ ", port=" + port
+ ", weight=" + weight
+ ", protocol=" + protocol
+ "}";
}
/**
* 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 = "RouteDestination", generator = "Immutables")
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends RouteDestination {
String name;
CloudMetadata metadata;
Metadata v3Metadata;
UUID applicationGuid;
Integer port;
Integer weight;
String protocol;
@JsonProperty("name")
public void setName(@Nullable String name) {
this.name = name;
}
@JsonProperty("metadata")
public void setMetadata(@Nullable CloudMetadata metadata) {
this.metadata = metadata;
}
@JsonProperty("v3Metadata")
public void setV3Metadata(@Nullable Metadata v3Metadata) {
this.v3Metadata = v3Metadata;
}
@JsonProperty("applicationGuid")
public void setApplicationGuid(UUID applicationGuid) {
this.applicationGuid = applicationGuid;
}
@JsonProperty("port")
public void setPort(@Nullable Integer port) {
this.port = port;
}
@JsonProperty("weight")
public void setWeight(@Nullable Integer weight) {
this.weight = weight;
}
@JsonProperty("protocol")
public void setProtocol(String protocol) {
this.protocol = protocol;
}
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public CloudMetadata getMetadata() { throw new UnsupportedOperationException(); }
@Override
public Metadata getV3Metadata() { throw new UnsupportedOperationException(); }
@Override
public UUID getApplicationGuid() { throw new UnsupportedOperationException(); }
@Override
public Integer getPort() { throw new UnsupportedOperationException(); }
@Override
public Integer getWeight() { throw new UnsupportedOperationException(); }
@Override
public String getProtocol() { 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 ImmutableRouteDestination fromJson(Json json) {
ImmutableRouteDestination.Builder builder = ImmutableRouteDestination.builder();
if (json.name != null) {
builder.name(json.name);
}
if (json.metadata != null) {
builder.metadata(json.metadata);
}
if (json.v3Metadata != null) {
builder.v3Metadata(json.v3Metadata);
}
if (json.applicationGuid != null) {
builder.applicationGuid(json.applicationGuid);
}
if (json.port != null) {
builder.port(json.port);
}
if (json.weight != null) {
builder.weight(json.weight);
}
if (json.protocol != null) {
builder.protocol(json.protocol);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link RouteDestination} 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 RouteDestination instance
*/
public static ImmutableRouteDestination copyOf(RouteDestination instance) {
if (instance instanceof ImmutableRouteDestination) {
return (ImmutableRouteDestination) instance;
}
return ImmutableRouteDestination.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableRouteDestination ImmutableRouteDestination}.
*
* ImmutableRouteDestination.builder()
* .name(String | null) // nullable {@link RouteDestination#getName() name}
* .metadata(com.sap.cloudfoundry.client.facade.domain.CloudMetadata | null) // nullable {@link RouteDestination#getMetadata() metadata}
* .v3Metadata(org.cloudfoundry.client.v3.Metadata | null) // nullable {@link RouteDestination#getV3Metadata() v3Metadata}
* .applicationGuid(UUID) // required {@link RouteDestination#getApplicationGuid() applicationGuid}
* .port(Integer | null) // nullable {@link RouteDestination#getPort() port}
* .weight(Integer | null) // nullable {@link RouteDestination#getWeight() weight}
* .protocol(String) // required {@link RouteDestination#getProtocol() protocol}
* .build();
*
* @return A new ImmutableRouteDestination builder
*/
public static ImmutableRouteDestination.Builder builder() {
return new ImmutableRouteDestination.Builder();
}
/**
* Builds instances of type {@link ImmutableRouteDestination ImmutableRouteDestination}.
* 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 = "RouteDestination", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_APPLICATION_GUID = 0x1L;
private static final long INIT_BIT_PROTOCOL = 0x2L;
private long initBits = 0x3L;
private String name;
private CloudMetadata metadata;
private Metadata v3Metadata;
private UUID applicationGuid;
private Integer port;
private Integer weight;
private String protocol;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.sap.cloudfoundry.client.facade.domain.RouteDestination} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(RouteDestination instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.sap.cloudfoundry.client.facade.domain.CloudEntity} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(CloudEntity instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
private void from(short _unused, Object object) {
long bits = 0;
if (object instanceof RouteDestination) {
RouteDestination instance = (RouteDestination) object;
if ((bits & 0x1L) == 0) {
@Nullable CloudMetadata metadataValue = instance.getMetadata();
if (metadataValue != null) {
metadata(metadataValue);
}
bits |= 0x1L;
}
this.protocol(instance.getProtocol());
@Nullable Integer portValue = instance.getPort();
if (portValue != null) {
port(portValue);
}
if ((bits & 0x2L) == 0) {
@Nullable Metadata v3MetadataValue = instance.getV3Metadata();
if (v3MetadataValue != null) {
v3Metadata(v3MetadataValue);
}
bits |= 0x2L;
}
if ((bits & 0x4L) == 0) {
@Nullable String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
bits |= 0x4L;
}
@Nullable Integer weightValue = instance.getWeight();
if (weightValue != null) {
weight(weightValue);
}
this.applicationGuid(instance.getApplicationGuid());
}
if (object instanceof CloudEntity) {
CloudEntity instance = (CloudEntity) object;
if ((bits & 0x2L) == 0) {
@Nullable Metadata v3MetadataValue = instance.getV3Metadata();
if (v3MetadataValue != null) {
v3Metadata(v3MetadataValue);
}
bits |= 0x2L;
}
if ((bits & 0x4L) == 0) {
@Nullable String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
bits |= 0x4L;
}
if ((bits & 0x1L) == 0) {
@Nullable CloudMetadata metadataValue = instance.getMetadata();
if (metadataValue != null) {
metadata(metadataValue);
}
bits |= 0x1L;
}
}
}
/**
* Initializes the value for the {@link RouteDestination#getName() name} attribute.
* @param name The value for name (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("name")
public final Builder name(@Nullable String name) {
this.name = name;
return this;
}
/**
* Initializes the value for the {@link RouteDestination#getMetadata() metadata} attribute.
* @param metadata The value for metadata (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("metadata")
public final Builder metadata(@Nullable CloudMetadata metadata) {
this.metadata = metadata;
return this;
}
/**
* Initializes the value for the {@link RouteDestination#getV3Metadata() v3Metadata} attribute.
* @param v3Metadata The value for v3Metadata (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("v3Metadata")
public final Builder v3Metadata(@Nullable Metadata v3Metadata) {
this.v3Metadata = v3Metadata;
return this;
}
/**
* Initializes the value for the {@link RouteDestination#getApplicationGuid() applicationGuid} attribute.
* @param applicationGuid The value for applicationGuid
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("applicationGuid")
public final Builder applicationGuid(UUID applicationGuid) {
this.applicationGuid = Objects.requireNonNull(applicationGuid, "applicationGuid");
initBits &= ~INIT_BIT_APPLICATION_GUID;
return this;
}
/**
* Initializes the value for the {@link RouteDestination#getPort() port} attribute.
* @param port The value for port (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("port")
public final Builder port(@Nullable Integer port) {
this.port = port;
return this;
}
/**
* Initializes the value for the {@link RouteDestination#getWeight() weight} attribute.
* @param weight The value for weight (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("weight")
public final Builder weight(@Nullable Integer weight) {
this.weight = weight;
return this;
}
/**
* Initializes the value for the {@link RouteDestination#getProtocol() protocol} attribute.
* @param protocol The value for protocol
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("protocol")
public final Builder protocol(String protocol) {
this.protocol = Objects.requireNonNull(protocol, "protocol");
initBits &= ~INIT_BIT_PROTOCOL;
return this;
}
/**
* Builds a new {@link ImmutableRouteDestination ImmutableRouteDestination}.
* @return An immutable instance of RouteDestination
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableRouteDestination build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableRouteDestination(name, metadata, v3Metadata, applicationGuid, port, weight, protocol);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_APPLICATION_GUID) != 0) attributes.add("applicationGuid");
if ((initBits & INIT_BIT_PROTOCOL) != 0) attributes.add("protocol");
return "Cannot build RouteDestination, some of required attributes are not set " + attributes;
}
}
}