org.cloudfoundry.client.lib.domain.ImmutableCloudServiceInstance 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.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
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 CloudServiceInstance}.
*
* Use the builder to create immutable instances:
* {@code ImmutableCloudServiceInstance.builder()}.
*/
@Generated(from = "CloudServiceInstance", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutableCloudServiceInstance
extends CloudServiceInstance {
private final @Nullable String name;
private final @Nullable CloudMetadata metadata;
private final @Nullable Metadata v3Metadata;
private final @Nullable String label;
private final @Nullable String plan;
private final @Nullable String provider;
private final @Nullable String broker;
private final @Nullable String version;
private final Map credentials;
private final List tags;
private final @Nullable ServiceInstanceType type;
private final @Nullable ServiceOperation lastOperation;
private ImmutableCloudServiceInstance(
@Nullable String name,
@Nullable CloudMetadata metadata,
@Nullable Metadata v3Metadata,
@Nullable String label,
@Nullable String plan,
@Nullable String provider,
@Nullable String broker,
@Nullable String version,
Map credentials,
List tags,
@Nullable ServiceInstanceType type,
@Nullable ServiceOperation lastOperation) {
this.name = name;
this.metadata = metadata;
this.v3Metadata = v3Metadata;
this.label = label;
this.plan = plan;
this.provider = provider;
this.broker = broker;
this.version = version;
this.credentials = credentials;
this.tags = tags;
this.type = type;
this.lastOperation = lastOperation;
}
/**
* @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 label} attribute
*/
@JsonProperty("label")
@Override
public @Nullable String getLabel() {
return label;
}
/**
* @return The value of the {@code plan} attribute
*/
@JsonProperty("plan")
@Override
public @Nullable String getPlan() {
return plan;
}
/**
* @return The value of the {@code provider} attribute
*/
@JsonProperty("provider")
@Override
public @Nullable String getProvider() {
return provider;
}
/**
* @return The value of the {@code broker} attribute
*/
@JsonProperty("broker")
@Override
public @Nullable String getBroker() {
return broker;
}
/**
* @return The value of the {@code version} attribute
*/
@JsonProperty("version")
@Override
public @Nullable String getVersion() {
return version;
}
/**
* @return The value of the {@code credentials} attribute
*/
@JsonProperty("credentials")
@Override
public Map getCredentials() {
return credentials;
}
/**
* @return The value of the {@code tags} attribute
*/
@JsonProperty("tags")
@Override
public List getTags() {
return tags;
}
/**
* @return The value of the {@code type} attribute
*/
@JsonProperty("type")
@Override
public @Nullable ServiceInstanceType getType() {
return type;
}
/**
* @return The value of the {@code lastOperation} attribute
*/
@JsonProperty("lastOperation")
@Override
public @Nullable ServiceOperation getLastOperation() {
return lastOperation;
}
/**
* Copy the current immutable object by setting a value for the {@link CloudServiceInstance#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 ImmutableCloudServiceInstance withName(@Nullable String value) {
if (Objects.equals(this.name, value)) return this;
return new ImmutableCloudServiceInstance(
value,
this.metadata,
this.v3Metadata,
this.label,
this.plan,
this.provider,
this.broker,
this.version,
this.credentials,
this.tags,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudServiceInstance#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 ImmutableCloudServiceInstance withMetadata(@Nullable CloudMetadata value) {
if (this.metadata == value) return this;
return new ImmutableCloudServiceInstance(
this.name,
value,
this.v3Metadata,
this.label,
this.plan,
this.provider,
this.broker,
this.version,
this.credentials,
this.tags,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudServiceInstance#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 ImmutableCloudServiceInstance withV3Metadata(@Nullable Metadata value) {
if (this.v3Metadata == value) return this;
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
value,
this.label,
this.plan,
this.provider,
this.broker,
this.version,
this.credentials,
this.tags,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudServiceInstance#getLabel() label} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for label (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudServiceInstance withLabel(@Nullable String value) {
if (Objects.equals(this.label, value)) return this;
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
this.v3Metadata,
value,
this.plan,
this.provider,
this.broker,
this.version,
this.credentials,
this.tags,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudServiceInstance#getPlan() plan} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for plan (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudServiceInstance withPlan(@Nullable String value) {
if (Objects.equals(this.plan, value)) return this;
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
this.v3Metadata,
this.label,
value,
this.provider,
this.broker,
this.version,
this.credentials,
this.tags,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudServiceInstance#getProvider() provider} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for provider (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudServiceInstance withProvider(@Nullable String value) {
if (Objects.equals(this.provider, value)) return this;
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
this.v3Metadata,
this.label,
this.plan,
value,
this.broker,
this.version,
this.credentials,
this.tags,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudServiceInstance#getBroker() broker} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for broker (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudServiceInstance withBroker(@Nullable String value) {
if (Objects.equals(this.broker, value)) return this;
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
this.v3Metadata,
this.label,
this.plan,
this.provider,
value,
this.version,
this.credentials,
this.tags,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudServiceInstance#getVersion() version} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for version (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudServiceInstance withVersion(@Nullable String value) {
if (Objects.equals(this.version, value)) return this;
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
this.v3Metadata,
this.label,
this.plan,
this.provider,
this.broker,
value,
this.credentials,
this.tags,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object by replacing the {@link CloudServiceInstance#getCredentials() credentials} 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 credentials map
* @return A modified copy of {@code this} object
*/
public final ImmutableCloudServiceInstance withCredentials(Map entries) {
if (this.credentials == entries) return this;
Map newValue = createUnmodifiableMap(false, false, entries);
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
this.v3Metadata,
this.label,
this.plan,
this.provider,
this.broker,
this.version,
newValue,
this.tags,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object with elements that replace the content of {@link CloudServiceInstance#getTags() tags}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableCloudServiceInstance withTags(String... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
this.v3Metadata,
this.label,
this.plan,
this.provider,
this.broker,
this.version,
this.credentials,
newValue,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object with elements that replace the content of {@link CloudServiceInstance#getTags() tags}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of tags elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableCloudServiceInstance withTags(Iterable elements) {
if (this.tags == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
this.v3Metadata,
this.label,
this.plan,
this.provider,
this.broker,
this.version,
this.credentials,
newValue,
this.type,
this.lastOperation);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudServiceInstance#getType() type} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for type (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudServiceInstance withType(@Nullable ServiceInstanceType value) {
if (this.type == value) return this;
if (Objects.equals(this.type, value)) return this;
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
this.v3Metadata,
this.label,
this.plan,
this.provider,
this.broker,
this.version,
this.credentials,
this.tags,
value,
this.lastOperation);
}
/**
* Copy the current immutable object by setting a value for the {@link CloudServiceInstance#getLastOperation() lastOperation} 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 lastOperation (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCloudServiceInstance withLastOperation(@Nullable ServiceOperation value) {
if (this.lastOperation == value) return this;
return new ImmutableCloudServiceInstance(
this.name,
this.metadata,
this.v3Metadata,
this.label,
this.plan,
this.provider,
this.broker,
this.version,
this.credentials,
this.tags,
this.type,
value);
}
/**
* This instance is equal to all instances of {@code ImmutableCloudServiceInstance} 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 ImmutableCloudServiceInstance
&& equalTo((ImmutableCloudServiceInstance) another);
}
private boolean equalTo(ImmutableCloudServiceInstance another) {
return Objects.equals(name, another.name)
&& Objects.equals(metadata, another.metadata)
&& Objects.equals(v3Metadata, another.v3Metadata)
&& Objects.equals(label, another.label)
&& Objects.equals(plan, another.plan)
&& Objects.equals(provider, another.provider)
&& Objects.equals(broker, another.broker)
&& Objects.equals(version, another.version)
&& credentials.equals(another.credentials)
&& tags.equals(another.tags)
&& Objects.equals(type, another.type)
&& Objects.equals(lastOperation, another.lastOperation);
}
/**
* Computes a hash code from attributes: {@code name}, {@code metadata}, {@code v3Metadata}, {@code label}, {@code plan}, {@code provider}, {@code broker}, {@code version}, {@code credentials}, {@code tags}, {@code type}, {@code lastOperation}.
* @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) + Objects.hashCode(label);
h += (h << 5) + Objects.hashCode(plan);
h += (h << 5) + Objects.hashCode(provider);
h += (h << 5) + Objects.hashCode(broker);
h += (h << 5) + Objects.hashCode(version);
h += (h << 5) + credentials.hashCode();
h += (h << 5) + tags.hashCode();
h += (h << 5) + Objects.hashCode(type);
h += (h << 5) + Objects.hashCode(lastOperation);
return h;
}
/**
* Prints the immutable value {@code CloudServiceInstance} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "CloudServiceInstance{"
+ "name=" + name
+ ", metadata=" + metadata
+ ", v3Metadata=" + v3Metadata
+ ", label=" + label
+ ", plan=" + plan
+ ", provider=" + provider
+ ", broker=" + broker
+ ", version=" + version
+ ", credentials=" + credentials
+ ", tags=" + tags
+ ", type=" + type
+ ", lastOperation=" + lastOperation
+ "}";
}
/**
* 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 = "CloudServiceInstance", generator = "Immutables")
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends CloudServiceInstance {
String name;
CloudMetadata metadata;
Metadata v3Metadata;
String label;
String plan;
String provider;
String broker;
String version;
Map credentials = Collections.emptyMap();
List tags = Collections.emptyList();
ServiceInstanceType type;
ServiceOperation lastOperation;
@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("label")
public void setLabel(@Nullable String label) {
this.label = label;
}
@JsonProperty("plan")
public void setPlan(@Nullable String plan) {
this.plan = plan;
}
@JsonProperty("provider")
public void setProvider(@Nullable String provider) {
this.provider = provider;
}
@JsonProperty("broker")
public void setBroker(@Nullable String broker) {
this.broker = broker;
}
@JsonProperty("version")
public void setVersion(@Nullable String version) {
this.version = version;
}
@JsonProperty("credentials")
public void setCredentials(Map credentials) {
this.credentials = credentials;
}
@JsonProperty("tags")
public void setTags(List tags) {
this.tags = tags;
}
@JsonProperty("type")
public void setType(@Nullable ServiceInstanceType type) {
this.type = type;
}
@JsonProperty("lastOperation")
public void setLastOperation(@Nullable ServiceOperation lastOperation) {
this.lastOperation = lastOperation;
}
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public CloudMetadata getMetadata() { throw new UnsupportedOperationException(); }
@Override
public Metadata getV3Metadata() { throw new UnsupportedOperationException(); }
@Override
public String getLabel() { throw new UnsupportedOperationException(); }
@Override
public String getPlan() { throw new UnsupportedOperationException(); }
@Override
public String getProvider() { throw new UnsupportedOperationException(); }
@Override
public String getBroker() { throw new UnsupportedOperationException(); }
@Override
public String getVersion() { throw new UnsupportedOperationException(); }
@Override
public Map getCredentials() { throw new UnsupportedOperationException(); }
@Override
public List getTags() { throw new UnsupportedOperationException(); }
@Override
public ServiceInstanceType getType() { throw new UnsupportedOperationException(); }
@Override
public ServiceOperation getLastOperation() { 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 ImmutableCloudServiceInstance fromJson(Json json) {
ImmutableCloudServiceInstance.Builder builder = ImmutableCloudServiceInstance.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.label != null) {
builder.label(json.label);
}
if (json.plan != null) {
builder.plan(json.plan);
}
if (json.provider != null) {
builder.provider(json.provider);
}
if (json.broker != null) {
builder.broker(json.broker);
}
if (json.version != null) {
builder.version(json.version);
}
if (json.credentials != null) {
builder.putAllCredentials(json.credentials);
}
if (json.tags != null) {
builder.addAllTags(json.tags);
}
if (json.type != null) {
builder.type(json.type);
}
if (json.lastOperation != null) {
builder.lastOperation(json.lastOperation);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link CloudServiceInstance} 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 CloudServiceInstance instance
*/
public static ImmutableCloudServiceInstance copyOf(CloudServiceInstance instance) {
if (instance instanceof ImmutableCloudServiceInstance) {
return (ImmutableCloudServiceInstance) instance;
}
return ImmutableCloudServiceInstance.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableCloudServiceInstance ImmutableCloudServiceInstance}.
*
* ImmutableCloudServiceInstance.builder()
* .name(String | null) // nullable {@link CloudServiceInstance#getName() name}
* .metadata(org.cloudfoundry.client.lib.domain.CloudMetadata | null) // nullable {@link CloudServiceInstance#getMetadata() metadata}
* .v3Metadata(org.cloudfoundry.client.v3.Metadata | null) // nullable {@link CloudServiceInstance#getV3Metadata() v3Metadata}
* .label(String | null) // nullable {@link CloudServiceInstance#getLabel() label}
* .plan(String | null) // nullable {@link CloudServiceInstance#getPlan() plan}
* .provider(String | null) // nullable {@link CloudServiceInstance#getProvider() provider}
* .broker(String | null) // nullable {@link CloudServiceInstance#getBroker() broker}
* .version(String | null) // nullable {@link CloudServiceInstance#getVersion() version}
* .putCredential|putAllCredentials(String => Object) // {@link CloudServiceInstance#getCredentials() credentials} mappings
* .addTag|addAllTags(String) // {@link CloudServiceInstance#getTags() tags} elements
* .type(org.cloudfoundry.client.lib.domain.ServiceInstanceType | null) // nullable {@link CloudServiceInstance#getType() type}
* .lastOperation(org.cloudfoundry.client.lib.domain.ServiceOperation | null) // nullable {@link CloudServiceInstance#getLastOperation() lastOperation}
* .build();
*
* @return A new ImmutableCloudServiceInstance builder
*/
public static ImmutableCloudServiceInstance.Builder builder() {
return new ImmutableCloudServiceInstance.Builder();
}
/**
* Builds instances of type {@link ImmutableCloudServiceInstance ImmutableCloudServiceInstance}.
* 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 = "CloudServiceInstance", generator = "Immutables")
public static final class Builder {
private String name;
private CloudMetadata metadata;
private Metadata v3Metadata;
private String label;
private String plan;
private String provider;
private String broker;
private String version;
private Map credentials = new LinkedHashMap();
private List tags = new ArrayList();
private ServiceInstanceType type;
private ServiceOperation lastOperation;
private Builder() {
}
/**
* 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;
}
/**
* Fill a builder with attribute values from the provided {@code org.cloudfoundry.client.lib.domain.CloudServiceInstance} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(CloudServiceInstance instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof CloudEntity) {
CloudEntity instance = (CloudEntity) object;
@Nullable String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
@Nullable Metadata v3MetadataValue = instance.getV3Metadata();
if (v3MetadataValue != null) {
v3Metadata(v3MetadataValue);
}
@Nullable CloudMetadata metadataValue = instance.getMetadata();
if (metadataValue != null) {
metadata(metadataValue);
}
}
if (object instanceof CloudServiceInstance) {
CloudServiceInstance instance = (CloudServiceInstance) object;
@Nullable String providerValue = instance.getProvider();
if (providerValue != null) {
provider(providerValue);
}
putAllCredentials(instance.getCredentials());
@Nullable ServiceOperation lastOperationValue = instance.getLastOperation();
if (lastOperationValue != null) {
lastOperation(lastOperationValue);
}
@Nullable String labelValue = instance.getLabel();
if (labelValue != null) {
label(labelValue);
}
@Nullable String brokerValue = instance.getBroker();
if (brokerValue != null) {
broker(brokerValue);
}
@Nullable ServiceInstanceType typeValue = instance.getType();
if (typeValue != null) {
type(typeValue);
}
@Nullable String planValue = instance.getPlan();
if (planValue != null) {
plan(planValue);
}
@Nullable String versionValue = instance.getVersion();
if (versionValue != null) {
version(versionValue);
}
addAllTags(instance.getTags());
}
}
/**
* Initializes the value for the {@link CloudServiceInstance#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 CloudServiceInstance#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 CloudServiceInstance#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 CloudServiceInstance#getLabel() label} attribute.
* @param label The value for label (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("label")
public final Builder label(@Nullable String label) {
this.label = label;
return this;
}
/**
* Initializes the value for the {@link CloudServiceInstance#getPlan() plan} attribute.
* @param plan The value for plan (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("plan")
public final Builder plan(@Nullable String plan) {
this.plan = plan;
return this;
}
/**
* Initializes the value for the {@link CloudServiceInstance#getProvider() provider} attribute.
* @param provider The value for provider (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("provider")
public final Builder provider(@Nullable String provider) {
this.provider = provider;
return this;
}
/**
* Initializes the value for the {@link CloudServiceInstance#getBroker() broker} attribute.
* @param broker The value for broker (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("broker")
public final Builder broker(@Nullable String broker) {
this.broker = broker;
return this;
}
/**
* Initializes the value for the {@link CloudServiceInstance#getVersion() version} attribute.
* @param version The value for version (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("version")
public final Builder version(@Nullable String version) {
this.version = version;
return this;
}
/**
* Put one entry to the {@link CloudServiceInstance#getCredentials() credentials} map.
* @param key The key in the credentials map
* @param value The associated value in the credentials map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putCredential(String key, Object value) {
this.credentials.put(key, value);
return this;
}
/**
* Put one entry to the {@link CloudServiceInstance#getCredentials() credentials} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putCredential(Map.Entry entry) {
String k = entry.getKey();
Object v = entry.getValue();
this.credentials.put(k, v);
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link CloudServiceInstance#getCredentials() credentials} map. Nulls are not permitted
* @param entries The entries that will be added to the credentials map
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("credentials")
public final Builder credentials(Map entries) {
this.credentials.clear();
return putAllCredentials(entries);
}
/**
* Put all mappings from the specified map as entries to {@link CloudServiceInstance#getCredentials() credentials} map. Nulls are not permitted
* @param entries The entries that will be added to the credentials map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putAllCredentials(Map entries) {
for (Map.Entry e : entries.entrySet()) {
String k = e.getKey();
Object v = e.getValue();
this.credentials.put(k, v);
}
return this;
}
/**
* Adds one element to {@link CloudServiceInstance#getTags() tags} list.
* @param element A tags element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addTag(String element) {
this.tags.add(Objects.requireNonNull(element, "tags element"));
return this;
}
/**
* Adds elements to {@link CloudServiceInstance#getTags() tags} list.
* @param elements An array of tags elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addTags(String... elements) {
for (String element : elements) {
this.tags.add(Objects.requireNonNull(element, "tags element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link CloudServiceInstance#getTags() tags} list.
* @param elements An iterable of tags elements
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("tags")
public final Builder tags(Iterable elements) {
this.tags.clear();
return addAllTags(elements);
}
/**
* Adds elements to {@link CloudServiceInstance#getTags() tags} list.
* @param elements An iterable of tags elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllTags(Iterable elements) {
for (String element : elements) {
this.tags.add(Objects.requireNonNull(element, "tags element"));
}
return this;
}
/**
* Initializes the value for the {@link CloudServiceInstance#getType() type} attribute.
* @param type The value for type (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("type")
public final Builder type(@Nullable ServiceInstanceType type) {
this.type = type;
return this;
}
/**
* Initializes the value for the {@link CloudServiceInstance#getLastOperation() lastOperation} attribute.
* @param lastOperation The value for lastOperation (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("lastOperation")
public final Builder lastOperation(@Nullable ServiceOperation lastOperation) {
this.lastOperation = lastOperation;
return this;
}
/**
* Builds a new {@link ImmutableCloudServiceInstance ImmutableCloudServiceInstance}.
* @return An immutable instance of CloudServiceInstance
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableCloudServiceInstance build() {
return new ImmutableCloudServiceInstance(
name,
metadata,
v3Metadata,
label,
plan,
provider,
broker,
version,
createUnmodifiableMap(false, false, credentials),
createUnmodifiableList(true, tags),
type,
lastOperation);
}
}
private static List createSafeList(Iterable extends T> iterable, boolean checkNulls, boolean skipNulls) {
ArrayList list;
if (iterable instanceof Collection>) {
int size = ((Collection>) iterable).size();
if (size == 0) return Collections.emptyList();
list = new ArrayList<>();
} else {
list = new ArrayList<>();
}
for (T element : iterable) {
if (skipNulls && element == null) continue;
if (checkNulls) Objects.requireNonNull(element, "element");
list.add(element);
}
return list;
}
private static List createUnmodifiableList(boolean clone, List list) {
switch(list.size()) {
case 0: return Collections.emptyList();
case 1: return Collections.singletonList(list.get(0));
default:
if (clone) {
return Collections.unmodifiableList(new ArrayList<>(list));
} else {
if (list instanceof ArrayList>) {
((ArrayList>) list).trimToSize();
}
return Collections.unmodifiableList(list);
}
}
}
private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, Map extends K, ? extends V> map) {
switch (map.size()) {
case 0: return Collections.emptyMap();
case 1: {
Map.Entry extends K, ? extends V> e = map.entrySet().iterator().next();
K k = e.getKey();
V v = e.getValue();
if (checkNulls) {
Objects.requireNonNull(k, "key");
Objects.requireNonNull(v, "value");
}
if (skipNulls && (k == null || v == null)) {
return Collections.emptyMap();
}
return Collections.singletonMap(k, v);
}
default: {
Map linkedMap = new LinkedHashMap<>(map.size());
if (skipNulls || checkNulls) {
for (Map.Entry extends K, ? extends V> e : map.entrySet()) {
K k = e.getKey();
V v = e.getValue();
if (skipNulls) {
if (k == null || v == null) continue;
} else if (checkNulls) {
Objects.requireNonNull(k, "key");
Objects.requireNonNull(v, "value");
}
linkedMap.put(k, v);
}
} else {
linkedMap.putAll(map);
}
return Collections.unmodifiableMap(linkedMap);
}
}
}
}