All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.cloudfoundry.operations.services.UpdateServiceInstanceRequest Maven / Gradle / Ivy

There is a newer version: 5.12.2.RELEASE
Show newest version
package org.cloudfoundry.operations.services;

import java.time.Duration;
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 options for the update service instance operation
 */
@Generated(from = "_UpdateServiceInstanceRequest", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class UpdateServiceInstanceRequest
    extends org.cloudfoundry.operations.services._UpdateServiceInstanceRequest {
  private final Duration completionTimeout;
  private final @Nullable Map parameters;
  private final @Nullable String planName;
  private final String serviceInstanceName;
  private final @Nullable List tags;

  private UpdateServiceInstanceRequest(UpdateServiceInstanceRequest.Builder builder) {
    this.parameters = builder.parameters == null ? null : createUnmodifiableMap(false, false, builder.parameters);
    this.planName = builder.planName;
    this.serviceInstanceName = builder.serviceInstanceName;
    this.tags = builder.tags == null ? null : createUnmodifiableList(true, builder.tags);
    this.completionTimeout = builder.completionTimeout != null
        ? builder.completionTimeout
        : Objects.requireNonNull(super.getCompletionTimeout(), "completionTimeout");
  }

  /**
   * How long to wait for update
   */
  @Override
  public Duration getCompletionTimeout() {
    return completionTimeout;
  }

  /**
   * The parameters of the service instance
   */
  @Override
  public @Nullable Map getParameters() {
    return parameters;
  }

  /**
   * The name of the required plan
   */
  @Override
  public @Nullable String getPlanName() {
    return planName;
  }

  /**
   * The name of the service instance
   */
  @Override
  public String getServiceInstanceName() {
    return serviceInstanceName;
  }

  /**
   * The tags
   */
  @Override
  public @Nullable List getTags() {
    return tags;
  }

  /**
   * 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((UpdateServiceInstanceRequest) another);
  }

  private boolean equalTo(UpdateServiceInstanceRequest another) {
    return completionTimeout.equals(another.completionTimeout)
        && Objects.equals(parameters, another.parameters)
        && Objects.equals(planName, another.planName)
        && serviceInstanceName.equals(another.serviceInstanceName)
        && Objects.equals(tags, another.tags);
  }

  /**
   * Computes a hash code from attributes: {@code completionTimeout}, {@code parameters}, {@code planName}, {@code serviceInstanceName}, {@code tags}.
   * @return hashCode value
   */
  @Override
  public int hashCode() {
    int h = 5381;
    h += (h << 5) + completionTimeout.hashCode();
    h += (h << 5) + Objects.hashCode(parameters);
    h += (h << 5) + Objects.hashCode(planName);
    h += (h << 5) + serviceInstanceName.hashCode();
    h += (h << 5) + Objects.hashCode(tags);
    return h;
  }

  /**
   * Prints the immutable value {@code UpdateServiceInstanceRequest} with attribute values.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return "UpdateServiceInstanceRequest{"
        + "completionTimeout=" + completionTimeout
        + ", parameters=" + parameters
        + ", planName=" + planName
        + ", serviceInstanceName=" + serviceInstanceName
        + ", tags=" + tags
        + "}";
  }

  /**
   * Creates a builder for {@link UpdateServiceInstanceRequest UpdateServiceInstanceRequest}.
   * @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_NAME = 0x1L; private long initBits = 0x1L; private Duration completionTimeout; private Map parameters = null; private String planName; private String serviceInstanceName; private List tags = null; 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"); completionTimeout(instance.getCompletionTimeout()); Map parametersValue = instance.getParameters(); if (parametersValue != null) { putAllParameters(parametersValue); } String planNameValue = instance.getPlanName(); if (planNameValue != null) { planName(planNameValue); } serviceInstanceName(instance.getServiceInstanceName()); List tagsValue = instance.getTags(); if (tagsValue != null) { addAllTags(tagsValue); } return this; } /** * Initializes the value for the {@link UpdateServiceInstanceRequest#getCompletionTimeout() completionTimeout} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link UpdateServiceInstanceRequest#getCompletionTimeout() completionTimeout}. * @param completionTimeout The value for completionTimeout * @return {@code this} builder for use in a chained invocation */ public final Builder completionTimeout(Duration completionTimeout) { this.completionTimeout = Objects.requireNonNull(completionTimeout, "completionTimeout"); 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(key, value); 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(k, v); 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(k, v); } return this; } /** * Initializes the value for the {@link UpdateServiceInstanceRequest#getPlanName() planName} attribute. * @param planName The value for planName (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ public final Builder planName(@Nullable String planName) { this.planName = planName; return this; } /** * Initializes the value for the {@link UpdateServiceInstanceRequest#getServiceInstanceName() serviceInstanceName} attribute. * @param serviceInstanceName The value for serviceInstanceName * @return {@code this} builder for use in a chained invocation */ public final Builder serviceInstanceName(String serviceInstanceName) { this.serviceInstanceName = Objects.requireNonNull(serviceInstanceName, "serviceInstanceName"); initBits &= ~INIT_BIT_SERVICE_INSTANCE_NAME; 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; } /** * 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_NAME) != 0) attributes.add("serviceInstanceName"); return "Cannot build UpdateServiceInstanceRequest, some of required attributes are not set " + attributes; } } private static List createSafeList(Iterable 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 map) { switch (map.size()) { case 0: return Collections.emptyMap(); case 1: { Map.Entry 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 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); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy