
org.cloudfoundry.client.v2.serviceinstances.CreateServiceInstanceRequest Maven / Gradle / Ivy
package org.cloudfoundry.client.v2.serviceinstances;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.ArrayList;
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.Nullable;
import org.immutables.value.Generated;
/**
* The request payload for the Create Service Instance
*/
@Generated(from = "_CreateServiceInstanceRequest", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class CreateServiceInstanceRequest
extends org.cloudfoundry.client.v2.serviceinstances._CreateServiceInstanceRequest {
private final @Nullable Boolean acceptsIncomplete;
private final String name;
private final @Nullable Map parameters;
private final String servicePlanId;
private final String spaceId;
private final @Nullable List tags;
private CreateServiceInstanceRequest(CreateServiceInstanceRequest.Builder builder) {
this.acceptsIncomplete = builder.acceptsIncomplete;
this.name = builder.name;
this.parameters = builder.parameters == null ? null : createUnmodifiableMap(false, false, builder.parameters);
this.servicePlanId = builder.servicePlanId;
this.spaceId = builder.spaceId;
this.tags = builder.tags == null ? null : createUnmodifiableList(true, builder.tags);
}
/**
* The accept incomplete flag
*/
@JsonIgnore
@Override
public @Nullable Boolean getAcceptsIncomplete() {
return acceptsIncomplete;
}
/**
* The name
*/
@JsonProperty("name")
@Override
public String getName() {
return name;
}
/**
* Key/value pairs of all arbitrary parameters to pass along to the service broker
*/
@JsonProperty("parameters")
@Override
public @Nullable Map getParameters() {
return parameters;
}
/**
* The service plan id
*/
@JsonProperty("service_plan_guid")
@Override
public String getServicePlanId() {
return servicePlanId;
}
/**
* The space id
*/
@JsonProperty("space_guid")
@Override
public String getSpaceId() {
return spaceId;
}
/**
* A list of tags for the service instance
*/
@JsonProperty("tags")
@Override
public @Nullable List getTags() {
return tags;
}
/**
* This instance is equal to all instances of {@code CreateServiceInstanceRequest} 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 CreateServiceInstanceRequest
&& equalTo(0, (CreateServiceInstanceRequest) another);
}
private boolean equalTo(int synthetic, CreateServiceInstanceRequest another) {
return Objects.equals(acceptsIncomplete, another.acceptsIncomplete)
&& name.equals(another.name)
&& Objects.equals(parameters, another.parameters)
&& servicePlanId.equals(another.servicePlanId)
&& spaceId.equals(another.spaceId)
&& Objects.equals(tags, another.tags);
}
/**
* Computes a hash code from attributes: {@code acceptsIncomplete}, {@code name}, {@code parameters}, {@code servicePlanId}, {@code spaceId}, {@code tags}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(acceptsIncomplete);
h += (h << 5) + name.hashCode();
h += (h << 5) + Objects.hashCode(parameters);
h += (h << 5) + servicePlanId.hashCode();
h += (h << 5) + spaceId.hashCode();
h += (h << 5) + Objects.hashCode(tags);
return h;
}
/**
* Prints the immutable value {@code CreateServiceInstanceRequest} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "CreateServiceInstanceRequest{"
+ "acceptsIncomplete=" + acceptsIncomplete
+ ", name=" + name
+ ", parameters=" + parameters
+ ", servicePlanId=" + servicePlanId
+ ", spaceId=" + spaceId
+ ", tags=" + tags
+ "}";
}
/**
* 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 = "_CreateServiceInstanceRequest", generator = "Immutables")
@Deprecated
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends org.cloudfoundry.client.v2.serviceinstances._CreateServiceInstanceRequest {
Boolean acceptsIncomplete;
String name;
Map parameters = null;
String servicePlanId;
String spaceId;
List tags = null;
@JsonIgnore
public void setAcceptsIncomplete(@Nullable Boolean acceptsIncomplete) {
this.acceptsIncomplete = acceptsIncomplete;
}
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("parameters")
public void setParameters(@Nullable Map parameters) {
this.parameters = parameters;
}
@JsonProperty("service_plan_guid")
public void setServicePlanId(String servicePlanId) {
this.servicePlanId = servicePlanId;
}
@JsonProperty("space_guid")
public void setSpaceId(String spaceId) {
this.spaceId = spaceId;
}
@JsonProperty("tags")
public void setTags(@Nullable List tags) {
this.tags = tags;
}
@Override
public Boolean getAcceptsIncomplete() { throw new UnsupportedOperationException(); }
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public Map getParameters() { throw new UnsupportedOperationException(); }
@Override
public String getServicePlanId() { throw new UnsupportedOperationException(); }
@Override
public String getSpaceId() { throw new UnsupportedOperationException(); }
@Override
public List getTags() { 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 CreateServiceInstanceRequest fromJson(Json json) {
CreateServiceInstanceRequest.Builder builder = CreateServiceInstanceRequest.builder();
if (json.acceptsIncomplete != null) {
builder.acceptsIncomplete(json.acceptsIncomplete);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.parameters != null) {
builder.putAllParameters(json.parameters);
}
if (json.servicePlanId != null) {
builder.servicePlanId(json.servicePlanId);
}
if (json.spaceId != null) {
builder.spaceId(json.spaceId);
}
if (json.tags != null) {
builder.addAllTags(json.tags);
}
return builder.build();
}
/**
* Creates a builder for {@link CreateServiceInstanceRequest CreateServiceInstanceRequest}.
*
* CreateServiceInstanceRequest.builder()
* .acceptsIncomplete(Boolean | null) // nullable {@link CreateServiceInstanceRequest#getAcceptsIncomplete() acceptsIncomplete}
* .name(String) // required {@link CreateServiceInstanceRequest#getName() name}
* .parameters(Map<String, Object> | null) // nullable {@link CreateServiceInstanceRequest#getParameters() parameters}
* .servicePlanId(String) // required {@link CreateServiceInstanceRequest#getServicePlanId() servicePlanId}
* .spaceId(String) // required {@link CreateServiceInstanceRequest#getSpaceId() spaceId}
* .tags(List<String> | null) // nullable {@link CreateServiceInstanceRequest#getTags() tags}
* .build();
*
* @return A new CreateServiceInstanceRequest builder
*/
public static CreateServiceInstanceRequest.Builder builder() {
return new CreateServiceInstanceRequest.Builder();
}
/**
* Builds instances of type {@link CreateServiceInstanceRequest CreateServiceInstanceRequest}.
* 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 = "_CreateServiceInstanceRequest", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private static final long INIT_BIT_SERVICE_PLAN_ID = 0x2L;
private static final long INIT_BIT_SPACE_ID = 0x4L;
private long initBits = 0x7L;
private Boolean acceptsIncomplete;
private String name;
private Map parameters = null;
private String servicePlanId;
private String spaceId;
private List tags = null;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code CreateServiceInstanceRequest} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(CreateServiceInstanceRequest instance) {
return from((_CreateServiceInstanceRequest) instance);
}
/**
* Copy abstract value type {@code _CreateServiceInstanceRequest} instance into builder.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
final Builder from(_CreateServiceInstanceRequest instance) {
Objects.requireNonNull(instance, "instance");
Boolean acceptsIncompleteValue = instance.getAcceptsIncomplete();
if (acceptsIncompleteValue != null) {
acceptsIncomplete(acceptsIncompleteValue);
}
name(instance.getName());
Map parametersValue = instance.getParameters();
if (parametersValue != null) {
putAllParameters(parametersValue);
}
servicePlanId(instance.getServicePlanId());
spaceId(instance.getSpaceId());
List tagsValue = instance.getTags();
if (tagsValue != null) {
addAllTags(tagsValue);
}
return this;
}
/**
* Initializes the value for the {@link CreateServiceInstanceRequest#getAcceptsIncomplete() acceptsIncomplete} attribute.
* @param acceptsIncomplete The value for acceptsIncomplete (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder acceptsIncomplete(@Nullable Boolean acceptsIncomplete) {
this.acceptsIncomplete = acceptsIncomplete;
return this;
}
/**
* Initializes the value for the {@link CreateServiceInstanceRequest#getName() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
public final Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Put one entry to the {@link CreateServiceInstanceRequest#getParameters() parameters} map.
* @param key The key in the parameters map
* @param value The associated value in the parameters map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder parameter(String key, Object value) {
if (this.parameters == null) {
this.parameters = new LinkedHashMap();
}
this.parameters.put(key, value);
return this;
}
/**
* Put one entry to the {@link CreateServiceInstanceRequest#getParameters() parameters} 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 parameter(Map.Entry entry) {
if (this.parameters == null) {
this.parameters = new LinkedHashMap();
}
String k = entry.getKey();
Object v = entry.getValue();
this.parameters.put(k, v);
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link CreateServiceInstanceRequest#getParameters() parameters} map. Nulls are not permitted as keys or values, but parameter itself can be null
* @param entries The entries that will be added to the parameters map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder parameters(@Nullable Map entries) {
if (entries == null) {
this.parameters = null;
return this;
}
this.parameters = new LinkedHashMap();
return putAllParameters(entries);
}
/**
* Put all mappings from the specified map as entries to {@link CreateServiceInstanceRequest#getParameters() parameters} map. Nulls are not permitted
* @param entries The entries that will be added to the parameters map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putAllParameters(Map entries) {
if (this.parameters == null) {
this.parameters = new LinkedHashMap();
}
for (Map.Entry e : entries.entrySet()) {
String k = e.getKey();
Object v = e.getValue();
this.parameters.put(k, v);
}
return this;
}
/**
* Initializes the value for the {@link CreateServiceInstanceRequest#getServicePlanId() servicePlanId} attribute.
* @param servicePlanId The value for servicePlanId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder servicePlanId(String servicePlanId) {
this.servicePlanId = Objects.requireNonNull(servicePlanId, "servicePlanId");
initBits &= ~INIT_BIT_SERVICE_PLAN_ID;
return this;
}
/**
* Initializes the value for the {@link CreateServiceInstanceRequest#getSpaceId() spaceId} attribute.
* @param spaceId The value for spaceId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder spaceId(String spaceId) {
this.spaceId = Objects.requireNonNull(spaceId, "spaceId");
initBits &= ~INIT_BIT_SPACE_ID;
return this;
}
/**
* Adds one element to {@link CreateServiceInstanceRequest#getTags() tags} list.
* @param element A tags element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder tag(String element) {
if (this.tags == null) {
this.tags = new ArrayList();
}
this.tags.add(Objects.requireNonNull(element, "tags element"));
return this;
}
/**
* Adds elements to {@link CreateServiceInstanceRequest#getTags() tags} list.
* @param elements An array of tags elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder tags(String... elements) {
if (this.tags == null) {
this.tags = new ArrayList();
}
for (String element : elements) {
this.tags.add(Objects.requireNonNull(element, "tags element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link CreateServiceInstanceRequest#getTags() tags} list.
* @param elements An iterable of tags elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder tags(@Nullable Iterable elements) {
if (elements == null) {
this.tags = null;
return this;
}
this.tags = new ArrayList();
return addAllTags(elements);
}
/**
* Adds elements to {@link CreateServiceInstanceRequest#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) {
Objects.requireNonNull(elements, "tags element");
if (this.tags == null) {
this.tags = new ArrayList();
}
for (String element : elements) {
this.tags.add(Objects.requireNonNull(element, "tags element"));
}
return this;
}
/**
* Builds a new {@link CreateServiceInstanceRequest CreateServiceInstanceRequest}.
* @return An immutable instance of CreateServiceInstanceRequest
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public CreateServiceInstanceRequest build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new CreateServiceInstanceRequest(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
if ((initBits & INIT_BIT_SERVICE_PLAN_ID) != 0) attributes.add("servicePlanId");
if ((initBits & INIT_BIT_SPACE_ID) != 0) attributes.add("spaceId");
return "Cannot build CreateServiceInstanceRequest, some of required attributes are not set " + attributes;
}
}
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<>(size);
} 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, v == null ? "value for key: " + k : null);
}
if (skipNulls && (k == null || v == null)) {
return Collections.emptyMap();
}
return Collections.singletonMap(k, v);
}
default: {
Map linkedMap = new LinkedHashMap<>(map.size() * 4 / 3 + 1);
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, v == null ? "value for key: " + k : null);
}
linkedMap.put(k, v);
}
} else {
linkedMap.putAll(map);
}
return Collections.unmodifiableMap(linkedMap);
}
}
}
}