org.cloudfoundry.client.v3.routes.InsertRouteDestinationsResponse Maven / Gradle / Ivy
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.client.v3.Link;
import org.immutables.value.Generated;
/**
* The response payload for the Insert Route Destinations operation
*/
@Generated(from = "_InsertRouteDestinationsResponse", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class InsertRouteDestinationsResponse
extends org.cloudfoundry.client.v3.routes._InsertRouteDestinationsResponse {
private final Map links;
private final List destinations;
private InsertRouteDestinationsResponse(InsertRouteDestinationsResponse.Builder builder) {
this.links = createUnmodifiableMap(false, false, builder.links);
this.destinations = createUnmodifiableList(true, builder.destinations);
}
/**
* Links to related resources and actions for the resource
*/
@JsonProperty("links")
@Override
public Map getLinks() {
return links;
}
/**
* The destinations
*/
@JsonProperty("destinations")
@Override
public List getDestinations() {
return destinations;
}
/**
* This instance is equal to all instances of {@code InsertRouteDestinationsResponse} 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 InsertRouteDestinationsResponse
&& equalTo(0, (InsertRouteDestinationsResponse) another);
}
private boolean equalTo(int synthetic, InsertRouteDestinationsResponse another) {
return links.equals(another.links)
&& destinations.equals(another.destinations);
}
/**
* Computes a hash code from attributes: {@code links}, {@code destinations}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + links.hashCode();
h += (h << 5) + destinations.hashCode();
return h;
}
/**
* Prints the immutable value {@code InsertRouteDestinationsResponse} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "InsertRouteDestinationsResponse{"
+ "links=" + links
+ ", destinations=" + destinations
+ "}";
}
/**
* 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 = "_InsertRouteDestinationsResponse", generator = "Immutables")
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends org.cloudfoundry.client.v3.routes._InsertRouteDestinationsResponse {
Map links = Collections.emptyMap();
List destinations = Collections.emptyList();
@JsonProperty("links")
public void setLinks(Map links) {
this.links = links;
}
@JsonProperty("destinations")
public void setDestinations(List destinations) {
this.destinations = destinations;
}
@Override
public Map getLinks() { throw new UnsupportedOperationException(); }
@Override
public List getDestinations() { 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 InsertRouteDestinationsResponse fromJson(Json json) {
InsertRouteDestinationsResponse.Builder builder = InsertRouteDestinationsResponse.builder();
if (json.links != null) {
builder.putAllLinks(json.links);
}
if (json.destinations != null) {
builder.addAllDestinations(json.destinations);
}
return builder.build();
}
/**
* Creates a builder for {@link InsertRouteDestinationsResponse InsertRouteDestinationsResponse}.
*
* InsertRouteDestinationsResponse.builder()
* .link|putAllLinks(String => org.cloudfoundry.client.v3.Link) // {@link InsertRouteDestinationsResponse#getLinks() links} mappings
* .destination|addAllDestinations(Destination) // {@link InsertRouteDestinationsResponse#getDestinations() destinations} elements
* .build();
*
* @return A new InsertRouteDestinationsResponse builder
*/
public static InsertRouteDestinationsResponse.Builder builder() {
return new InsertRouteDestinationsResponse.Builder();
}
/**
* Builds instances of type {@link InsertRouteDestinationsResponse InsertRouteDestinationsResponse}.
* 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 = "_InsertRouteDestinationsResponse", generator = "Immutables")
public static final class Builder {
private Map links = new LinkedHashMap();
private List destinations = new ArrayList();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code org.cloudfoundry.client.v3.routes.RouteDestinations} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(RouteDestinations instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code InsertRouteDestinationsResponse} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(InsertRouteDestinationsResponse instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
/**
* Copy abstract value type {@code _InsertRouteDestinationsResponse} 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(_InsertRouteDestinationsResponse instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
private void from(short _unused, Object object) {
if (object instanceof RouteDestinations) {
RouteDestinations instance = (RouteDestinations) object;
putAllLinks(instance.getLinks());
addAllDestinations(instance.getDestinations());
}
}
/**
* Put one entry to the {@link InsertRouteDestinationsResponse#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 InsertRouteDestinationsResponse#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 InsertRouteDestinationsResponse#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 InsertRouteDestinationsResponse#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;
}
/**
* Adds one element to {@link InsertRouteDestinationsResponse#getDestinations() destinations} list.
* @param element A destinations element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder destination(Destination element) {
this.destinations.add(Objects.requireNonNull(element, "destinations element"));
return this;
}
/**
* Adds elements to {@link InsertRouteDestinationsResponse#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) {
for (Destination element : elements) {
this.destinations.add(Objects.requireNonNull(element, "destinations element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link InsertRouteDestinationsResponse#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(Iterable extends Destination> elements) {
this.destinations.clear();
return addAllDestinations(elements);
}
/**
* Adds elements to {@link InsertRouteDestinationsResponse#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 extends Destination> elements) {
for (Destination element : elements) {
this.destinations.add(Objects.requireNonNull(element, "destinations element"));
}
return this;
}
/**
* Builds a new {@link InsertRouteDestinationsResponse InsertRouteDestinationsResponse}.
* @return An immutable instance of InsertRouteDestinationsResponse
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public InsertRouteDestinationsResponse build() {
return new InsertRouteDestinationsResponse(this);
}
}
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);
}
}
}
}