
com.hubspot.slack.client.models.events.SlackEventMessage 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.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.hubspot.immutables.validation.InvalidImmutableStateException;
import com.hubspot.slack.client.methods.interceptor.HasChannel;
import com.hubspot.slack.client.methods.interceptor.HasUser;
import com.hubspot.slack.client.models.Attachment;
import com.hubspot.slack.client.models.files.SlackFile;
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 AbstractSlackEventMessage}.
*
* Use the builder to create immutable instances:
* {@code SlackEventMessage.builder()}.
*/
@Generated(from = "AbstractSlackEventMessage", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class SlackEventMessage extends AbstractSlackEventMessage {
private final SlackEventType type;
private final String ts;
private final @Nullable SlackMessageSubtype subtype;
private final List attachments;
private final String channelId;
private final @Nullable String threadTs;
private final @Nullable String botId;
private final String userId;
private final String text;
private final List files;
private SlackEventMessage(
SlackEventType type,
String ts,
@Nullable SlackMessageSubtype subtype,
List attachments,
String channelId,
@Nullable String threadTs,
@Nullable String botId,
String userId,
String text,
List files) {
this.type = type;
this.ts = ts;
this.subtype = subtype;
this.attachments = attachments;
this.channelId = channelId;
this.threadTs = threadTs;
this.botId = botId;
this.userId = userId;
this.text = text;
this.files = files;
}
/**
* @return The value of the {@code type} attribute
*/
@JsonProperty
@Override
public SlackEventType getType() {
return type;
}
/**
* @return The value of the {@code ts} attribute
*/
@JsonProperty
@Override
public String getTs() {
return ts;
}
/**
* @return The value of the {@code subtype} attribute
*/
@JsonProperty
@Override
public Optional getSubtype() {
return Optional.ofNullable(subtype);
}
/**
* @return The value of the {@code attachments} attribute
*/
@JsonProperty
@Override
public List getAttachments() {
return attachments;
}
/**
* @return The value of the {@code channelId} attribute
*/
@JsonProperty("channel")
@Override
public String getChannelId() {
return channelId;
}
/**
* @return The value of the {@code threadTs} attribute
*/
@JsonProperty
@Override
public Optional getThreadTs() {
return Optional.ofNullable(threadTs);
}
/**
* @return The value of the {@code botId} attribute
*/
@JsonProperty
@Override
public Optional getBotId() {
return Optional.ofNullable(botId);
}
/**
* @return The value of the {@code userId} attribute
*/
@JsonProperty("user")
@Override
public String getUserId() {
return userId;
}
/**
* @return The value of the {@code text} attribute
*/
@JsonProperty
@Override
public String getText() {
return text;
}
/**
* @return The value of the {@code files} attribute
*/
@JsonProperty
@Override
public List getFiles() {
return files;
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractSlackEventMessage#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 SlackEventMessage withType(SlackEventType value) {
SlackEventType newValue = Objects.requireNonNull(value, "type");
if (this.type == newValue) return this;
return new SlackEventMessage(
newValue,
this.ts,
this.subtype,
this.attachments,
this.channelId,
this.threadTs,
this.botId,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractSlackEventMessage#getTs() ts} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for ts
* @return A modified copy of the {@code this} object
*/
public final SlackEventMessage withTs(String value) {
String newValue = Objects.requireNonNull(value, "ts");
if (this.ts.equals(newValue)) return this;
return new SlackEventMessage(
this.type,
newValue,
this.subtype,
this.attachments,
this.channelId,
this.threadTs,
this.botId,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link AbstractSlackEventMessage#getSubtype() subtype} attribute.
* @param value The value for subtype, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final SlackEventMessage withSubtype(@Nullable SlackMessageSubtype value) {
@Nullable SlackMessageSubtype newValue = value;
if (this.subtype == newValue) return this;
return new SlackEventMessage(
this.type,
this.ts,
newValue,
this.attachments,
this.channelId,
this.threadTs,
this.botId,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object by setting an optional value for the {@link AbstractSlackEventMessage#getSubtype() subtype} 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 subtype
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final SlackEventMessage withSubtype(Optional extends SlackMessageSubtype> optional) {
@Nullable SlackMessageSubtype value = optional.orElse(null);
if (this.subtype == value) return this;
return new SlackEventMessage(
this.type,
this.ts,
value,
this.attachments,
this.channelId,
this.threadTs,
this.botId,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AbstractSlackEventMessage#getAttachments() attachments}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final SlackEventMessage withAttachments(Attachment... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
newValue,
this.channelId,
this.threadTs,
this.botId,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AbstractSlackEventMessage#getAttachments() attachments}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of attachments elements to set
* @return A modified copy of {@code this} object
*/
public final SlackEventMessage withAttachments(Iterable extends Attachment> elements) {
if (this.attachments == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
newValue,
this.channelId,
this.threadTs,
this.botId,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractSlackEventMessage#getChannelId() channelId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for channelId
* @return A modified copy of the {@code this} object
*/
public final SlackEventMessage withChannelId(String value) {
String newValue = Objects.requireNonNull(value, "channelId");
if (this.channelId.equals(newValue)) return this;
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
this.attachments,
newValue,
this.threadTs,
this.botId,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link AbstractSlackEventMessage#getThreadTs() threadTs} attribute.
* @param value The value for threadTs, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final SlackEventMessage withThreadTs(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.threadTs, newValue)) return this;
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
this.attachments,
this.channelId,
newValue,
this.botId,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object by setting an optional value for the {@link AbstractSlackEventMessage#getThreadTs() threadTs} 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 threadTs
* @return A modified copy of {@code this} object
*/
public final SlackEventMessage withThreadTs(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.threadTs, value)) return this;
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
this.attachments,
this.channelId,
value,
this.botId,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link AbstractSlackEventMessage#getBotId() botId} attribute.
* @param value The value for botId, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final SlackEventMessage withBotId(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.botId, newValue)) return this;
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
this.attachments,
this.channelId,
this.threadTs,
newValue,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object by setting an optional value for the {@link AbstractSlackEventMessage#getBotId() botId} 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 botId
* @return A modified copy of {@code this} object
*/
public final SlackEventMessage withBotId(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.botId, value)) return this;
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
this.attachments,
this.channelId,
this.threadTs,
value,
this.userId,
this.text,
this.files);
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractSlackEventMessage#getUserId() userId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for userId
* @return A modified copy of the {@code this} object
*/
public final SlackEventMessage withUserId(String value) {
String newValue = Objects.requireNonNull(value, "userId");
if (this.userId.equals(newValue)) return this;
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
this.attachments,
this.channelId,
this.threadTs,
this.botId,
newValue,
this.text,
this.files);
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractSlackEventMessage#getText() text} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for text
* @return A modified copy of the {@code this} object
*/
public final SlackEventMessage withText(String value) {
String newValue = Objects.requireNonNull(value, "text");
if (this.text.equals(newValue)) return this;
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
this.attachments,
this.channelId,
this.threadTs,
this.botId,
this.userId,
newValue,
this.files);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AbstractSlackEventMessage#getFiles() files}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final SlackEventMessage withFiles(SlackFile... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
this.attachments,
this.channelId,
this.threadTs,
this.botId,
this.userId,
this.text,
newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AbstractSlackEventMessage#getFiles() files}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of files elements to set
* @return A modified copy of {@code this} object
*/
public final SlackEventMessage withFiles(Iterable extends SlackFile> elements) {
if (this.files == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return new SlackEventMessage(
this.type,
this.ts,
this.subtype,
this.attachments,
this.channelId,
this.threadTs,
this.botId,
this.userId,
this.text,
newValue);
}
/**
* This instance is equal to all instances of {@code SlackEventMessage} 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 SlackEventMessage
&& equalTo(0, (SlackEventMessage) another);
}
private boolean equalTo(int synthetic, SlackEventMessage another) {
return type.equals(another.type)
&& ts.equals(another.ts)
&& Objects.equals(subtype, another.subtype)
&& attachments.equals(another.attachments)
&& channelId.equals(another.channelId)
&& Objects.equals(threadTs, another.threadTs)
&& Objects.equals(botId, another.botId)
&& userId.equals(another.userId)
&& text.equals(another.text)
&& files.equals(another.files);
}
/**
* Computes a hash code from attributes: {@code type}, {@code ts}, {@code subtype}, {@code attachments}, {@code channelId}, {@code threadTs}, {@code botId}, {@code userId}, {@code text}, {@code files}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + type.hashCode();
h += (h << 5) + ts.hashCode();
h += (h << 5) + Objects.hashCode(subtype);
h += (h << 5) + attachments.hashCode();
h += (h << 5) + channelId.hashCode();
h += (h << 5) + Objects.hashCode(threadTs);
h += (h << 5) + Objects.hashCode(botId);
h += (h << 5) + userId.hashCode();
h += (h << 5) + text.hashCode();
h += (h << 5) + files.hashCode();
return h;
}
/**
* Prints the immutable value {@code SlackEventMessage} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("SlackEventMessage{");
builder.append("type=").append(type);
builder.append(", ");
builder.append("ts=").append(ts);
if (subtype != null) {
builder.append(", ");
builder.append("subtype=").append(subtype);
}
builder.append(", ");
builder.append("attachments=").append(attachments);
builder.append(", ");
builder.append("channelId=").append(channelId);
if (threadTs != null) {
builder.append(", ");
builder.append("threadTs=").append(threadTs);
}
if (botId != null) {
builder.append(", ");
builder.append("botId=").append(botId);
}
builder.append(", ");
builder.append("userId=").append(userId);
builder.append(", ");
builder.append("text=").append(text);
builder.append(", ");
builder.append("files=").append(files);
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 = "AbstractSlackEventMessage", generator = "Immutables")
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends AbstractSlackEventMessage {
@Nullable SlackEventType type;
@Nullable String ts;
@Nullable Optional subtype = Optional.empty();
@Nullable List attachments = Collections.emptyList();
@Nullable String channelId;
@Nullable Optional threadTs = Optional.empty();
@Nullable Optional botId = Optional.empty();
@Nullable String userId;
@Nullable String text;
@Nullable List files = Collections.emptyList();
@JsonProperty
public void setType(SlackEventType type) {
this.type = type;
}
@JsonProperty
public void setTs(String ts) {
this.ts = ts;
}
@JsonProperty
public void setSubtype(Optional subtype) {
this.subtype = subtype;
}
@JsonProperty
public void setAttachments(List attachments) {
this.attachments = attachments;
}
@JsonProperty("channel")
public void setChannelId(String channelId) {
this.channelId = channelId;
}
@JsonProperty
public void setThreadTs(Optional threadTs) {
this.threadTs = threadTs;
}
@JsonProperty
public void setBotId(Optional botId) {
this.botId = botId;
}
@JsonProperty("user")
public void setUserId(String userId) {
this.userId = userId;
}
@JsonProperty
public void setText(String text) {
this.text = text;
}
@JsonProperty
public void setFiles(List files) {
this.files = files;
}
@Override
public SlackEventType getType() { throw new UnsupportedOperationException(); }
@Override
public String getTs() { throw new UnsupportedOperationException(); }
@Override
public Optional getSubtype() { throw new UnsupportedOperationException(); }
@Override
public List getAttachments() { throw new UnsupportedOperationException(); }
@Override
public String getChannelId() { throw new UnsupportedOperationException(); }
@Override
public Optional getThreadTs() { throw new UnsupportedOperationException(); }
@Override
public Optional getBotId() { throw new UnsupportedOperationException(); }
@Override
public String getUserId() { throw new UnsupportedOperationException(); }
@Override
public String getText() { throw new UnsupportedOperationException(); }
@Override
public List getFiles() { 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 SlackEventMessage fromJson(Json json) {
SlackEventMessage.Builder builder = SlackEventMessage.builder();
if (json.type != null) {
builder.setType(json.type);
}
if (json.ts != null) {
builder.setTs(json.ts);
}
if (json.subtype != null) {
builder.setSubtype(json.subtype);
}
if (json.attachments != null) {
builder.addAllAttachments(json.attachments);
}
if (json.channelId != null) {
builder.setChannelId(json.channelId);
}
if (json.threadTs != null) {
builder.setThreadTs(json.threadTs);
}
if (json.botId != null) {
builder.setBotId(json.botId);
}
if (json.userId != null) {
builder.setUserId(json.userId);
}
if (json.text != null) {
builder.setText(json.text);
}
if (json.files != null) {
builder.addAllFiles(json.files);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link AbstractSlackEventMessage} 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 SlackEventMessage instance
*/
public static SlackEventMessage copyOf(AbstractSlackEventMessage instance) {
if (instance instanceof SlackEventMessage) {
return (SlackEventMessage) instance;
}
return SlackEventMessage.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link SlackEventMessage SlackEventMessage}.
*
* SlackEventMessage.builder()
* .setType(com.hubspot.slack.client.models.events.SlackEventType) // required {@link AbstractSlackEventMessage#getType() type}
* .setTs(String) // required {@link AbstractSlackEventMessage#getTs() ts}
* .setSubtype(com.hubspot.slack.client.models.events.SlackMessageSubtype) // optional {@link AbstractSlackEventMessage#getSubtype() subtype}
* .addAttachments|addAllAttachments(com.hubspot.slack.client.models.Attachment) // {@link AbstractSlackEventMessage#getAttachments() attachments} elements
* .setChannelId(String) // required {@link AbstractSlackEventMessage#getChannelId() channelId}
* .setThreadTs(String) // optional {@link AbstractSlackEventMessage#getThreadTs() threadTs}
* .setBotId(String) // optional {@link AbstractSlackEventMessage#getBotId() botId}
* .setUserId(String) // required {@link AbstractSlackEventMessage#getUserId() userId}
* .setText(String) // required {@link AbstractSlackEventMessage#getText() text}
* .addFiles|addAllFiles(com.hubspot.slack.client.models.files.SlackFile) // {@link AbstractSlackEventMessage#getFiles() files} elements
* .build();
*
* @return A new SlackEventMessage builder
*/
public static SlackEventMessage.Builder builder() {
return new SlackEventMessage.Builder();
}
/**
* Builds instances of type {@link SlackEventMessage SlackEventMessage}.
* 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 = "AbstractSlackEventMessage", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_TYPE = 0x1L;
private static final long INIT_BIT_TS = 0x2L;
private static final long INIT_BIT_CHANNEL_ID = 0x4L;
private static final long INIT_BIT_USER_ID = 0x8L;
private static final long INIT_BIT_TEXT = 0x10L;
private long initBits = 0x1fL;
private @Nullable SlackEventType type;
private @Nullable String ts;
private @Nullable SlackMessageSubtype subtype;
private List attachments = new ArrayList();
private @Nullable String channelId;
private @Nullable String threadTs;
private @Nullable String botId;
private @Nullable String userId;
private @Nullable String text;
private List files = new ArrayList();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.hubspot.slack.client.methods.interceptor.HasChannel} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(HasChannel 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.events.SlackEvent} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(SlackEvent 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.events.SlackEventMessageBase} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(SlackEventMessageBase 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.events.AbstractSlackEventMessage} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(AbstractSlackEventMessage 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.methods.interceptor.HasUser} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(HasUser 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 HasChannel) {
HasChannel instance = (HasChannel) object;
if ((bits & 0x10L) == 0) {
this.setChannelId(instance.getChannelId());
bits |= 0x10L;
}
}
if (object instanceof SlackEvent) {
SlackEvent instance = (SlackEvent) object;
if ((bits & 0x2L) == 0) {
this.setType(instance.getType());
bits |= 0x2L;
}
if ((bits & 0x20L) == 0) {
this.setTs(instance.getTs());
bits |= 0x20L;
}
}
if (object instanceof SlackEventMessageBase) {
SlackEventMessageBase instance = (SlackEventMessageBase) object;
if ((bits & 0x1L) == 0) {
addAllAttachments(instance.getAttachments());
bits |= 0x1L;
}
if ((bits & 0x2L) == 0) {
this.setType(instance.getType());
bits |= 0x2L;
}
if ((bits & 0x8L) == 0) {
Optional subtypeOptional = instance.getSubtype();
if (subtypeOptional.isPresent()) {
setSubtype(subtypeOptional);
}
bits |= 0x8L;
}
if ((bits & 0x10L) == 0) {
this.setChannelId(instance.getChannelId());
bits |= 0x10L;
}
if ((bits & 0x20L) == 0) {
this.setTs(instance.getTs());
bits |= 0x20L;
}
}
if (object instanceof AbstractSlackEventMessage) {
AbstractSlackEventMessage instance = (AbstractSlackEventMessage) object;
if ((bits & 0x1L) == 0) {
addAllAttachments(instance.getAttachments());
bits |= 0x1L;
}
if ((bits & 0x8L) == 0) {
Optional subtypeOptional = instance.getSubtype();
if (subtypeOptional.isPresent()) {
setSubtype(subtypeOptional);
}
bits |= 0x8L;
}
addAllFiles(instance.getFiles());
Optional botIdOptional = instance.getBotId();
if (botIdOptional.isPresent()) {
setBotId(botIdOptional);
}
this.setText(instance.getText());
if ((bits & 0x2L) == 0) {
this.setType(instance.getType());
bits |= 0x2L;
}
Optional threadTsOptional = instance.getThreadTs();
if (threadTsOptional.isPresent()) {
setThreadTs(threadTsOptional);
}
if ((bits & 0x4L) == 0) {
this.setUserId(instance.getUserId());
bits |= 0x4L;
}
if ((bits & 0x10L) == 0) {
this.setChannelId(instance.getChannelId());
bits |= 0x10L;
}
if ((bits & 0x20L) == 0) {
this.setTs(instance.getTs());
bits |= 0x20L;
}
}
if (object instanceof HasUser) {
HasUser instance = (HasUser) object;
if ((bits & 0x4L) == 0) {
this.setUserId(instance.getUserId());
bits |= 0x4L;
}
}
}
/**
* Initializes the value for the {@link AbstractSlackEventMessage#getType() type} attribute.
* @param type The value for type
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty
public final Builder setType(SlackEventType type) {
this.type = Objects.requireNonNull(type, "type");
initBits &= ~INIT_BIT_TYPE;
return this;
}
/**
* Initializes the value for the {@link AbstractSlackEventMessage#getTs() ts} attribute.
* @param ts The value for ts
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty
public final Builder setTs(String ts) {
this.ts = Objects.requireNonNull(ts, "ts");
initBits &= ~INIT_BIT_TS;
return this;
}
/**
* Initializes the optional value {@link AbstractSlackEventMessage#getSubtype() subtype} to subtype.
* @param subtype The value for subtype, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setSubtype(@Nullable SlackMessageSubtype subtype) {
this.subtype = subtype;
return this;
}
/**
* Initializes the optional value {@link AbstractSlackEventMessage#getSubtype() subtype} to subtype.
* @param subtype The value for subtype
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty
public final Builder setSubtype(Optional extends SlackMessageSubtype> subtype) {
this.subtype = subtype.orElse(null);
return this;
}
/**
* Adds one element to {@link AbstractSlackEventMessage#getAttachments() attachments} list.
* @param element A attachments element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAttachments(Attachment element) {
this.attachments.add(Objects.requireNonNull(element, "attachments element"));
return this;
}
/**
* Adds elements to {@link AbstractSlackEventMessage#getAttachments() attachments} list.
* @param elements An array of attachments elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAttachments(Attachment... elements) {
for (Attachment element : elements) {
this.attachments.add(Objects.requireNonNull(element, "attachments element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link AbstractSlackEventMessage#getAttachments() attachments} list.
* @param elements An iterable of attachments elements
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty
public final Builder setAttachments(Iterable extends Attachment> elements) {
this.attachments.clear();
return addAllAttachments(elements);
}
/**
* Adds elements to {@link AbstractSlackEventMessage#getAttachments() attachments} list.
* @param elements An iterable of attachments elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllAttachments(Iterable extends Attachment> elements) {
for (Attachment element : elements) {
this.attachments.add(Objects.requireNonNull(element, "attachments element"));
}
return this;
}
/**
* Initializes the value for the {@link AbstractSlackEventMessage#getChannelId() channelId} attribute.
* @param channelId The value for channelId
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("channel")
public final Builder setChannelId(String channelId) {
this.channelId = Objects.requireNonNull(channelId, "channelId");
initBits &= ~INIT_BIT_CHANNEL_ID;
return this;
}
/**
* Initializes the optional value {@link AbstractSlackEventMessage#getThreadTs() threadTs} to threadTs.
* @param threadTs The value for threadTs, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setThreadTs(@Nullable String threadTs) {
this.threadTs = threadTs;
return this;
}
/**
* Initializes the optional value {@link AbstractSlackEventMessage#getThreadTs() threadTs} to threadTs.
* @param threadTs The value for threadTs
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty
public final Builder setThreadTs(Optional threadTs) {
this.threadTs = threadTs.orElse(null);
return this;
}
/**
* Initializes the optional value {@link AbstractSlackEventMessage#getBotId() botId} to botId.
* @param botId The value for botId, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setBotId(@Nullable String botId) {
this.botId = botId;
return this;
}
/**
* Initializes the optional value {@link AbstractSlackEventMessage#getBotId() botId} to botId.
* @param botId The value for botId
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty
public final Builder setBotId(Optional botId) {
this.botId = botId.orElse(null);
return this;
}
/**
* Initializes the value for the {@link AbstractSlackEventMessage#getUserId() userId} attribute.
* @param userId The value for userId
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("user")
public final Builder setUserId(String userId) {
this.userId = Objects.requireNonNull(userId, "userId");
initBits &= ~INIT_BIT_USER_ID;
return this;
}
/**
* Initializes the value for the {@link AbstractSlackEventMessage#getText() text} attribute.
* @param text The value for text
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty
public final Builder setText(String text) {
this.text = Objects.requireNonNull(text, "text");
initBits &= ~INIT_BIT_TEXT;
return this;
}
/**
* Adds one element to {@link AbstractSlackEventMessage#getFiles() files} list.
* @param element A files element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addFiles(SlackFile element) {
this.files.add(Objects.requireNonNull(element, "files element"));
return this;
}
/**
* Adds elements to {@link AbstractSlackEventMessage#getFiles() files} list.
* @param elements An array of files elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addFiles(SlackFile... elements) {
for (SlackFile element : elements) {
this.files.add(Objects.requireNonNull(element, "files element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link AbstractSlackEventMessage#getFiles() files} list.
* @param elements An iterable of files elements
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty
public final Builder setFiles(Iterable extends SlackFile> elements) {
this.files.clear();
return addAllFiles(elements);
}
/**
* Adds elements to {@link AbstractSlackEventMessage#getFiles() files} list.
* @param elements An iterable of files elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllFiles(Iterable extends SlackFile> elements) {
for (SlackFile element : elements) {
this.files.add(Objects.requireNonNull(element, "files element"));
}
return this;
}
/**
* Builds a new {@link SlackEventMessage SlackEventMessage}.
* @return An immutable instance of SlackEventMessage
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public SlackEventMessage build() {
checkRequiredAttributes();
return new SlackEventMessage(
type,
ts,
subtype,
createUnmodifiableList(true, attachments),
channelId,
threadTs,
botId,
userId,
text,
createUnmodifiableList(true, files));
}
private boolean typeIsSet() {
return (initBits & INIT_BIT_TYPE) == 0;
}
private boolean tsIsSet() {
return (initBits & INIT_BIT_TS) == 0;
}
private boolean channelIdIsSet() {
return (initBits & INIT_BIT_CHANNEL_ID) == 0;
}
private boolean userIdIsSet() {
return (initBits & INIT_BIT_USER_ID) == 0;
}
private boolean textIsSet() {
return (initBits & INIT_BIT_TEXT) == 0;
}
private void checkRequiredAttributes() {
if (initBits != 0) {
throw new InvalidImmutableStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if (!typeIsSet()) attributes.add("type");
if (!tsIsSet()) attributes.add("ts");
if (!channelIdIsSet()) attributes.add("channelId");
if (!userIdIsSet()) attributes.add("userId");
if (!textIsSet()) attributes.add("text");
return "Cannot build SlackEventMessage, 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);
}
}
}
}