
com.hubspot.slack.client.methods.params.migration.MigrationExchangeParams Maven / Gradle / Ivy
package com.hubspot.slack.client.methods.params.migration;
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 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.LinkedHashSet;
import java.util.List;
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 MigrationExchangeParamsIF}.
*
* Use the builder to create immutable instances:
* {@code MigrationExchangeParams.builder()}.
*/
@Generated(from = "MigrationExchangeParamsIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class MigrationExchangeParams
implements MigrationExchangeParamsIF {
private final @Nullable String teamId;
private final @Nullable Boolean toOld;
private final Set userIds;
private MigrationExchangeParams(
@Nullable String teamId,
@Nullable Boolean toOld,
Set userIds) {
this.teamId = teamId;
this.toOld = toOld;
this.userIds = userIds;
}
/**
* @return The value of the {@code teamId} attribute
*/
@JsonProperty
@Override
public Optional getTeamId() {
return Optional.ofNullable(teamId);
}
/**
* @return The value of the {@code toOld} attribute
*/
@JsonProperty
@Override
public Optional getToOld() {
return Optional.ofNullable(toOld);
}
/**
* @return The value of the {@code userIds} attribute
*/
@JsonProperty
@JsonIgnore
@Override
public Set getUserIds() {
return userIds;
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MigrationExchangeParamsIF#getTeamId() teamId} attribute.
* @param value The value for teamId, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final MigrationExchangeParams withTeamId(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.teamId, newValue)) return this;
return new MigrationExchangeParams(newValue, this.toOld, this.userIds);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MigrationExchangeParamsIF#getTeamId() teamId} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for teamId
* @return A modified copy of {@code this} object
*/
public final MigrationExchangeParams withTeamId(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.teamId, value)) return this;
return new MigrationExchangeParams(value, this.toOld, this.userIds);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link MigrationExchangeParamsIF#getToOld() toOld} attribute.
* @param value The value for toOld, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final MigrationExchangeParams withToOld(@Nullable Boolean value) {
@Nullable Boolean newValue = value;
if (Objects.equals(this.toOld, newValue)) return this;
return new MigrationExchangeParams(this.teamId, newValue, this.userIds);
}
/**
* Copy the current immutable object by setting an optional value for the {@link MigrationExchangeParamsIF#getToOld() toOld} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for toOld
* @return A modified copy of {@code this} object
*/
public final MigrationExchangeParams withToOld(Optional optional) {
@Nullable Boolean value = optional.orElse(null);
if (Objects.equals(this.toOld, value)) return this;
return new MigrationExchangeParams(this.teamId, value, this.userIds);
}
/**
* Copy the current immutable object with elements that replace the content of {@link MigrationExchangeParamsIF#getUserIds() userIds}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final MigrationExchangeParams withUserIds(String... elements) {
Set newValue = createUnmodifiableSet(createSafeList(Arrays.asList(elements), true, false));
return new MigrationExchangeParams(this.teamId, this.toOld, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link MigrationExchangeParamsIF#getUserIds() userIds}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of userIds elements to set
* @return A modified copy of {@code this} object
*/
public final MigrationExchangeParams withUserIds(Iterable elements) {
if (this.userIds == elements) return this;
Set newValue = createUnmodifiableSet(createSafeList(elements, true, false));
return new MigrationExchangeParams(this.teamId, this.toOld, newValue);
}
/**
* This instance is equal to all instances of {@code MigrationExchangeParams} 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 MigrationExchangeParams
&& equalTo(0, (MigrationExchangeParams) another);
}
private boolean equalTo(int synthetic, MigrationExchangeParams another) {
return Objects.equals(teamId, another.teamId)
&& Objects.equals(toOld, another.toOld)
&& userIds.equals(another.userIds);
}
/**
* Computes a hash code from attributes: {@code teamId}, {@code toOld}, {@code userIds}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(teamId);
h += (h << 5) + Objects.hashCode(toOld);
h += (h << 5) + userIds.hashCode();
return h;
}
/**
* Prints the immutable value {@code MigrationExchangeParams} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("MigrationExchangeParams{");
if (teamId != null) {
builder.append("teamId=").append(teamId);
}
if (toOld != null) {
if (builder.length() > 24) builder.append(", ");
builder.append("toOld=").append(toOld);
}
if (builder.length() > 24) builder.append(", ");
builder.append("userIds=").append(userIds);
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 = "MigrationExchangeParamsIF", generator = "Immutables")
@Deprecated
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json
implements MigrationExchangeParamsIF {
@Nullable Optional teamId = Optional.empty();
@Nullable Optional toOld = Optional.empty();
@Nullable Set userIds = Collections.emptySet();
@JsonProperty
public void setTeamId(Optional teamId) {
this.teamId = teamId;
}
@JsonProperty
public void setToOld(Optional toOld) {
this.toOld = toOld;
}
@JsonProperty
@JsonIgnore
public void setUserIds(Set userIds) {
this.userIds = userIds;
}
@Override
public Optional getTeamId() { throw new UnsupportedOperationException(); }
@Override
public Optional getToOld() { throw new UnsupportedOperationException(); }
@Override
public Set getUserIds() { 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 MigrationExchangeParams fromJson(Json json) {
MigrationExchangeParams.Builder builder = MigrationExchangeParams.builder();
if (json.teamId != null) {
builder.setTeamId(json.teamId);
}
if (json.toOld != null) {
builder.setToOld(json.toOld);
}
if (json.userIds != null) {
builder.addAllUserIds(json.userIds);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link MigrationExchangeParamsIF} 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 MigrationExchangeParams instance
*/
public static MigrationExchangeParams copyOf(MigrationExchangeParamsIF instance) {
if (instance instanceof MigrationExchangeParams) {
return (MigrationExchangeParams) instance;
}
return MigrationExchangeParams.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link MigrationExchangeParams MigrationExchangeParams}.
*
* MigrationExchangeParams.builder()
* .setTeamId(String) // optional {@link MigrationExchangeParamsIF#getTeamId() teamId}
* .setToOld(Boolean) // optional {@link MigrationExchangeParamsIF#getToOld() toOld}
* .addUserIds|addAllUserIds(String) // {@link MigrationExchangeParamsIF#getUserIds() userIds} elements
* .build();
*
* @return A new MigrationExchangeParams builder
*/
public static MigrationExchangeParams.Builder builder() {
return new MigrationExchangeParams.Builder();
}
/**
* Builds instances of type {@link MigrationExchangeParams MigrationExchangeParams}.
* 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 = "MigrationExchangeParamsIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private @Nullable String teamId;
private @Nullable Boolean toOld;
private List userIds = new ArrayList();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code MigrationExchangeParamsIF} 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(MigrationExchangeParamsIF instance) {
Objects.requireNonNull(instance, "instance");
Optional teamIdOptional = instance.getTeamId();
if (teamIdOptional.isPresent()) {
setTeamId(teamIdOptional);
}
Optional toOldOptional = instance.getToOld();
if (toOldOptional.isPresent()) {
setToOld(toOldOptional);
}
addAllUserIds(instance.getUserIds());
return this;
}
/**
* Initializes the optional value {@link MigrationExchangeParamsIF#getTeamId() teamId} to teamId.
* @param teamId The value for teamId, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setTeamId(@Nullable String teamId) {
this.teamId = teamId;
return this;
}
/**
* Initializes the optional value {@link MigrationExchangeParamsIF#getTeamId() teamId} to teamId.
* @param teamId The value for teamId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setTeamId(Optional teamId) {
this.teamId = teamId.orElse(null);
return this;
}
/**
* Initializes the optional value {@link MigrationExchangeParamsIF#getToOld() toOld} to toOld.
* @param toOld The value for toOld, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setToOld(@Nullable Boolean toOld) {
this.toOld = toOld;
return this;
}
/**
* Initializes the optional value {@link MigrationExchangeParamsIF#getToOld() toOld} to toOld.
* @param toOld The value for toOld
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setToOld(Optional toOld) {
this.toOld = toOld.orElse(null);
return this;
}
/**
* Adds one element to {@link MigrationExchangeParamsIF#getUserIds() userIds} set.
* @param element A userIds element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addUserIds(String element) {
this.userIds.add(Objects.requireNonNull(element, "userIds element"));
return this;
}
/**
* Adds elements to {@link MigrationExchangeParamsIF#getUserIds() userIds} set.
* @param elements An array of userIds elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addUserIds(String... elements) {
for (String element : elements) {
this.userIds.add(Objects.requireNonNull(element, "userIds element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link MigrationExchangeParamsIF#getUserIds() userIds} set.
* @param elements An iterable of userIds elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setUserIds(Iterable elements) {
this.userIds.clear();
return addAllUserIds(elements);
}
/**
* Adds elements to {@link MigrationExchangeParamsIF#getUserIds() userIds} set.
* @param elements An iterable of userIds elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllUserIds(Iterable elements) {
for (String element : elements) {
this.userIds.add(Objects.requireNonNull(element, "userIds element"));
}
return this;
}
/**
* Builds a new {@link MigrationExchangeParams MigrationExchangeParams}.
* @return An immutable instance of MigrationExchangeParams
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public MigrationExchangeParams build() {
return new MigrationExchangeParams(teamId, toOld, createUnmodifiableSet(userIds));
}
}
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);
}
}
}