
com.hubspot.slack.client.models.response.migration.MigrationExchangeResponse Maven / Gradle / Ivy
package com.hubspot.slack.client.models.response.migration;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.hubspot.immutables.validation.InvalidImmutableStateException;
import com.hubspot.slack.client.models.response.*;
import com.hubspot.slack.client.models.response.SlackResponse;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link MigrationExchangeResponseIF}.
*
* Use the builder to create immutable instances:
* {@code MigrationExchangeResponse.builder()}.
*/
@Generated(from = "MigrationExchangeResponseIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class MigrationExchangeResponse
implements MigrationExchangeResponseIF {
private final boolean ok;
private final @Nullable ResponseMetadata responseMetadata;
private final String teamId;
private final String enterpriseId;
private final Map userIdMap;
private final Set invalidUserIds;
private MigrationExchangeResponse(
boolean ok,
@Nullable ResponseMetadata responseMetadata,
String teamId,
String enterpriseId,
Map userIdMap,
Set invalidUserIds) {
this.ok = ok;
this.responseMetadata = responseMetadata;
this.teamId = teamId;
this.enterpriseId = enterpriseId;
this.userIdMap = userIdMap;
this.invalidUserIds = invalidUserIds;
}
/**
* @return The value of the {@code ok} attribute
*/
@JsonProperty
@Override
public boolean isOk() {
return ok;
}
/**
* @return The value of the {@code responseMetadata} attribute
*/
@JsonProperty("response_metadata")
@Override
public Optional getResponseMetadata() {
return Optional.ofNullable(responseMetadata);
}
/**
* @return The value of the {@code teamId} attribute
*/
@JsonProperty
@Override
public String getTeamId() {
return teamId;
}
/**
* @return The value of the {@code enterpriseId} attribute
*/
@JsonProperty
@Override
public String getEnterpriseId() {
return enterpriseId;
}
/**
* @return The value of the {@code userIdMap} attribute
*/
@JsonProperty
@Override
public Map getUserIdMap() {
return userIdMap;
}
/**
* @return The value of the {@code invalidUserIds} attribute
*/
@JsonProperty
@Override
public Set getInvalidUserIds() {
return invalidUserIds;
}
/**
* Copy the current immutable object by setting a value for the {@link MigrationExchangeResponseIF#isOk() ok} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for ok
* @return A modified copy of the {@code this} object
*/
public final MigrationExchangeResponse withOk(boolean value) {
if (this.ok == value) return this;
return new MigrationExchangeResponse(
value,
this.responseMetadata,
this.teamId,
this.enterpriseId,
this.userIdMap,
this.invalidUserIds);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MigrationExchangeResponseIF#getResponseMetadata() responseMetadata} attribute.
* @param value The value for responseMetadata, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final MigrationExchangeResponse withResponseMetadata(@Nullable ResponseMetadata value) {
@Nullable ResponseMetadata newValue = value;
if (this.responseMetadata == newValue) return this;
return new MigrationExchangeResponse(this.ok, newValue, this.teamId, this.enterpriseId, this.userIdMap, this.invalidUserIds);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MigrationExchangeResponseIF#getResponseMetadata() responseMetadata} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for responseMetadata
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final MigrationExchangeResponse withResponseMetadata(Optional extends ResponseMetadata> optional) {
@Nullable ResponseMetadata value = optional.orElse(null);
if (this.responseMetadata == value) return this;
return new MigrationExchangeResponse(this.ok, value, this.teamId, this.enterpriseId, this.userIdMap, this.invalidUserIds);
}
/**
* Copy the current immutable object by setting a value for the {@link MigrationExchangeResponseIF#getTeamId() teamId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for teamId
* @return A modified copy of the {@code this} object
*/
public final MigrationExchangeResponse withTeamId(String value) {
String newValue = Objects.requireNonNull(value, "teamId");
if (this.teamId.equals(newValue)) return this;
return new MigrationExchangeResponse(
this.ok,
this.responseMetadata,
newValue,
this.enterpriseId,
this.userIdMap,
this.invalidUserIds);
}
/**
* Copy the current immutable object by setting a value for the {@link MigrationExchangeResponseIF#getEnterpriseId() enterpriseId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for enterpriseId
* @return A modified copy of the {@code this} object
*/
public final MigrationExchangeResponse withEnterpriseId(String value) {
String newValue = Objects.requireNonNull(value, "enterpriseId");
if (this.enterpriseId.equals(newValue)) return this;
return new MigrationExchangeResponse(this.ok, this.responseMetadata, this.teamId, newValue, this.userIdMap, this.invalidUserIds);
}
/**
* Copy the current immutable object by replacing the {@link MigrationExchangeResponseIF#getUserIdMap() userIdMap} map with the specified map.
* Nulls are not permitted as keys or values.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param entries The entries to be added to the userIdMap map
* @return A modified copy of {@code this} object
*/
public final MigrationExchangeResponse withUserIdMap(Map entries) {
if (this.userIdMap == entries) return this;
Map newValue = createUnmodifiableMap(true, false, entries);
return new MigrationExchangeResponse(this.ok, this.responseMetadata, this.teamId, this.enterpriseId, newValue, this.invalidUserIds);
}
/**
* Copy the current immutable object with elements that replace the content of {@link MigrationExchangeResponseIF#getInvalidUserIds() invalidUserIds}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final MigrationExchangeResponse withInvalidUserIds(String... elements) {
Set newValue = createUnmodifiableSet(createSafeList(Arrays.asList(elements), true, false));
return new MigrationExchangeResponse(this.ok, this.responseMetadata, this.teamId, this.enterpriseId, this.userIdMap, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link MigrationExchangeResponseIF#getInvalidUserIds() invalidUserIds}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of invalidUserIds elements to set
* @return A modified copy of {@code this} object
*/
public final MigrationExchangeResponse withInvalidUserIds(Iterable elements) {
if (this.invalidUserIds == elements) return this;
Set newValue = createUnmodifiableSet(createSafeList(elements, true, false));
return new MigrationExchangeResponse(this.ok, this.responseMetadata, this.teamId, this.enterpriseId, this.userIdMap, newValue);
}
/**
* This instance is equal to all instances of {@code MigrationExchangeResponse} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(@Nullable Object another) {
if (this == another) return true;
return another instanceof MigrationExchangeResponse
&& equalTo(0, (MigrationExchangeResponse) another);
}
private boolean equalTo(int synthetic, MigrationExchangeResponse another) {
return ok == another.ok
&& Objects.equals(responseMetadata, another.responseMetadata)
&& teamId.equals(another.teamId)
&& enterpriseId.equals(another.enterpriseId)
&& userIdMap.equals(another.userIdMap)
&& invalidUserIds.equals(another.invalidUserIds);
}
/**
* Computes a hash code from attributes: {@code ok}, {@code responseMetadata}, {@code teamId}, {@code enterpriseId}, {@code userIdMap}, {@code invalidUserIds}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Boolean.hashCode(ok);
h += (h << 5) + Objects.hashCode(responseMetadata);
h += (h << 5) + teamId.hashCode();
h += (h << 5) + enterpriseId.hashCode();
h += (h << 5) + userIdMap.hashCode();
h += (h << 5) + invalidUserIds.hashCode();
return h;
}
/**
* Prints the immutable value {@code MigrationExchangeResponse} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("MigrationExchangeResponse{");
builder.append("ok=").append(ok);
if (responseMetadata != null) {
builder.append(", ");
builder.append("responseMetadata=").append(responseMetadata);
}
builder.append(", ");
builder.append("teamId=").append(teamId);
builder.append(", ");
builder.append("enterpriseId=").append(enterpriseId);
builder.append(", ");
builder.append("userIdMap=").append(userIdMap);
builder.append(", ");
builder.append("invalidUserIds=").append(invalidUserIds);
return builder.append("}").toString();
}
/**
* 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 = "MigrationExchangeResponseIF", generator = "Immutables")
@Deprecated
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json
implements MigrationExchangeResponseIF {
boolean ok;
boolean okIsSet;
@Nullable Optional responseMetadata = Optional.empty();
@Nullable String teamId;
@Nullable String enterpriseId;
@Nullable Map userIdMap = Collections.emptyMap();
@Nullable Set invalidUserIds = Collections.emptySet();
@JsonProperty
public void setOk(boolean ok) {
this.ok = ok;
this.okIsSet = true;
}
@JsonProperty("response_metadata")
public void setResponseMetadata(Optional responseMetadata) {
this.responseMetadata = responseMetadata;
}
@JsonProperty
public void setTeamId(String teamId) {
this.teamId = teamId;
}
@JsonProperty
public void setEnterpriseId(String enterpriseId) {
this.enterpriseId = enterpriseId;
}
@JsonProperty
public void setUserIdMap(Map userIdMap) {
this.userIdMap = userIdMap;
}
@JsonProperty
public void setInvalidUserIds(Set invalidUserIds) {
this.invalidUserIds = invalidUserIds;
}
@Override
public boolean isOk() { throw new UnsupportedOperationException(); }
@Override
public Optional getResponseMetadata() { throw new UnsupportedOperationException(); }
@Override
public String getTeamId() { throw new UnsupportedOperationException(); }
@Override
public String getEnterpriseId() { throw new UnsupportedOperationException(); }
@Override
public Map getUserIdMap() { throw new UnsupportedOperationException(); }
@Override
public Set getInvalidUserIds() { 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 MigrationExchangeResponse fromJson(Json json) {
MigrationExchangeResponse.Builder builder = MigrationExchangeResponse.builder();
if (json.okIsSet) {
builder.setOk(json.ok);
}
if (json.responseMetadata != null) {
builder.setResponseMetadata(json.responseMetadata);
}
if (json.teamId != null) {
builder.setTeamId(json.teamId);
}
if (json.enterpriseId != null) {
builder.setEnterpriseId(json.enterpriseId);
}
if (json.userIdMap != null) {
builder.putAllUserIdMap(json.userIdMap);
}
if (json.invalidUserIds != null) {
builder.addAllInvalidUserIds(json.invalidUserIds);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link MigrationExchangeResponseIF} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param instance The instance to copy
* @return A copied immutable MigrationExchangeResponse instance
*/
public static MigrationExchangeResponse copyOf(MigrationExchangeResponseIF instance) {
if (instance instanceof MigrationExchangeResponse) {
return (MigrationExchangeResponse) instance;
}
return MigrationExchangeResponse.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link MigrationExchangeResponse MigrationExchangeResponse}.
*
* MigrationExchangeResponse.builder()
* .setOk(boolean) // required {@link MigrationExchangeResponseIF#isOk() ok}
* .setResponseMetadata(ResponseMetadata) // optional {@link MigrationExchangeResponseIF#getResponseMetadata() responseMetadata}
* .setTeamId(String) // required {@link MigrationExchangeResponseIF#getTeamId() teamId}
* .setEnterpriseId(String) // required {@link MigrationExchangeResponseIF#getEnterpriseId() enterpriseId}
* .putUserIdMap|putAllUserIdMap(String => String) // {@link MigrationExchangeResponseIF#getUserIdMap() userIdMap} mappings
* .addInvalidUserIds|addAllInvalidUserIds(String) // {@link MigrationExchangeResponseIF#getInvalidUserIds() invalidUserIds} elements
* .build();
*
* @return A new MigrationExchangeResponse builder
*/
public static MigrationExchangeResponse.Builder builder() {
return new MigrationExchangeResponse.Builder();
}
/**
* Builds instances of type {@link MigrationExchangeResponse MigrationExchangeResponse}.
* 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 = "MigrationExchangeResponseIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_OK = 0x1L;
private static final long INIT_BIT_TEAM_ID = 0x2L;
private static final long INIT_BIT_ENTERPRISE_ID = 0x4L;
private long initBits = 0x7L;
private boolean ok;
private @Nullable ResponseMetadata responseMetadata;
private @Nullable String teamId;
private @Nullable String enterpriseId;
private Map userIdMap = new LinkedHashMap();
private List invalidUserIds = new ArrayList();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.hubspot.slack.client.models.response.migration.MigrationExchangeResponseIF} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(MigrationExchangeResponseIF instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.hubspot.slack.client.models.response.SlackResponse} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(SlackResponse 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 MigrationExchangeResponseIF) {
MigrationExchangeResponseIF instance = (MigrationExchangeResponseIF) object;
putAllUserIdMap(instance.getUserIdMap());
addAllInvalidUserIds(instance.getInvalidUserIds());
if ((bits & 0x1L) == 0) {
Optional responseMetadataOptional = instance.getResponseMetadata();
if (responseMetadataOptional.isPresent()) {
setResponseMetadata(responseMetadataOptional);
}
bits |= 0x1L;
}
this.setEnterpriseId(instance.getEnterpriseId());
if ((bits & 0x2L) == 0) {
this.setOk(instance.isOk());
bits |= 0x2L;
}
this.setTeamId(instance.getTeamId());
}
if (object instanceof SlackResponse) {
SlackResponse instance = (SlackResponse) object;
if ((bits & 0x2L) == 0) {
this.setOk(instance.isOk());
bits |= 0x2L;
}
if ((bits & 0x1L) == 0) {
Optional responseMetadataOptional = instance.getResponseMetadata();
if (responseMetadataOptional.isPresent()) {
setResponseMetadata(responseMetadataOptional);
}
bits |= 0x1L;
}
}
}
/**
* Initializes the value for the {@link MigrationExchangeResponseIF#isOk() ok} attribute.
* @param ok The value for ok
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setOk(boolean ok) {
this.ok = ok;
initBits &= ~INIT_BIT_OK;
return this;
}
/**
* Initializes the optional value {@link MigrationExchangeResponseIF#getResponseMetadata() responseMetadata} to responseMetadata.
* @param responseMetadata The value for responseMetadata, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setResponseMetadata(@Nullable ResponseMetadata responseMetadata) {
this.responseMetadata = responseMetadata;
return this;
}
/**
* Initializes the optional value {@link MigrationExchangeResponseIF#getResponseMetadata() responseMetadata} to responseMetadata.
* @param responseMetadata The value for responseMetadata
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setResponseMetadata(Optional extends ResponseMetadata> responseMetadata) {
this.responseMetadata = responseMetadata.orElse(null);
return this;
}
/**
* Initializes the value for the {@link MigrationExchangeResponseIF#getTeamId() teamId} attribute.
* @param teamId The value for teamId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setTeamId(String teamId) {
this.teamId = Objects.requireNonNull(teamId, "teamId");
initBits &= ~INIT_BIT_TEAM_ID;
return this;
}
/**
* Initializes the value for the {@link MigrationExchangeResponseIF#getEnterpriseId() enterpriseId} attribute.
* @param enterpriseId The value for enterpriseId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setEnterpriseId(String enterpriseId) {
this.enterpriseId = Objects.requireNonNull(enterpriseId, "enterpriseId");
initBits &= ~INIT_BIT_ENTERPRISE_ID;
return this;
}
/**
* Put one entry to the {@link MigrationExchangeResponseIF#getUserIdMap() userIdMap} map.
* @param key The key in the userIdMap map
* @param value The associated value in the userIdMap map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putUserIdMap(String key, String value) {
this.userIdMap.put(
Objects.requireNonNull(key, "userIdMap key"),
Objects.requireNonNull(value, value == null ? "userIdMap value for key: " + key : null));
return this;
}
/**
* Put one entry to the {@link MigrationExchangeResponseIF#getUserIdMap() userIdMap} 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 putUserIdMap(Map.Entry entry) {
String k = entry.getKey();
String v = entry.getValue();
this.userIdMap.put(
Objects.requireNonNull(k, "userIdMap key"),
Objects.requireNonNull(v, v == null ? "userIdMap value for key: " + k : null));
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link MigrationExchangeResponseIF#getUserIdMap() userIdMap} map. Nulls are not permitted
* @param entries The entries that will be added to the userIdMap map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setUserIdMap(Map entries) {
this.userIdMap.clear();
return putAllUserIdMap(entries);
}
/**
* Put all mappings from the specified map as entries to {@link MigrationExchangeResponseIF#getUserIdMap() userIdMap} map. Nulls are not permitted
* @param entries The entries that will be added to the userIdMap map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putAllUserIdMap(Map entries) {
for (Map.Entry e : entries.entrySet()) {
String k = e.getKey();
String v = e.getValue();
this.userIdMap.put(
Objects.requireNonNull(k, "userIdMap key"),
Objects.requireNonNull(v, v == null ? "userIdMap value for key: " + k : null));
}
return this;
}
/**
* Adds one element to {@link MigrationExchangeResponseIF#getInvalidUserIds() invalidUserIds} set.
* @param element A invalidUserIds element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addInvalidUserIds(String element) {
this.invalidUserIds.add(Objects.requireNonNull(element, "invalidUserIds element"));
return this;
}
/**
* Adds elements to {@link MigrationExchangeResponseIF#getInvalidUserIds() invalidUserIds} set.
* @param elements An array of invalidUserIds elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addInvalidUserIds(String... elements) {
for (String element : elements) {
this.invalidUserIds.add(Objects.requireNonNull(element, "invalidUserIds element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link MigrationExchangeResponseIF#getInvalidUserIds() invalidUserIds} set.
* @param elements An iterable of invalidUserIds elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setInvalidUserIds(Iterable elements) {
this.invalidUserIds.clear();
return addAllInvalidUserIds(elements);
}
/**
* Adds elements to {@link MigrationExchangeResponseIF#getInvalidUserIds() invalidUserIds} set.
* @param elements An iterable of invalidUserIds elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllInvalidUserIds(Iterable elements) {
for (String element : elements) {
this.invalidUserIds.add(Objects.requireNonNull(element, "invalidUserIds element"));
}
return this;
}
/**
* Builds a new {@link MigrationExchangeResponse MigrationExchangeResponse}.
* @return An immutable instance of MigrationExchangeResponse
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public MigrationExchangeResponse build() {
checkRequiredAttributes();
return new MigrationExchangeResponse(
ok,
responseMetadata,
teamId,
enterpriseId,
createUnmodifiableMap(false, false, userIdMap),
createUnmodifiableSet(invalidUserIds));
}
private boolean okIsSet() {
return (initBits & INIT_BIT_OK) == 0;
}
private boolean teamIdIsSet() {
return (initBits & INIT_BIT_TEAM_ID) == 0;
}
private boolean enterpriseIdIsSet() {
return (initBits & INIT_BIT_ENTERPRISE_ID) == 0;
}
private void checkRequiredAttributes() {
if (initBits != 0) {
throw new InvalidImmutableStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if (!okIsSet()) attributes.add("ok");
if (!teamIdIsSet()) attributes.add("teamId");
if (!enterpriseIdIsSet()) attributes.add("enterpriseId");
return "Cannot build MigrationExchangeResponse, 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;
}
/** Unmodifiable set constructed from list to avoid rehashing. */
private static Set createUnmodifiableSet(List list) {
switch(list.size()) {
case 0: return Collections.emptySet();
case 1: return Collections.singleton(list.get(0));
default:
Set set = new LinkedHashSet<>(list.size() * 4 / 3 + 1);
set.addAll(list);
return Collections.unmodifiableSet(set);
}
}
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 (java.util.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) {
java.util.Objects.requireNonNull(k, "key");
java.util.Objects.requireNonNull(v, v == null ? "value for key: " + k : null);
}
linkedMap.put(k, v);
}
} else {
linkedMap.putAll(map);
}
return java.util.Collections.unmodifiableMap(linkedMap);
}
}
}
}