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

org.cloudfoundry.client.v3.routes.CreateRouteResponse Maven / Gradle / Ivy

There is a newer version: 5.12.2.RELEASE
Show newest version
package org.cloudfoundry.client.v3.routes;

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.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.*;
import org.cloudfoundry.client.v3.Metadata;
import org.cloudfoundry.client.v3.Resource;
import org.immutables.value.Generated;

/**
 * The response payload for the Create Route operation
 */
@Generated(from = "_CreateRouteResponse", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class CreateRouteResponse extends org.cloudfoundry.client.v3.routes._CreateRouteResponse {
  private final String createdAt;
  private final String id;
  private final Map links;
  private final @Nullable String updatedAt;
  private final @Nullable List destinations;
  private final String host;
  private final @Nullable Metadata metadata;
  private final String path;
  private final @Nullable Integer port;
  private final @Nullable Protocol protocol;
  private final RouteRelationships relationships;
  private final String url;

  private CreateRouteResponse(CreateRouteResponse.Builder builder) {
    this.createdAt = builder.createdAt;
    this.id = builder.id;
    this.links = createUnmodifiableMap(false, false, builder.links);
    this.updatedAt = builder.updatedAt;
    this.destinations = builder.destinations == null ? null : createUnmodifiableList(true, builder.destinations);
    this.host = builder.host;
    this.metadata = builder.metadata;
    this.path = builder.path;
    this.port = builder.port;
    this.protocol = builder.protocol;
    this.relationships = builder.relationships;
    this.url = builder.url;
  }

  /**
   * When the resource was created
   */
  @JsonProperty("created_at")
  @Override
  public String getCreatedAt() {
    return createdAt;
  }

  /**
   * The resource's id
   */
  @JsonProperty("guid")
  @Override
  public String getId() {
    return id;
  }

  /**
   * Links to related resources and actions for the resource
   */
  @JsonProperty("links")
  @Override
  public Map getLinks() {
    return links;
  }

  /**
   * When the resource was last updated
   */
  @JsonProperty("updated_at")
  @Override
  public @Nullable String getUpdatedAt() {
    return updatedAt;
  }

  /**
   * The destinations
   */
  @JsonProperty("destinations")
  @Override
  public @Nullable List getDestinations() {
    return destinations;
  }

  /**
   * The host
   */
  @JsonProperty("host")
  @Override
  public String getHost() {
    return host;
  }

  /**
   * The metadata
   */
  @JsonProperty("metadata")
  @Override
  public @Nullable Metadata getMetadata() {
    return metadata;
  }

  /**
   * The path
   */
  @JsonProperty("path")
  @Override
  public String getPath() {
    return path;
  }

  /**
   * The port
   */
  @JsonProperty("port")
  @Override
  public @Nullable Integer getPort() {
    return port;
  }

  /**
   * The protocol
   */
  @JsonProperty("protocol")
  @Override
  public @Nullable Protocol getProtocol() {
    return protocol;
  }

  /**
   * The relationships
   */
  @JsonProperty("relationships")
  @Override
  public RouteRelationships getRelationships() {
    return relationships;
  }

  /**
   * The url
   */
  @JsonProperty("url")
  @Override
  public String getUrl() {
    return url;
  }

  /**
   * This instance is equal to all instances of {@code CreateRouteResponse} 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 CreateRouteResponse
        && equalTo(0, (CreateRouteResponse) another);
  }

  private boolean equalTo(int synthetic, CreateRouteResponse another) {
    return createdAt.equals(another.createdAt)
        && id.equals(another.id)
        && links.equals(another.links)
        && Objects.equals(updatedAt, another.updatedAt)
        && Objects.equals(destinations, another.destinations)
        && host.equals(another.host)
        && Objects.equals(metadata, another.metadata)
        && path.equals(another.path)
        && Objects.equals(port, another.port)
        && Objects.equals(protocol, another.protocol)
        && relationships.equals(another.relationships)
        && url.equals(another.url);
  }

  /**
   * Computes a hash code from attributes: {@code createdAt}, {@code id}, {@code links}, {@code updatedAt}, {@code destinations}, {@code host}, {@code metadata}, {@code path}, {@code port}, {@code protocol}, {@code relationships}, {@code url}.
   * @return hashCode value
   */
  @Override
  public int hashCode() {
    int h = 5381;
    h += (h << 5) + createdAt.hashCode();
    h += (h << 5) + id.hashCode();
    h += (h << 5) + links.hashCode();
    h += (h << 5) + Objects.hashCode(updatedAt);
    h += (h << 5) + Objects.hashCode(destinations);
    h += (h << 5) + host.hashCode();
    h += (h << 5) + Objects.hashCode(metadata);
    h += (h << 5) + path.hashCode();
    h += (h << 5) + Objects.hashCode(port);
    h += (h << 5) + Objects.hashCode(protocol);
    h += (h << 5) + relationships.hashCode();
    h += (h << 5) + url.hashCode();
    return h;
  }

  /**
   * Prints the immutable value {@code CreateRouteResponse} with attribute values.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return "CreateRouteResponse{"
        + "createdAt=" + createdAt
        + ", id=" + id
        + ", links=" + links
        + ", updatedAt=" + updatedAt
        + ", destinations=" + destinations
        + ", host=" + host
        + ", metadata=" + metadata
        + ", path=" + path
        + ", port=" + port
        + ", protocol=" + protocol
        + ", relationships=" + relationships
        + ", url=" + url
        + "}";
  }

  /**
   * 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 = "_CreateRouteResponse", generator = "Immutables")
  @Deprecated
  @JsonDeserialize
  @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
  static final class Json extends org.cloudfoundry.client.v3.routes._CreateRouteResponse {
    String createdAt;
    String id;
    Map links = Collections.emptyMap();
    String updatedAt;
    List destinations = null;
    String host;
    Metadata metadata;
    String path;
    Integer port;
    Protocol protocol;
    RouteRelationships relationships;
    String url;
    @JsonProperty("created_at")
    public void setCreatedAt(String createdAt) {
      this.createdAt = createdAt;
    }
    @JsonProperty("guid")
    public void setId(String id) {
      this.id = id;
    }
    @JsonProperty("links")
    public void setLinks(Map links) {
      this.links = links;
    }
    @JsonProperty("updated_at")
    public void setUpdatedAt(@Nullable String updatedAt) {
      this.updatedAt = updatedAt;
    }
    @JsonProperty("destinations")
    public void setDestinations(@Nullable List destinations) {
      this.destinations = destinations;
    }
    @JsonProperty("host")
    public void setHost(String host) {
      this.host = host;
    }
    @JsonProperty("metadata")
    public void setMetadata(@Nullable Metadata metadata) {
      this.metadata = metadata;
    }
    @JsonProperty("path")
    public void setPath(String path) {
      this.path = path;
    }
    @JsonProperty("port")
    public void setPort(@Nullable Integer port) {
      this.port = port;
    }
    @JsonProperty("protocol")
    public void setProtocol(@Nullable Protocol protocol) {
      this.protocol = protocol;
    }
    @JsonProperty("relationships")
    public void setRelationships(RouteRelationships relationships) {
      this.relationships = relationships;
    }
    @JsonProperty("url")
    public void setUrl(String url) {
      this.url = url;
    }
    @Override
    public String getCreatedAt() { throw new UnsupportedOperationException(); }
    @Override
    public String getId() { throw new UnsupportedOperationException(); }
    @Override
    public Map getLinks() { throw new UnsupportedOperationException(); }
    @Override
    public String getUpdatedAt() { throw new UnsupportedOperationException(); }
    @Override
    public List getDestinations() { throw new UnsupportedOperationException(); }
    @Override
    public String getHost() { throw new UnsupportedOperationException(); }
    @Override
    public Metadata getMetadata() { throw new UnsupportedOperationException(); }
    @Override
    public String getPath() { throw new UnsupportedOperationException(); }
    @Override
    public Integer getPort() { throw new UnsupportedOperationException(); }
    @Override
    public Protocol getProtocol() { throw new UnsupportedOperationException(); }
    @Override
    public RouteRelationships getRelationships() { throw new UnsupportedOperationException(); }
    @Override
    public String getUrl() { 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 CreateRouteResponse fromJson(Json json) {
    CreateRouteResponse.Builder builder = CreateRouteResponse.builder();
    if (json.createdAt != null) {
      builder.createdAt(json.createdAt);
    }
    if (json.id != null) {
      builder.id(json.id);
    }
    if (json.links != null) {
      builder.putAllLinks(json.links);
    }
    if (json.updatedAt != null) {
      builder.updatedAt(json.updatedAt);
    }
    if (json.destinations != null) {
      builder.addAllDestinations(json.destinations);
    }
    if (json.host != null) {
      builder.host(json.host);
    }
    if (json.metadata != null) {
      builder.metadata(json.metadata);
    }
    if (json.path != null) {
      builder.path(json.path);
    }
    if (json.port != null) {
      builder.port(json.port);
    }
    if (json.protocol != null) {
      builder.protocol(json.protocol);
    }
    if (json.relationships != null) {
      builder.relationships(json.relationships);
    }
    if (json.url != null) {
      builder.url(json.url);
    }
    return builder.build();
  }

  /**
   * Creates a builder for {@link CreateRouteResponse CreateRouteResponse}.
   * 
   * CreateRouteResponse.builder()
   *    .createdAt(String) // required {@link CreateRouteResponse#getCreatedAt() createdAt}
   *    .id(String) // required {@link CreateRouteResponse#getId() id}
   *    .link|putAllLinks(String => Link) // {@link CreateRouteResponse#getLinks() links} mappings
   *    .updatedAt(String | null) // nullable {@link CreateRouteResponse#getUpdatedAt() updatedAt}
   *    .destinations(List&lt;Destination&gt; | null) // nullable {@link CreateRouteResponse#getDestinations() destinations}
   *    .host(String) // required {@link CreateRouteResponse#getHost() host}
   *    .metadata(org.cloudfoundry.client.v3.Metadata | null) // nullable {@link CreateRouteResponse#getMetadata() metadata}
   *    .path(String) // required {@link CreateRouteResponse#getPath() path}
   *    .port(Integer | null) // nullable {@link CreateRouteResponse#getPort() port}
   *    .protocol(org.cloudfoundry.client.v3.routes.Protocol | null) // nullable {@link CreateRouteResponse#getProtocol() protocol}
   *    .relationships(org.cloudfoundry.client.v3.routes.RouteRelationships) // required {@link CreateRouteResponse#getRelationships() relationships}
   *    .url(String) // required {@link CreateRouteResponse#getUrl() url}
   *    .build();
   * 
* @return A new CreateRouteResponse builder */ public static CreateRouteResponse.Builder builder() { return new CreateRouteResponse.Builder(); } /** * Builds instances of type {@link CreateRouteResponse CreateRouteResponse}. * 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 = "_CreateRouteResponse", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_CREATED_AT = 0x1L; private static final long INIT_BIT_ID = 0x2L; private static final long INIT_BIT_HOST = 0x4L; private static final long INIT_BIT_PATH = 0x8L; private static final long INIT_BIT_RELATIONSHIPS = 0x10L; private static final long INIT_BIT_URL = 0x20L; private long initBits = 0x3fL; private String createdAt; private String id; private Map links = new LinkedHashMap(); private String updatedAt; private List destinations = null; private String host; private Metadata metadata; private String path; private Integer port; private Protocol protocol; private RouteRelationships relationships; private String url; private Builder() { } /** * Fill a builder with attribute values from the provided {@code org.cloudfoundry.client.v3.Resource} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(Resource instance) { Objects.requireNonNull(instance, "instance"); from((short) 0, (Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code org.cloudfoundry.client.v3.routes.Route} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(Route instance) { Objects.requireNonNull(instance, "instance"); from((short) 0, (Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code CreateRouteResponse} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(CreateRouteResponse instance) { Objects.requireNonNull(instance, "instance"); from((short) 0, (Object) instance); return this; } /** * Copy abstract value type {@code _CreateRouteResponse} instance into builder. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(_CreateRouteResponse instance) { Objects.requireNonNull(instance, "instance"); from((short) 0, (Object) instance); return this; } private void from(short _unused, Object object) { long bits = 0; if (object instanceof Resource) { Resource instance = (Resource) object; if ((bits & 0x8L) == 0) { createdAt(instance.getCreatedAt()); bits |= 0x8L; } if ((bits & 0x200L) == 0) { putAllLinks(instance.getLinks()); bits |= 0x200L; } if ((bits & 0x400L) == 0) { id(instance.getId()); bits |= 0x400L; } if ((bits & 0x800L) == 0) { String updatedAtValue = instance.getUpdatedAt(); if (updatedAtValue != null) { updatedAt(updatedAtValue); } bits |= 0x800L; } } if (object instanceof Route) { Route instance = (Route) object; if ((bits & 0x8L) == 0) { createdAt(instance.getCreatedAt()); bits |= 0x8L; } if ((bits & 0x10L) == 0) { path(instance.getPath()); bits |= 0x10L; } if ((bits & 0x20L) == 0) { relationships(instance.getRelationships()); bits |= 0x20L; } if ((bits & 0x1L) == 0) { Metadata metadataValue = instance.getMetadata(); if (metadataValue != null) { metadata(metadataValue); } bits |= 0x1L; } if ((bits & 0x40L) == 0) { Protocol protocolValue = instance.getProtocol(); if (protocolValue != null) { protocol(protocolValue); } bits |= 0x40L; } if ((bits & 0x80L) == 0) { Integer portValue = instance.getPort(); if (portValue != null) { port(portValue); } bits |= 0x80L; } if ((bits & 0x2L) == 0) { List destinationsValue = instance.getDestinations(); if (destinationsValue != null) { addAllDestinations(destinationsValue); } bits |= 0x2L; } if ((bits & 0x100L) == 0) { host(instance.getHost()); bits |= 0x100L; } if ((bits & 0x200L) == 0) { putAllLinks(instance.getLinks()); bits |= 0x200L; } if ((bits & 0x400L) == 0) { id(instance.getId()); bits |= 0x400L; } if ((bits & 0x4L) == 0) { url(instance.getUrl()); bits |= 0x4L; } if ((bits & 0x800L) == 0) { String updatedAtValue = instance.getUpdatedAt(); if (updatedAtValue != null) { updatedAt(updatedAtValue); } bits |= 0x800L; } } if (object instanceof org.cloudfoundry.client.v3.routes._CreateRouteResponse) { org.cloudfoundry.client.v3.routes._CreateRouteResponse instance = (org.cloudfoundry.client.v3.routes._CreateRouteResponse) object; if ((bits & 0x10L) == 0) { path(instance.getPath()); bits |= 0x10L; } if ((bits & 0x20L) == 0) { relationships(instance.getRelationships()); bits |= 0x20L; } if ((bits & 0x1L) == 0) { Metadata metadataValue = instance.getMetadata(); if (metadataValue != null) { metadata(metadataValue); } bits |= 0x1L; } if ((bits & 0x40L) == 0) { Protocol protocolValue = instance.getProtocol(); if (protocolValue != null) { protocol(protocolValue); } bits |= 0x40L; } if ((bits & 0x80L) == 0) { Integer portValue = instance.getPort(); if (portValue != null) { port(portValue); } bits |= 0x80L; } if ((bits & 0x2L) == 0) { List destinationsValue = instance.getDestinations(); if (destinationsValue != null) { addAllDestinations(destinationsValue); } bits |= 0x2L; } if ((bits & 0x100L) == 0) { host(instance.getHost()); bits |= 0x100L; } if ((bits & 0x4L) == 0) { url(instance.getUrl()); bits |= 0x4L; } } } /** * Initializes the value for the {@link CreateRouteResponse#getCreatedAt() createdAt} attribute. * @param createdAt The value for createdAt * @return {@code this} builder for use in a chained invocation */ @JsonProperty("created_at") public final Builder createdAt(String createdAt) { this.createdAt = Objects.requireNonNull(createdAt, "createdAt"); initBits &= ~INIT_BIT_CREATED_AT; return this; } /** * Initializes the value for the {@link CreateRouteResponse#getId() id} attribute. * @param id The value for id * @return {@code this} builder for use in a chained invocation */ @JsonProperty("guid") public final Builder id(String id) { this.id = Objects.requireNonNull(id, "id"); initBits &= ~INIT_BIT_ID; return this; } /** * Put one entry to the {@link CreateRouteResponse#getLinks() links} map. * @param key The key in the links map * @param value The associated value in the links map * @return {@code this} builder for use in a chained invocation */ public final Builder link(String key, Link value) { this.links.put(key, value); return this; } /** * Put one entry to the {@link CreateRouteResponse#getLinks() links} 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 link(Map.Entry entry) { String k = entry.getKey(); Link v = entry.getValue(); this.links.put(k, v); return this; } /** * Sets or replaces all mappings from the specified map as entries for the {@link CreateRouteResponse#getLinks() links} map. Nulls are not permitted * @param entries The entries that will be added to the links map * @return {@code this} builder for use in a chained invocation */ @JsonProperty("links") public final Builder links(Map entries) { this.links.clear(); return putAllLinks(entries); } /** * Put all mappings from the specified map as entries to {@link CreateRouteResponse#getLinks() links} map. Nulls are not permitted * @param entries The entries that will be added to the links map * @return {@code this} builder for use in a chained invocation */ public final Builder putAllLinks(Map entries) { for (Map.Entry e : entries.entrySet()) { String k = e.getKey(); Link v = e.getValue(); this.links.put(k, v); } return this; } /** * Initializes the value for the {@link CreateRouteResponse#getUpdatedAt() updatedAt} attribute. * @param updatedAt The value for updatedAt (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @JsonProperty("updated_at") public final Builder updatedAt(@Nullable String updatedAt) { this.updatedAt = updatedAt; return this; } /** * Adds one element to {@link CreateRouteResponse#getDestinations() destinations} list. * @param element A destinations element * @return {@code this} builder for use in a chained invocation */ public final Builder destination(Destination element) { if (this.destinations == null) { this.destinations = new ArrayList(); } this.destinations.add(Objects.requireNonNull(element, "destinations element")); return this; } /** * Adds elements to {@link CreateRouteResponse#getDestinations() destinations} list. * @param elements An array of destinations elements * @return {@code this} builder for use in a chained invocation */ public final Builder destinations(Destination... elements) { if (this.destinations == null) { this.destinations = new ArrayList(); } for (Destination element : elements) { this.destinations.add(Objects.requireNonNull(element, "destinations element")); } return this; } /** * Sets or replaces all elements for {@link CreateRouteResponse#getDestinations() destinations} list. * @param elements An iterable of destinations elements * @return {@code this} builder for use in a chained invocation */ @JsonProperty("destinations") public final Builder destinations(@Nullable Iterable elements) { if (elements == null) { this.destinations = null; return this; } this.destinations = new ArrayList(); return addAllDestinations(elements); } /** * Adds elements to {@link CreateRouteResponse#getDestinations() destinations} list. * @param elements An iterable of destinations elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllDestinations(Iterable elements) { Objects.requireNonNull(elements, "destinations element"); if (this.destinations == null) { this.destinations = new ArrayList(); } for (Destination element : elements) { this.destinations.add(Objects.requireNonNull(element, "destinations element")); } return this; } /** * Initializes the value for the {@link CreateRouteResponse#getHost() host} attribute. * @param host The value for host * @return {@code this} builder for use in a chained invocation */ @JsonProperty("host") public final Builder host(String host) { this.host = Objects.requireNonNull(host, "host"); initBits &= ~INIT_BIT_HOST; return this; } /** * Initializes the value for the {@link CreateRouteResponse#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 Metadata metadata) { this.metadata = metadata; return this; } /** * Initializes the value for the {@link CreateRouteResponse#getPath() path} attribute. * @param path The value for path * @return {@code this} builder for use in a chained invocation */ @JsonProperty("path") public final Builder path(String path) { this.path = Objects.requireNonNull(path, "path"); initBits &= ~INIT_BIT_PATH; return this; } /** * Initializes the value for the {@link CreateRouteResponse#getPort() port} attribute. * @param port The value for port (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @JsonProperty("port") public final Builder port(@Nullable Integer port) { this.port = port; return this; } /** * Initializes the value for the {@link CreateRouteResponse#getProtocol() protocol} attribute. * @param protocol The value for protocol (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @JsonProperty("protocol") public final Builder protocol(@Nullable Protocol protocol) { this.protocol = protocol; return this; } /** * Initializes the value for the {@link CreateRouteResponse#getRelationships() relationships} attribute. * @param relationships The value for relationships * @return {@code this} builder for use in a chained invocation */ @JsonProperty("relationships") public final Builder relationships(RouteRelationships relationships) { this.relationships = Objects.requireNonNull(relationships, "relationships"); initBits &= ~INIT_BIT_RELATIONSHIPS; return this; } /** * Initializes the value for the {@link CreateRouteResponse#getUrl() url} attribute. * @param url The value for url * @return {@code this} builder for use in a chained invocation */ @JsonProperty("url") public final Builder url(String url) { this.url = Objects.requireNonNull(url, "url"); initBits &= ~INIT_BIT_URL; return this; } /** * Builds a new {@link CreateRouteResponse CreateRouteResponse}. * @return An immutable instance of CreateRouteResponse * @throws java.lang.IllegalStateException if any required attributes are missing */ public CreateRouteResponse build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new CreateRouteResponse(this); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_CREATED_AT) != 0) attributes.add("createdAt"); if ((initBits & INIT_BIT_ID) != 0) attributes.add("id"); if ((initBits & INIT_BIT_HOST) != 0) attributes.add("host"); if ((initBits & INIT_BIT_PATH) != 0) attributes.add("path"); if ((initBits & INIT_BIT_RELATIONSHIPS) != 0) attributes.add("relationships"); if ((initBits & INIT_BIT_URL) != 0) attributes.add("url"); return "Cannot build CreateRouteResponse, 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<>(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 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, 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 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); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy