
com.hubspot.slack.client.models.events.SlackEventWrapper Maven / Gradle / Ivy
package com.hubspot.slack.client.models.events;
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 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.List;
import java.util.Objects;
import java.util.Optional;
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 SlackEventWrapperIF}.
*
* Use the builder to create immutable instances:
* {@code SlackEventWrapper.builder()}.
*/
@Generated(from = "SlackEventWrapperIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class SlackEventWrapper
implements SlackEventWrapperIF {
private final String token;
private final String teamId;
private final @Nullable String contextTeamId;
private final SlackEventType type;
private final List authedUsers;
private final String eventId;
private final String eventTime;
private final T event;
private SlackEventWrapper(
String token,
String teamId,
@Nullable String contextTeamId,
SlackEventType type,
List authedUsers,
String eventId,
String eventTime,
T event) {
this.token = token;
this.teamId = teamId;
this.contextTeamId = contextTeamId;
this.type = type;
this.authedUsers = authedUsers;
this.eventId = eventId;
this.eventTime = eventTime;
this.event = event;
}
/**
* @return The value of the {@code token} attribute
*/
@JsonProperty
@Override
public String getToken() {
return token;
}
/**
* @return The value of the {@code teamId} attribute
*/
@JsonProperty
@Override
public String getTeamId() {
return teamId;
}
/**
* @return The value of the {@code contextTeamId} attribute
*/
@JsonProperty
@Override
public Optional getContextTeamId() {
return Optional.ofNullable(contextTeamId);
}
/**
* @return The value of the {@code type} attribute
*/
@JsonProperty
@Override
public SlackEventType getType() {
return type;
}
/**
* @return The value of the {@code authedUsers} attribute
*/
@JsonProperty
@Override
public List getAuthedUsers() {
return authedUsers;
}
/**
* @return The value of the {@code eventId} attribute
*/
@JsonProperty
@Override
public String getEventId() {
return eventId;
}
/**
* @return The value of the {@code eventTime} attribute
*/
@JsonProperty
@Override
public String getEventTime() {
return eventTime;
}
/**
* @return The value of the {@code event} attribute
*/
@JsonProperty
@Override
public T getEvent() {
return event;
}
/**
* Copy the current immutable object by setting a value for the {@link SlackEventWrapperIF#getToken() token} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for token
* @return A modified copy of the {@code this} object
*/
public final SlackEventWrapper withToken(String value) {
String newValue = Objects.requireNonNull(value, "token");
if (this.token.equals(newValue)) return this;
return new SlackEventWrapper<>(
newValue,
this.teamId,
this.contextTeamId,
this.type,
this.authedUsers,
this.eventId,
this.eventTime,
this.event);
}
/**
* Copy the current immutable object by setting a value for the {@link SlackEventWrapperIF#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 SlackEventWrapper withTeamId(String value) {
String newValue = Objects.requireNonNull(value, "teamId");
if (this.teamId.equals(newValue)) return this;
return new SlackEventWrapper<>(
this.token,
newValue,
this.contextTeamId,
this.type,
this.authedUsers,
this.eventId,
this.eventTime,
this.event);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link SlackEventWrapperIF#getContextTeamId() contextTeamId} attribute.
* @param value The value for contextTeamId, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final SlackEventWrapper withContextTeamId(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.contextTeamId, newValue)) return this;
return new SlackEventWrapper<>(
this.token,
this.teamId,
newValue,
this.type,
this.authedUsers,
this.eventId,
this.eventTime,
this.event);
}
/**
* Copy the current immutable object by setting an optional value for the {@link SlackEventWrapperIF#getContextTeamId() contextTeamId} 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 contextTeamId
* @return A modified copy of {@code this} object
*/
public final SlackEventWrapper withContextTeamId(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.contextTeamId, value)) return this;
return new SlackEventWrapper<>(
this.token,
this.teamId,
value,
this.type,
this.authedUsers,
this.eventId,
this.eventTime,
this.event);
}
/**
* Copy the current immutable object by setting a value for the {@link SlackEventWrapperIF#getType() type} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for type
* @return A modified copy of the {@code this} object
*/
public final SlackEventWrapper withType(SlackEventType value) {
SlackEventType newValue = Objects.requireNonNull(value, "type");
if (this.type == newValue) return this;
return new SlackEventWrapper<>(
this.token,
this.teamId,
this.contextTeamId,
newValue,
this.authedUsers,
this.eventId,
this.eventTime,
this.event);
}
/**
* Copy the current immutable object with elements that replace the content of {@link SlackEventWrapperIF#getAuthedUsers() authedUsers}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final SlackEventWrapper withAuthedUsers(String... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new SlackEventWrapper<>(
this.token,
this.teamId,
this.contextTeamId,
this.type,
newValue,
this.eventId,
this.eventTime,
this.event);
}
/**
* Copy the current immutable object with elements that replace the content of {@link SlackEventWrapperIF#getAuthedUsers() authedUsers}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of authedUsers elements to set
* @return A modified copy of {@code this} object
*/
public final SlackEventWrapper withAuthedUsers(Iterable elements) {
if (this.authedUsers == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return new SlackEventWrapper<>(
this.token,
this.teamId,
this.contextTeamId,
this.type,
newValue,
this.eventId,
this.eventTime,
this.event);
}
/**
* Copy the current immutable object by setting a value for the {@link SlackEventWrapperIF#getEventId() eventId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for eventId
* @return A modified copy of the {@code this} object
*/
public final SlackEventWrapper withEventId(String value) {
String newValue = Objects.requireNonNull(value, "eventId");
if (this.eventId.equals(newValue)) return this;
return new SlackEventWrapper<>(
this.token,
this.teamId,
this.contextTeamId,
this.type,
this.authedUsers,
newValue,
this.eventTime,
this.event);
}
/**
* Copy the current immutable object by setting a value for the {@link SlackEventWrapperIF#getEventTime() eventTime} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for eventTime
* @return A modified copy of the {@code this} object
*/
public final SlackEventWrapper withEventTime(String value) {
String newValue = Objects.requireNonNull(value, "eventTime");
if (this.eventTime.equals(newValue)) return this;
return new SlackEventWrapper<>(
this.token,
this.teamId,
this.contextTeamId,
this.type,
this.authedUsers,
this.eventId,
newValue,
this.event);
}
/**
* Copy the current immutable object by setting a value for the {@link SlackEventWrapperIF#getEvent() event} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for event
* @return A modified copy of the {@code this} object
*/
public final SlackEventWrapper withEvent(T value) {
if (this.event == value) return this;
T newValue = Objects.requireNonNull(value, "event");
return new SlackEventWrapper<>(
this.token,
this.teamId,
this.contextTeamId,
this.type,
this.authedUsers,
this.eventId,
this.eventTime,
newValue);
}
/**
* This instance is equal to all instances of {@code SlackEventWrapper} 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 SlackEventWrapper>
&& equalTo(0, (SlackEventWrapper>) another);
}
private boolean equalTo(int synthetic, SlackEventWrapper> another) {
return token.equals(another.token)
&& teamId.equals(another.teamId)
&& Objects.equals(contextTeamId, another.contextTeamId)
&& type.equals(another.type)
&& authedUsers.equals(another.authedUsers)
&& eventId.equals(another.eventId)
&& eventTime.equals(another.eventTime)
&& event.equals(another.event);
}
/**
* Computes a hash code from attributes: {@code token}, {@code teamId}, {@code contextTeamId}, {@code type}, {@code authedUsers}, {@code eventId}, {@code eventTime}, {@code event}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + token.hashCode();
h += (h << 5) + teamId.hashCode();
h += (h << 5) + Objects.hashCode(contextTeamId);
h += (h << 5) + type.hashCode();
h += (h << 5) + authedUsers.hashCode();
h += (h << 5) + eventId.hashCode();
h += (h << 5) + eventTime.hashCode();
h += (h << 5) + event.hashCode();
return h;
}
/**
* Prints the immutable value {@code SlackEventWrapper} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("SlackEventWrapper{");
builder.append("token=").append(token);
builder.append(", ");
builder.append("teamId=").append(teamId);
if (contextTeamId != null) {
builder.append(", ");
builder.append("contextTeamId=").append(contextTeamId);
}
builder.append(", ");
builder.append("type=").append(type);
builder.append(", ");
builder.append("authedUsers=").append(authedUsers);
builder.append(", ");
builder.append("eventId=").append(eventId);
builder.append(", ");
builder.append("eventTime=").append(eventTime);
builder.append(", ");
builder.append("event=").append(event);
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 = "SlackEventWrapperIF", generator = "Immutables")
@Deprecated
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json
implements SlackEventWrapperIF {
@Nullable String token;
@Nullable String teamId;
@Nullable Optional contextTeamId = Optional.empty();
@Nullable SlackEventType type;
@Nullable List authedUsers = Collections.emptyList();
@Nullable String eventId;
@Nullable String eventTime;
@Nullable T event;
@JsonProperty
public void setToken(String token) {
this.token = token;
}
@JsonProperty
public void setTeamId(String teamId) {
this.teamId = teamId;
}
@JsonProperty
public void setContextTeamId(Optional contextTeamId) {
this.contextTeamId = contextTeamId;
}
@JsonProperty
public void setType(SlackEventType type) {
this.type = type;
}
@JsonProperty
public void setAuthedUsers(List authedUsers) {
this.authedUsers = authedUsers;
}
@JsonProperty
public void setEventId(String eventId) {
this.eventId = eventId;
}
@JsonProperty
public void setEventTime(String eventTime) {
this.eventTime = eventTime;
}
@JsonProperty
public void setEvent(T event) {
this.event = event;
}
@Override
public String getToken() { throw new UnsupportedOperationException(); }
@Override
public String getTeamId() { throw new UnsupportedOperationException(); }
@Override
public Optional getContextTeamId() { throw new UnsupportedOperationException(); }
@Override
public SlackEventType getType() { throw new UnsupportedOperationException(); }
@Override
public List getAuthedUsers() { throw new UnsupportedOperationException(); }
@Override
public String getEventId() { throw new UnsupportedOperationException(); }
@Override
public String getEventTime() { throw new UnsupportedOperationException(); }
@Override
public T getEvent() { throw new UnsupportedOperationException(); }
}
/**
* @param generic parameter T
* @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 SlackEventWrapper fromJson(Json json) {
SlackEventWrapper.Builder builder = SlackEventWrapper.builder();
if (json.token != null) {
builder.setToken(json.token);
}
if (json.teamId != null) {
builder.setTeamId(json.teamId);
}
if (json.contextTeamId != null) {
builder.setContextTeamId(json.contextTeamId);
}
if (json.type != null) {
builder.setType(json.type);
}
if (json.authedUsers != null) {
builder.addAllAuthedUsers(json.authedUsers);
}
if (json.eventId != null) {
builder.setEventId(json.eventId);
}
if (json.eventTime != null) {
builder.setEventTime(json.eventTime);
}
if (json.event != null) {
builder.setEvent(json.event);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link SlackEventWrapperIF} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param generic parameter T
* @param instance The instance to copy
* @return A copied immutable SlackEventWrapper instance
*/
public static SlackEventWrapper copyOf(SlackEventWrapperIF instance) {
if (instance instanceof SlackEventWrapper>) {
return (SlackEventWrapper) instance;
}
return SlackEventWrapper.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link SlackEventWrapper SlackEventWrapper}.
*
* SlackEventWrapper.<T>builder()
* .setToken(String) // required {@link SlackEventWrapperIF#getToken() token}
* .setTeamId(String) // required {@link SlackEventWrapperIF#getTeamId() teamId}
* .setContextTeamId(String) // optional {@link SlackEventWrapperIF#getContextTeamId() contextTeamId}
* .setType(com.hubspot.slack.client.models.events.SlackEventType) // required {@link SlackEventWrapperIF#getType() type}
* .addAuthedUsers|addAllAuthedUsers(String) // {@link SlackEventWrapperIF#getAuthedUsers() authedUsers} elements
* .setEventId(String) // required {@link SlackEventWrapperIF#getEventId() eventId}
* .setEventTime(String) // required {@link SlackEventWrapperIF#getEventTime() eventTime}
* .setEvent(T) // required {@link SlackEventWrapperIF#getEvent() event}
* .build();
*
* @param generic parameter T
* @return A new SlackEventWrapper builder
*/
public static SlackEventWrapper.Builder builder() {
return new SlackEventWrapper.Builder<>();
}
/**
* Builds instances of type {@link SlackEventWrapper SlackEventWrapper}.
* 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 = "SlackEventWrapperIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_TOKEN = 0x1L;
private static final long INIT_BIT_TEAM_ID = 0x2L;
private static final long INIT_BIT_TYPE = 0x4L;
private static final long INIT_BIT_EVENT_ID = 0x8L;
private static final long INIT_BIT_EVENT_TIME = 0x10L;
private static final long INIT_BIT_EVENT = 0x20L;
private long initBits = 0x3fL;
private @Nullable String token;
private @Nullable String teamId;
private @Nullable String contextTeamId;
private @Nullable SlackEventType type;
private List authedUsers = new ArrayList();
private @Nullable String eventId;
private @Nullable String eventTime;
private @Nullable T event;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code SlackEventWrapperIF} 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(SlackEventWrapperIF instance) {
Objects.requireNonNull(instance, "instance");
this.setToken(instance.getToken());
this.setTeamId(instance.getTeamId());
Optional contextTeamIdOptional = instance.getContextTeamId();
if (contextTeamIdOptional.isPresent()) {
setContextTeamId(contextTeamIdOptional);
}
this.setType(instance.getType());
addAllAuthedUsers(instance.getAuthedUsers());
this.setEventId(instance.getEventId());
this.setEventTime(instance.getEventTime());
this.setEvent(instance.getEvent());
return this;
}
/**
* Initializes the value for the {@link SlackEventWrapperIF#getToken() token} attribute.
* @param token The value for token
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setToken(String token) {
this.token = Objects.requireNonNull(token, "token");
initBits &= ~INIT_BIT_TOKEN;
return this;
}
/**
* Initializes the value for the {@link SlackEventWrapperIF#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 optional value {@link SlackEventWrapperIF#getContextTeamId() contextTeamId} to contextTeamId.
* @param contextTeamId The value for contextTeamId, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setContextTeamId(@Nullable String contextTeamId) {
this.contextTeamId = contextTeamId;
return this;
}
/**
* Initializes the optional value {@link SlackEventWrapperIF#getContextTeamId() contextTeamId} to contextTeamId.
* @param contextTeamId The value for contextTeamId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setContextTeamId(Optional contextTeamId) {
this.contextTeamId = contextTeamId.orElse(null);
return this;
}
/**
* Initializes the value for the {@link SlackEventWrapperIF#getType() type} attribute.
* @param type The value for type
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setType(SlackEventType type) {
this.type = Objects.requireNonNull(type, "type");
initBits &= ~INIT_BIT_TYPE;
return this;
}
/**
* Adds one element to {@link SlackEventWrapperIF#getAuthedUsers() authedUsers} list.
* @param element A authedUsers element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAuthedUsers(String element) {
this.authedUsers.add(Objects.requireNonNull(element, "authedUsers element"));
return this;
}
/**
* Adds elements to {@link SlackEventWrapperIF#getAuthedUsers() authedUsers} list.
* @param elements An array of authedUsers elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAuthedUsers(String... elements) {
for (String element : elements) {
this.authedUsers.add(Objects.requireNonNull(element, "authedUsers element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link SlackEventWrapperIF#getAuthedUsers() authedUsers} list.
* @param elements An iterable of authedUsers elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setAuthedUsers(Iterable elements) {
this.authedUsers.clear();
return addAllAuthedUsers(elements);
}
/**
* Adds elements to {@link SlackEventWrapperIF#getAuthedUsers() authedUsers} list.
* @param elements An iterable of authedUsers elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllAuthedUsers(Iterable elements) {
for (String element : elements) {
this.authedUsers.add(Objects.requireNonNull(element, "authedUsers element"));
}
return this;
}
/**
* Initializes the value for the {@link SlackEventWrapperIF#getEventId() eventId} attribute.
* @param eventId The value for eventId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setEventId(String eventId) {
this.eventId = Objects.requireNonNull(eventId, "eventId");
initBits &= ~INIT_BIT_EVENT_ID;
return this;
}
/**
* Initializes the value for the {@link SlackEventWrapperIF#getEventTime() eventTime} attribute.
* @param eventTime The value for eventTime
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setEventTime(String eventTime) {
this.eventTime = Objects.requireNonNull(eventTime, "eventTime");
initBits &= ~INIT_BIT_EVENT_TIME;
return this;
}
/**
* Initializes the value for the {@link SlackEventWrapperIF#getEvent() event} attribute.
* @param event The value for event
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setEvent(T event) {
this.event = Objects.requireNonNull(event, "event");
initBits &= ~INIT_BIT_EVENT;
return this;
}
/**
* Builds a new {@link SlackEventWrapper SlackEventWrapper}.
* @return An immutable instance of SlackEventWrapper
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public SlackEventWrapper build() {
checkRequiredAttributes();
return new SlackEventWrapper<>(
token,
teamId,
contextTeamId,
type,
createUnmodifiableList(true, authedUsers),
eventId,
eventTime,
event);
}
private boolean tokenIsSet() {
return (initBits & INIT_BIT_TOKEN) == 0;
}
private boolean teamIdIsSet() {
return (initBits & INIT_BIT_TEAM_ID) == 0;
}
private boolean typeIsSet() {
return (initBits & INIT_BIT_TYPE) == 0;
}
private boolean eventIdIsSet() {
return (initBits & INIT_BIT_EVENT_ID) == 0;
}
private boolean eventTimeIsSet() {
return (initBits & INIT_BIT_EVENT_TIME) == 0;
}
private boolean eventIsSet() {
return (initBits & INIT_BIT_EVENT) == 0;
}
private void checkRequiredAttributes() {
if (initBits != 0) {
throw new InvalidImmutableStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if (!tokenIsSet()) attributes.add("token");
if (!teamIdIsSet()) attributes.add("teamId");
if (!typeIsSet()) attributes.add("type");
if (!eventIdIsSet()) attributes.add("eventId");
if (!eventTimeIsSet()) attributes.add("eventTime");
if (!eventIsSet()) attributes.add("event");
return "Cannot build SlackEventWrapper, 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;
}
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);
}
}
}
}