
org.cloudfoundry.client.v3.serviceinstances.UpdateServiceInstanceRequest Maven / Gradle / Ivy
package org.cloudfoundry.client.v3.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.cloudfoundry.client.v3.MaintenanceInfo;
import org.cloudfoundry.client.v3.Metadata;
import org.immutables.value.Generated;
/**
* The request payload for the Update Service operation
*/
@Generated(from = "_UpdateServiceInstanceRequest", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class UpdateServiceInstanceRequest
extends org.cloudfoundry.client.v3.serviceinstances._UpdateServiceInstanceRequest {
private final String serviceInstanceId;
private final @Nullable Metadata metadata;
private final @Nullable String name;
private final @Nullable ServiceInstanceRelationships relationships;
private final @Nullable List tags;
private final @Nullable Map parameters;
private final @Nullable Map credentials;
private final @Nullable String syslogDrainUrl;
private final @Nullable String routeServiceUrl;
private final @Nullable MaintenanceInfo maintenanceInfo;
private UpdateServiceInstanceRequest(UpdateServiceInstanceRequest.Builder builder) {
this.serviceInstanceId = builder.serviceInstanceId;
this.metadata = builder.metadata;
this.name = builder.name;
this.relationships = builder.relationships;
this.tags = builder.tags == null ? null : createUnmodifiableList(true, builder.tags);
this.parameters = builder.parameters == null ? null : createUnmodifiableMap(false, false, builder.parameters);
this.credentials = builder.credentials == null ? null : createUnmodifiableMap(false, false, builder.credentials);
this.syslogDrainUrl = builder.syslogDrainUrl;
this.routeServiceUrl = builder.routeServiceUrl;
this.maintenanceInfo = builder.maintenanceInfo;
}
/**
* The service instance id
*/
@JsonProperty("serviceInstanceId")
@JsonIgnore
@Override
public String getServiceInstanceId() {
return serviceInstanceId;
}
/**
* The metadata
*/
@JsonProperty("metadata")
@Override
public @Nullable Metadata getMetadata() {
return metadata;
}
/**
* The name
*/
@JsonProperty("name")
@Override
public @Nullable String getName() {
return name;
}
/**
* The relationships
*/
@JsonProperty("relationships")
@Override
public @Nullable ServiceInstanceRelationships getRelationships() {
return relationships;
}
/**
* A list of tags for the service instance
*/
@JsonProperty("tags")
@Override
public @Nullable List getTags() {
return tags;
}
/**
* The service creation parameters
*/
@JsonProperty("parameters")
@Override
public @Nullable Map getParameters() {
return parameters;
}
/**
* The user provided service credentials
*/
@JsonProperty("credentials")
@Override
public @Nullable Map getCredentials() {
return credentials;
}
/**
* The syslog drain url
*/
@JsonProperty("syslog_drain_url")
@Override
public @Nullable String getSyslogDrainUrl() {
return syslogDrainUrl;
}
/**
* The route service url
*/
@JsonProperty("route_service_url")
@Override
public @Nullable String getRouteServiceUrl() {
return routeServiceUrl;
}
/**
* The maintenance info object
*/
@JsonProperty("maintenance_info")
@Override
public @Nullable MaintenanceInfo maintenanceInfo() {
return maintenanceInfo;
}
/**
* This instance is equal to all instances of {@code UpdateServiceInstanceRequest} 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 UpdateServiceInstanceRequest
&& equalTo(0, (UpdateServiceInstanceRequest) another);
}
private boolean equalTo(int synthetic, UpdateServiceInstanceRequest another) {
return serviceInstanceId.equals(another.serviceInstanceId)
&& Objects.equals(metadata, another.metadata)
&& Objects.equals(name, another.name)
&& Objects.equals(relationships, another.relationships)
&& Objects.equals(tags, another.tags)
&& Objects.equals(parameters, another.parameters)
&& Objects.equals(credentials, another.credentials)
&& Objects.equals(syslogDrainUrl, another.syslogDrainUrl)
&& Objects.equals(routeServiceUrl, another.routeServiceUrl)
&& Objects.equals(maintenanceInfo, another.maintenanceInfo);
}
/**
* Computes a hash code from attributes: {@code serviceInstanceId}, {@code metadata}, {@code name}, {@code relationships}, {@code tags}, {@code parameters}, {@code credentials}, {@code syslogDrainUrl}, {@code routeServiceUrl}, {@code maintenanceInfo}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + serviceInstanceId.hashCode();
h += (h << 5) + Objects.hashCode(metadata);
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + Objects.hashCode(relationships);
h += (h << 5) + Objects.hashCode(tags);
h += (h << 5) + Objects.hashCode(parameters);
h += (h << 5) + Objects.hashCode(credentials);
h += (h << 5) + Objects.hashCode(syslogDrainUrl);
h += (h << 5) + Objects.hashCode(routeServiceUrl);
h += (h << 5) + Objects.hashCode(maintenanceInfo);
return h;
}
/**
* Prints the immutable value {@code UpdateServiceInstanceRequest} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "UpdateServiceInstanceRequest{"
+ "serviceInstanceId=" + serviceInstanceId
+ ", metadata=" + metadata
+ ", name=" + name
+ ", relationships=" + relationships
+ ", tags=" + tags
+ ", parameters=" + parameters
+ ", credentials=" + credentials
+ ", syslogDrainUrl=" + syslogDrainUrl
+ ", routeServiceUrl=" + routeServiceUrl
+ ", maintenanceInfo=" + maintenanceInfo
+ "}";
}
/**
* 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 = "_UpdateServiceInstanceRequest", generator = "Immutables")
@Deprecated
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends org.cloudfoundry.client.v3.serviceinstances._UpdateServiceInstanceRequest {
String serviceInstanceId;
Metadata metadata;
String name;
ServiceInstanceRelationships relationships;
List tags = null;
Map parameters = null;
Map credentials = null;
String syslogDrainUrl;
String routeServiceUrl;
MaintenanceInfo maintenanceInfo;
@JsonProperty("serviceInstanceId")
@JsonIgnore
public void setServiceInstanceId(String serviceInstanceId) {
this.serviceInstanceId = serviceInstanceId;
}
@JsonProperty("metadata")
public void setMetadata(@Nullable Metadata metadata) {
this.metadata = metadata;
}
@JsonProperty("name")
public void setName(@Nullable String name) {
this.name = name;
}
@JsonProperty("relationships")
public void setRelationships(@Nullable ServiceInstanceRelationships relationships) {
this.relationships = relationships;
}
@JsonProperty("tags")
public void setTags(@Nullable List tags) {
this.tags = tags;
}
@JsonProperty("parameters")
public void setParameters(@Nullable Map parameters) {
this.parameters = parameters;
}
@JsonProperty("credentials")
public void setCredentials(@Nullable Map credentials) {
this.credentials = credentials;
}
@JsonProperty("syslog_drain_url")
public void setSyslogDrainUrl(@Nullable String syslogDrainUrl) {
this.syslogDrainUrl = syslogDrainUrl;
}
@JsonProperty("route_service_url")
public void setRouteServiceUrl(@Nullable String routeServiceUrl) {
this.routeServiceUrl = routeServiceUrl;
}
@JsonProperty("maintenance_info")
public void setMaintenanceInfo(@Nullable MaintenanceInfo maintenanceInfo) {
this.maintenanceInfo = maintenanceInfo;
}
@Override
public String getServiceInstanceId() { throw new UnsupportedOperationException(); }
@Override
public Metadata getMetadata() { throw new UnsupportedOperationException(); }
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public ServiceInstanceRelationships getRelationships() { throw new UnsupportedOperationException(); }
@Override
public List getTags() { throw new UnsupportedOperationException(); }
@Override
public Map getParameters() { throw new UnsupportedOperationException(); }
@Override
public Map getCredentials() { throw new UnsupportedOperationException(); }
@Override
public String getSyslogDrainUrl() { throw new UnsupportedOperationException(); }
@Override
public String getRouteServiceUrl() { throw new UnsupportedOperationException(); }
@Override
public MaintenanceInfo maintenanceInfo() { 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 UpdateServiceInstanceRequest fromJson(Json json) {
UpdateServiceInstanceRequest.Builder builder = UpdateServiceInstanceRequest.builder();
if (json.serviceInstanceId != null) {
builder.serviceInstanceId(json.serviceInstanceId);
}
if (json.metadata != null) {
builder.metadata(json.metadata);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.relationships != null) {
builder.relationships(json.relationships);
}
if (json.tags != null) {
builder.addAllTags(json.tags);
}
if (json.parameters != null) {
builder.putAllParameters(json.parameters);
}
if (json.credentials != null) {
builder.putAllCredentials(json.credentials);
}
if (json.syslogDrainUrl != null) {
builder.syslogDrainUrl(json.syslogDrainUrl);
}
if (json.routeServiceUrl != null) {
builder.routeServiceUrl(json.routeServiceUrl);
}
if (json.maintenanceInfo != null) {
builder.maintenanceInfo(json.maintenanceInfo);
}
return builder.build();
}
/**
* Creates a builder for {@link UpdateServiceInstanceRequest UpdateServiceInstanceRequest}.
*
* UpdateServiceInstanceRequest.builder()
* .serviceInstanceId(String) // required {@link UpdateServiceInstanceRequest#getServiceInstanceId() serviceInstanceId}
* .metadata(org.cloudfoundry.client.v3.Metadata | null) // nullable {@link UpdateServiceInstanceRequest#getMetadata() metadata}
* .name(String | null) // nullable {@link UpdateServiceInstanceRequest#getName() name}
* .relationships(org.cloudfoundry.client.v3.serviceinstances.ServiceInstanceRelationships | null) // nullable {@link UpdateServiceInstanceRequest#getRelationships() relationships}
* .tags(List<String> | null) // nullable {@link UpdateServiceInstanceRequest#getTags() tags}
* .parameters(Map<String, Object> | null) // nullable {@link UpdateServiceInstanceRequest#getParameters() parameters}
* .credentials(Map<String, Object> | null) // nullable {@link UpdateServiceInstanceRequest#getCredentials() credentials}
* .syslogDrainUrl(String | null) // nullable {@link UpdateServiceInstanceRequest#getSyslogDrainUrl() syslogDrainUrl}
* .routeServiceUrl(String | null) // nullable {@link UpdateServiceInstanceRequest#getRouteServiceUrl() routeServiceUrl}
* .maintenanceInfo(org.cloudfoundry.client.v3.MaintenanceInfo | null) // nullable {@link UpdateServiceInstanceRequest#maintenanceInfo() maintenanceInfo}
* .build();
*
* @return A new UpdateServiceInstanceRequest builder
*/
public static UpdateServiceInstanceRequest.Builder builder() {
return new UpdateServiceInstanceRequest.Builder();
}
/**
* Builds instances of type {@link UpdateServiceInstanceRequest UpdateServiceInstanceRequest}.
* 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 = "_UpdateServiceInstanceRequest", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_SERVICE_INSTANCE_ID = 0x1L;
private long initBits = 0x1L;
private String serviceInstanceId;
private Metadata metadata;
private String name;
private ServiceInstanceRelationships relationships;
private List tags = null;
private Map parameters = null;
private Map credentials = null;
private String syslogDrainUrl;
private String routeServiceUrl;
private MaintenanceInfo maintenanceInfo;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code UpdateServiceInstanceRequest} 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(UpdateServiceInstanceRequest instance) {
return from((_UpdateServiceInstanceRequest) instance);
}
/**
* Copy abstract value type {@code _UpdateServiceInstanceRequest} 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(_UpdateServiceInstanceRequest instance) {
Objects.requireNonNull(instance, "instance");
serviceInstanceId(instance.getServiceInstanceId());
Metadata metadataValue = instance.getMetadata();
if (metadataValue != null) {
metadata(metadataValue);
}
String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
ServiceInstanceRelationships relationshipsValue = instance.getRelationships();
if (relationshipsValue != null) {
relationships(relationshipsValue);
}
List tagsValue = instance.getTags();
if (tagsValue != null) {
addAllTags(tagsValue);
}
Map parametersValue = instance.getParameters();
if (parametersValue != null) {
putAllParameters(parametersValue);
}
Map credentialsValue = instance.getCredentials();
if (credentialsValue != null) {
putAllCredentials(credentialsValue);
}
String syslogDrainUrlValue = instance.getSyslogDrainUrl();
if (syslogDrainUrlValue != null) {
syslogDrainUrl(syslogDrainUrlValue);
}
String routeServiceUrlValue = instance.getRouteServiceUrl();
if (routeServiceUrlValue != null) {
routeServiceUrl(routeServiceUrlValue);
}
MaintenanceInfo maintenanceInfoValue = instance.maintenanceInfo();
if (maintenanceInfoValue != null) {
maintenanceInfo(maintenanceInfoValue);
}
return this;
}
/**
* Initializes the value for the {@link UpdateServiceInstanceRequest#getServiceInstanceId() serviceInstanceId} attribute.
* @param serviceInstanceId The value for serviceInstanceId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder serviceInstanceId(String serviceInstanceId) {
this.serviceInstanceId = Objects.requireNonNull(serviceInstanceId, "serviceInstanceId");
initBits &= ~INIT_BIT_SERVICE_INSTANCE_ID;
return this;
}
/**
* Initializes the value for the {@link UpdateServiceInstanceRequest#getMetadata() metadata} attribute.
* @param metadata The value for metadata (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder metadata(@Nullable Metadata metadata) {
this.metadata = metadata;
return this;
}
/**
* Initializes the value for the {@link UpdateServiceInstanceRequest#getName() name} attribute.
* @param name The value for name (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder name(@Nullable String name) {
this.name = name;
return this;
}
/**
* Initializes the value for the {@link UpdateServiceInstanceRequest#getRelationships() relationships} attribute.
* @param relationships The value for relationships (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder relationships(@Nullable ServiceInstanceRelationships relationships) {
this.relationships = relationships;
return this;
}
/**
* Adds one element to {@link UpdateServiceInstanceRequest#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 UpdateServiceInstanceRequest#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 UpdateServiceInstanceRequest#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 UpdateServiceInstanceRequest#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;
}
/**
* Put one entry to the {@link UpdateServiceInstanceRequest#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(
Objects.requireNonNull(key, "parameters key"),
Objects.requireNonNull(value, value == null ? "parameters value for key: " + key : null));
return this;
}
/**
* Put one entry to the {@link UpdateServiceInstanceRequest#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(
Objects.requireNonNull(k, "parameters key"),
Objects.requireNonNull(v, v == null ? "parameters value for key: " + k : null));
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link UpdateServiceInstanceRequest#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 UpdateServiceInstanceRequest#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(
Objects.requireNonNull(k, "parameters key"),
Objects.requireNonNull(v, v == null ? "parameters value for key: " + k : null));
}
return this;
}
/**
* Put one entry to the {@link UpdateServiceInstanceRequest#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 credential(String key, Object value) {
if (this.credentials == null) {
this.credentials = new LinkedHashMap();
}
this.credentials.put(
Objects.requireNonNull(key, "credentials key"),
Objects.requireNonNull(value, value == null ? "credentials value for key: " + key : null));
return this;
}
/**
* Put one entry to the {@link UpdateServiceInstanceRequest#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 credential(Map.Entry entry) {
if (this.credentials == null) {
this.credentials = new LinkedHashMap();
}
String k = entry.getKey();
Object v = entry.getValue();
this.credentials.put(
Objects.requireNonNull(k, "credentials key"),
Objects.requireNonNull(v, v == null ? "credentials value for key: " + k : null));
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link UpdateServiceInstanceRequest#getCredentials() credentials} 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 credentials map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder credentials(@Nullable Map entries) {
if (entries == null) {
this.credentials = null;
return this;
}
this.credentials = new LinkedHashMap();
return putAllCredentials(entries);
}
/**
* Put all mappings from the specified map as entries to {@link UpdateServiceInstanceRequest#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) {
if (this.credentials == null) {
this.credentials = new LinkedHashMap();
}
for (Map.Entry e : entries.entrySet()) {
String k = e.getKey();
Object v = e.getValue();
this.credentials.put(
Objects.requireNonNull(k, "credentials key"),
Objects.requireNonNull(v, v == null ? "credentials value for key: " + k : null));
}
return this;
}
/**
* Initializes the value for the {@link UpdateServiceInstanceRequest#getSyslogDrainUrl() syslogDrainUrl} attribute.
* @param syslogDrainUrl The value for syslogDrainUrl (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder syslogDrainUrl(@Nullable String syslogDrainUrl) {
this.syslogDrainUrl = syslogDrainUrl;
return this;
}
/**
* Initializes the value for the {@link UpdateServiceInstanceRequest#getRouteServiceUrl() routeServiceUrl} attribute.
* @param routeServiceUrl The value for routeServiceUrl (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder routeServiceUrl(@Nullable String routeServiceUrl) {
this.routeServiceUrl = routeServiceUrl;
return this;
}
/**
* Initializes the value for the {@link UpdateServiceInstanceRequest#maintenanceInfo() maintenanceInfo} attribute.
* @param maintenanceInfo The value for maintenanceInfo (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder maintenanceInfo(@Nullable MaintenanceInfo maintenanceInfo) {
this.maintenanceInfo = maintenanceInfo;
return this;
}
/**
* Builds a new {@link UpdateServiceInstanceRequest UpdateServiceInstanceRequest}.
* @return An immutable instance of UpdateServiceInstanceRequest
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public UpdateServiceInstanceRequest build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new UpdateServiceInstanceRequest(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_SERVICE_INSTANCE_ID) != 0) attributes.add("serviceInstanceId");
return "Cannot build UpdateServiceInstanceRequest, 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);
}
}
}
}