org.cloudfoundry.client.lib.domain.ImmutableCloudRoute Maven / Gradle / Ivy
Show all versions of cloudfoundry-client-lib Show documentation
package org.cloudfoundry.client.lib.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 java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.cloudfoundry.client.lib.domain.annotation.Nullable;
import org.cloudfoundry.client.v3.Metadata;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link CloudRoute}.
*
* Use the builder to create immutable instances:
* {@code ImmutableCloudRoute.builder()}.
*/
@Generated(from = "CloudRoute", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutableCloudRoute extends CloudRoute {
private final @Nullable CloudMetadata metadata;
private final @Nullable Metadata v3Metadata;
private final int appsUsingRoute;
private final boolean hasServiceUsingRoute;
private final @Nullable CloudDomain domain;
private final @Nullable String host;
private final @Nullable String path;
private ImmutableCloudRoute(ImmutableCloudRoute.Builder builder) {
this.metadata = builder.metadata;
this.v3Metadata = builder.v3Metadata;
this.domain = builder.domain;
this.host = builder.host;
this.path = builder.path;
if (builder.appsUsingRouteIsSet()) {
initShim.appsUsingRoute(builder.appsUsingRoute);
}
if (builder.hasServiceUsingRouteIsSet()) {
initShim.hasServiceUsingRoute(builder.hasServiceUsingRoute);
}
this.appsUsingRoute = initShim.getAppsUsingRoute();
this.hasServiceUsingRoute = initShim.hasServiceUsingRoute();
this.initShim = null;
}
private ImmutableCloudRoute(
@Nullable CloudMetadata metadata,
@Nullable Metadata v3Metadata,
int appsUsingRoute,
boolean hasServiceUsingRoute,
@Nullable CloudDomain domain,
@Nullable String host,
@Nullable String path) {
this.metadata = metadata;
this.v3Metadata = v3Metadata;
this.appsUsingRoute = appsUsingRoute;
this.hasServiceUsingRoute = hasServiceUsingRoute;
this.domain = domain;
this.host = host;
this.path = path;
this.initShim = null;
}
private static final byte STAGE_INITIALIZING = -1;
private static final byte STAGE_UNINITIALIZED = 0;
private static final byte STAGE_INITIALIZED = 1;
private transient volatile InitShim initShim = new InitShim();
@Generated(from = "CloudRoute", generator = "Immutables")
private final class InitShim {
private byte appsUsingRouteBuildStage = STAGE_UNINITIALIZED;
private int appsUsingRoute;
int getAppsUsingRoute() {
if (appsUsingRouteBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (appsUsingRouteBuildStage == STAGE_UNINITIALIZED) {
appsUsingRouteBuildStage = STAGE_INITIALIZING;
this.appsUsingRoute = ImmutableCloudRoute.super.getAppsUsingRoute();
appsUsingRouteBuildStage = STAGE_INITIALIZED;
}
return this.appsUsingRoute;
}
void appsUsingRoute(int appsUsingRoute) {
this.appsUsingRoute = appsUsingRoute;
appsUsingRouteBuildStage = STAGE_INITIALIZED;
}
private byte hasServiceUsingRouteBuildStage = STAGE_UNINITIALIZED;
private boolean hasServiceUsingRoute;
boolean hasServiceUsingRoute() {
if (hasServiceUsingRouteBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (hasServiceUsingRouteBuildStage == STAGE_UNINITIALIZED) {
hasServiceUsingRouteBuildStage = STAGE_INITIALIZING;
this.hasServiceUsingRoute = ImmutableCloudRoute.super.hasServiceUsingRoute();
hasServiceUsingRouteBuildStage = STAGE_INITIALIZED;
}
return this.hasServiceUsingRoute;
}
void hasServiceUsingRoute(boolean hasServiceUsingRoute) {
this.hasServiceUsingRoute = hasServiceUsingRoute;
hasServiceUsingRouteBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (appsUsingRouteBuildStage == STAGE_INITIALIZING) attributes.add("appsUsingRoute");
if (hasServiceUsingRouteBuildStage == STAGE_INITIALIZING) attributes.add("hasServiceUsingRoute");
return "Cannot build CloudRoute, attribute initializers form cycle " + attributes;
}
}
/**
* @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 appsUsingRoute} attribute
*/
@JsonProperty("appsUsingRoute")
@Override
public int getAppsUsingRoute() {
InitShim shim = this.initShim;
return shim != null
? shim.getAppsUsingRoute()
: this.appsUsingRoute;
}
/**
* @return The value of the {@code hasServiceUsingRoute} attribute
*/
@JsonProperty("hasServiceUsingRoute")
@Override
public boolean hasServiceUsingRoute() {
InitShim shim = this.initShim;
return shim != null
? shim.hasServiceUsingRoute()
: this.hasServiceUsingRoute;
}
/**
* @return The value of the {@code domain} attribute
*/
@JsonProperty("domain")
@Override
public @Nullable CloudDomain getDomain() {
return domain;
}
/**
* @return The value of the {@code host} attribute
*/
@JsonProperty("host")
@Override
public @Nullable String getHost() {
return host;
}
/**
* @return The value of the {@code path} attribute
*/
@JsonProperty("path")
@Override
public @Nullable String getPath() {
return path;
}
/**
* Copy the current immutable object by setting a value for the {@link CloudRoute#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 ImmutableCloudRoute withMetadata(@Nullable CloudMetadata value) {
if (this.metadata == value) return this;
return new ImmutableCloudRoute(
value,
this.v3Metadata,
this.appsUsingRoute,
this.hasServiceUsingRoute,
this.domain,
this.host,
this.path);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudRoute#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 ImmutableCloudRoute withV3Metadata(@Nullable Metadata value) {
if (this.v3Metadata == value) return this;
return new ImmutableCloudRoute(
this.metadata,
value,
this.appsUsingRoute,
this.hasServiceUsingRoute,
this.domain,
this.host,
this.path);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudRoute#getAppsUsingRoute() appsUsingRoute} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for appsUsingRoute
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudRoute withAppsUsingRoute(int value) {
if (this.appsUsingRoute == value) return this;
return new ImmutableCloudRoute(
this.metadata,
this.v3Metadata,
value,
this.hasServiceUsingRoute,
this.domain,
this.host,
this.path);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudRoute#hasServiceUsingRoute() hasServiceUsingRoute} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for hasServiceUsingRoute
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudRoute withHasServiceUsingRoute(boolean value) {
if (this.hasServiceUsingRoute == value) return this;
return new ImmutableCloudRoute(this.metadata, this.v3Metadata, this.appsUsingRoute, value, this.domain, this.host, this.path);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudRoute#getDomain() domain} 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 domain (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudRoute withDomain(@Nullable CloudDomain value) {
if (this.domain == value) return this;
return new ImmutableCloudRoute(
this.metadata,
this.v3Metadata,
this.appsUsingRoute,
this.hasServiceUsingRoute,
value,
this.host,
this.path);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudRoute#getHost() host} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for host (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudRoute withHost(@Nullable String value) {
if (Objects.equals(this.host, value)) return this;
return new ImmutableCloudRoute(
this.metadata,
this.v3Metadata,
this.appsUsingRoute,
this.hasServiceUsingRoute,
this.domain,
value,
this.path);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudRoute#getPath() path} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for path (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudRoute withPath(@Nullable String value) {
if (Objects.equals(this.path, value)) return this;
return new ImmutableCloudRoute(
this.metadata,
this.v3Metadata,
this.appsUsingRoute,
this.hasServiceUsingRoute,
this.domain,
this.host,
value);
}
/**
* This instance is equal to all instances of {@code ImmutableCloudRoute} 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 ImmutableCloudRoute
&& equalTo((ImmutableCloudRoute) another);
}
private boolean equalTo(ImmutableCloudRoute another) {
return Objects.equals(metadata, another.metadata)
&& Objects.equals(v3Metadata, another.v3Metadata)
&& appsUsingRoute == another.appsUsingRoute
&& hasServiceUsingRoute == another.hasServiceUsingRoute
&& Objects.equals(domain, another.domain)
&& Objects.equals(host, another.host)
&& Objects.equals(path, another.path);
}
/**
* Computes a hash code from attributes: {@code metadata}, {@code v3Metadata}, {@code appsUsingRoute}, {@code hasServiceUsingRoute}, {@code domain}, {@code host}, {@code path}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(metadata);
h += (h << 5) + Objects.hashCode(v3Metadata);
h += (h << 5) + appsUsingRoute;
h += (h << 5) + Boolean.hashCode(hasServiceUsingRoute);
h += (h << 5) + Objects.hashCode(domain);
h += (h << 5) + Objects.hashCode(host);
h += (h << 5) + Objects.hashCode(path);
return h;
}
/**
* Prints the immutable value {@code CloudRoute} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "CloudRoute{"
+ "metadata=" + metadata
+ ", v3Metadata=" + v3Metadata
+ ", appsUsingRoute=" + appsUsingRoute
+ ", hasServiceUsingRoute=" + hasServiceUsingRoute
+ ", domain=" + domain
+ ", host=" + host
+ ", path=" + path
+ "}";
}
/**
* 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 = "CloudRoute", generator = "Immutables")
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends CloudRoute {
CloudMetadata metadata;
Metadata v3Metadata;
int appsUsingRoute;
boolean appsUsingRouteIsSet;
boolean hasServiceUsingRoute;
boolean hasServiceUsingRouteIsSet;
CloudDomain domain;
String host;
String path;
@JsonProperty("metadata")
public void setMetadata(@Nullable CloudMetadata metadata) {
this.metadata = metadata;
}
@JsonProperty("v3Metadata")
public void setV3Metadata(@Nullable Metadata v3Metadata) {
this.v3Metadata = v3Metadata;
}
@JsonProperty("appsUsingRoute")
public void setAppsUsingRoute(int appsUsingRoute) {
this.appsUsingRoute = appsUsingRoute;
this.appsUsingRouteIsSet = true;
}
@JsonProperty("hasServiceUsingRoute")
public void setHasServiceUsingRoute(boolean hasServiceUsingRoute) {
this.hasServiceUsingRoute = hasServiceUsingRoute;
this.hasServiceUsingRouteIsSet = true;
}
@JsonProperty("domain")
public void setDomain(@Nullable CloudDomain domain) {
this.domain = domain;
}
@JsonProperty("host")
public void setHost(@Nullable String host) {
this.host = host;
}
@JsonProperty("path")
public void setPath(@Nullable String path) {
this.path = path;
}
@Override
public CloudMetadata getMetadata() { throw new UnsupportedOperationException(); }
@Override
public Metadata getV3Metadata() { throw new UnsupportedOperationException(); }
@Override
public int getAppsUsingRoute() { throw new UnsupportedOperationException(); }
@Override
public boolean hasServiceUsingRoute() { throw new UnsupportedOperationException(); }
@Override
public CloudDomain getDomain() { throw new UnsupportedOperationException(); }
@Override
public String getHost() { throw new UnsupportedOperationException(); }
@Override
public String getPath() { 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 ImmutableCloudRoute fromJson(Json json) {
ImmutableCloudRoute.Builder builder = ImmutableCloudRoute.builder();
if (json.metadata != null) {
builder.metadata(json.metadata);
}
if (json.v3Metadata != null) {
builder.v3Metadata(json.v3Metadata);
}
if (json.appsUsingRouteIsSet) {
builder.appsUsingRoute(json.appsUsingRoute);
}
if (json.hasServiceUsingRouteIsSet) {
builder.hasServiceUsingRoute(json.hasServiceUsingRoute);
}
if (json.domain != null) {
builder.domain(json.domain);
}
if (json.host != null) {
builder.host(json.host);
}
if (json.path != null) {
builder.path(json.path);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link CloudRoute} 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 CloudRoute instance
*/
public static ImmutableCloudRoute copyOf(CloudRoute instance) {
if (instance instanceof ImmutableCloudRoute) {
return (ImmutableCloudRoute) instance;
}
return ImmutableCloudRoute.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableCloudRoute ImmutableCloudRoute}.
*
* ImmutableCloudRoute.builder()
* .metadata(org.cloudfoundry.client.lib.domain.CloudMetadata | null) // nullable {@link CloudRoute#getMetadata() metadata}
* .v3Metadata(org.cloudfoundry.client.v3.Metadata | null) // nullable {@link CloudRoute#getV3Metadata() v3Metadata}
* .appsUsingRoute(int) // optional {@link CloudRoute#getAppsUsingRoute() appsUsingRoute}
* .hasServiceUsingRoute(boolean) // optional {@link CloudRoute#hasServiceUsingRoute() hasServiceUsingRoute}
* .domain(org.cloudfoundry.client.lib.domain.CloudDomain | null) // nullable {@link CloudRoute#getDomain() domain}
* .host(String | null) // nullable {@link CloudRoute#getHost() host}
* .path(String | null) // nullable {@link CloudRoute#getPath() path}
* .build();
*
* @return A new ImmutableCloudRoute builder
*/
public static ImmutableCloudRoute.Builder builder() {
return new ImmutableCloudRoute.Builder();
}
/**
* Builds instances of type {@link ImmutableCloudRoute ImmutableCloudRoute}.
* 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 = "CloudRoute", generator = "Immutables")
public static final class Builder {
private static final long OPT_BIT_APPS_USING_ROUTE = 0x1L;
private static final long OPT_BIT_HAS_SERVICE_USING_ROUTE = 0x2L;
private long optBits;
private CloudMetadata metadata;
private Metadata v3Metadata;
private int appsUsingRoute;
private boolean hasServiceUsingRoute;
private CloudDomain domain;
private String host;
private String path;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code org.cloudfoundry.client.lib.domain.CloudRoute} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(CloudRoute instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code org.cloudfoundry.client.lib.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((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof CloudRoute) {
CloudRoute instance = (CloudRoute) object;
@Nullable String hostValue = instance.getHost();
if (hostValue != null) {
host(hostValue);
}
@Nullable String pathValue = instance.getPath();
if (pathValue != null) {
path(pathValue);
}
appsUsingRoute(instance.getAppsUsingRoute());
hasServiceUsingRoute(instance.hasServiceUsingRoute());
@Nullable CloudDomain domainValue = instance.getDomain();
if (domainValue != null) {
domain(domainValue);
}
}
if (object instanceof CloudEntity) {
CloudEntity instance = (CloudEntity) object;
@Nullable Metadata v3MetadataValue = instance.getV3Metadata();
if (v3MetadataValue != null) {
v3Metadata(v3MetadataValue);
}
@Nullable CloudMetadata metadataValue = instance.getMetadata();
if (metadataValue != null) {
metadata(metadataValue);
}
}
}
/**
* Initializes the value for the {@link CloudRoute#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 CloudRoute#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 CloudRoute#getAppsUsingRoute() appsUsingRoute} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link CloudRoute#getAppsUsingRoute() appsUsingRoute}.
* @param appsUsingRoute The value for appsUsingRoute
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("appsUsingRoute")
public final Builder appsUsingRoute(int appsUsingRoute) {
this.appsUsingRoute = appsUsingRoute;
optBits |= OPT_BIT_APPS_USING_ROUTE;
return this;
}
/**
* Initializes the value for the {@link CloudRoute#hasServiceUsingRoute() hasServiceUsingRoute} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link CloudRoute#hasServiceUsingRoute() hasServiceUsingRoute}.
* @param hasServiceUsingRoute The value for hasServiceUsingRoute
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("hasServiceUsingRoute")
public final Builder hasServiceUsingRoute(boolean hasServiceUsingRoute) {
this.hasServiceUsingRoute = hasServiceUsingRoute;
optBits |= OPT_BIT_HAS_SERVICE_USING_ROUTE;
return this;
}
/**
* Initializes the value for the {@link CloudRoute#getDomain() domain} attribute.
* @param domain The value for domain (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("domain")
public final Builder domain(@Nullable CloudDomain domain) {
this.domain = domain;
return this;
}
/**
* Initializes the value for the {@link CloudRoute#getHost() host} attribute.
* @param host The value for host (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("host")
public final Builder host(@Nullable String host) {
this.host = host;
return this;
}
/**
* Initializes the value for the {@link CloudRoute#getPath() path} attribute.
* @param path The value for path (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("path")
public final Builder path(@Nullable String path) {
this.path = path;
return this;
}
/**
* Builds a new {@link ImmutableCloudRoute ImmutableCloudRoute}.
* @return An immutable instance of CloudRoute
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableCloudRoute build() {
return new ImmutableCloudRoute(this);
}
private boolean appsUsingRouteIsSet() {
return (optBits & OPT_BIT_APPS_USING_ROUTE) != 0;
}
private boolean hasServiceUsingRouteIsSet() {
return (optBits & OPT_BIT_HAS_SERVICE_USING_ROUTE) != 0;
}
}
}