
com.hubspot.slack.client.models.events.links.SlackLinkSharedEvent Maven / Gradle / Ivy
package com.hubspot.slack.client.models.events.links;
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.models.events.SlackEvent;
import com.hubspot.slack.client.models.events.SlackEventType;
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 SlackLinkSharedEventIF}.
*
* Use the builder to create immutable instances:
* {@code SlackLinkSharedEvent.builder()}.
*/
@Generated(from = "SlackLinkSharedEventIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class SlackLinkSharedEvent
implements SlackLinkSharedEventIF {
private final SlackEventType type;
private final String channelId;
private final String userId;
private final String messageTs;
private final @Nullable String threadTs;
private final List links;
private SlackLinkSharedEvent(
SlackEventType type,
String channelId,
String userId,
String messageTs,
@Nullable String threadTs,
List links) {
this.type = type;
this.channelId = channelId;
this.userId = userId;
this.messageTs = messageTs;
this.threadTs = threadTs;
this.links = links;
}
/**
* @return The value of the {@code type} attribute
*/
@JsonProperty
@Override
public SlackEventType getType() {
return type;
}
/**
* @return The value of the {@code channelId} attribute
*/
@JsonProperty("channel")
@Override
public String getChannelId() {
return channelId;
}
/**
* @return The value of the {@code userId} attribute
*/
@JsonProperty("user")
@Override
public String getUserId() {
return userId;
}
/**
* @return The value of the {@code messageTs} attribute
*/
@JsonProperty
@Override
public String getMessageTs() {
return messageTs;
}
/**
* @return The value of the {@code threadTs} attribute
*/
@JsonProperty
@Override
public Optional getThreadTs() {
return Optional.ofNullable(threadTs);
}
/**
* @return The value of the {@code links} attribute
*/
@JsonProperty
@Override
public List getLinks() {
return links;
}
/**
* Copy the current immutable object by setting a value for the {@link SlackLinkSharedEventIF#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 SlackLinkSharedEvent withType(SlackEventType value) {
SlackEventType newValue = Objects.requireNonNull(value, "type");
if (this.type == newValue) return this;
return new SlackLinkSharedEvent(newValue, this.channelId, this.userId, this.messageTs, this.threadTs, this.links);
}
/**
* Copy the current immutable object by setting a value for the {@link SlackLinkSharedEventIF#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 SlackLinkSharedEvent withChannelId(String value) {
String newValue = Objects.requireNonNull(value, "channelId");
if (this.channelId.equals(newValue)) return this;
return new SlackLinkSharedEvent(this.type, newValue, this.userId, this.messageTs, this.threadTs, this.links);
}
/**
* Copy the current immutable object by setting a value for the {@link SlackLinkSharedEventIF#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 SlackLinkSharedEvent withUserId(String value) {
String newValue = Objects.requireNonNull(value, "userId");
if (this.userId.equals(newValue)) return this;
return new SlackLinkSharedEvent(this.type, this.channelId, newValue, this.messageTs, this.threadTs, this.links);
}
/**
* Copy the current immutable object by setting a value for the {@link SlackLinkSharedEventIF#getMessageTs() messageTs} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for messageTs
* @return A modified copy of the {@code this} object
*/
public final SlackLinkSharedEvent withMessageTs(String value) {
String newValue = Objects.requireNonNull(value, "messageTs");
if (this.messageTs.equals(newValue)) return this;
return new SlackLinkSharedEvent(this.type, this.channelId, this.userId, newValue, this.threadTs, this.links);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link SlackLinkSharedEventIF#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 SlackLinkSharedEvent withThreadTs(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.threadTs, newValue)) return this;
return new SlackLinkSharedEvent(this.type, this.channelId, this.userId, this.messageTs, newValue, this.links);
}
/**
* Copy the current immutable object by setting an optional value for the {@link SlackLinkSharedEventIF#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 SlackLinkSharedEvent withThreadTs(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.threadTs, value)) return this;
return new SlackLinkSharedEvent(this.type, this.channelId, this.userId, this.messageTs, value, this.links);
}
/**
* Copy the current immutable object with elements that replace the content of {@link SlackLinkSharedEventIF#getLinks() links}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final SlackLinkSharedEvent withLinks(Link... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new SlackLinkSharedEvent(this.type, this.channelId, this.userId, this.messageTs, this.threadTs, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link SlackLinkSharedEventIF#getLinks() links}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of links elements to set
* @return A modified copy of {@code this} object
*/
public final SlackLinkSharedEvent withLinks(Iterable extends Link> elements) {
if (this.links == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return new SlackLinkSharedEvent(this.type, this.channelId, this.userId, this.messageTs, this.threadTs, newValue);
}
/**
* This instance is equal to all instances of {@code SlackLinkSharedEvent} 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 SlackLinkSharedEvent
&& equalTo(0, (SlackLinkSharedEvent) another);
}
private boolean equalTo(int synthetic, SlackLinkSharedEvent another) {
return type.equals(another.type)
&& channelId.equals(another.channelId)
&& userId.equals(another.userId)
&& messageTs.equals(another.messageTs)
&& Objects.equals(threadTs, another.threadTs)
&& links.equals(another.links);
}
/**
* Computes a hash code from attributes: {@code type}, {@code channelId}, {@code userId}, {@code messageTs}, {@code threadTs}, {@code links}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + type.hashCode();
h += (h << 5) + channelId.hashCode();
h += (h << 5) + userId.hashCode();
h += (h << 5) + messageTs.hashCode();
h += (h << 5) + Objects.hashCode(threadTs);
h += (h << 5) + links.hashCode();
return h;
}
/**
* Prints the immutable value {@code SlackLinkSharedEvent} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("SlackLinkSharedEvent{");
builder.append("type=").append(type);
builder.append(", ");
builder.append("channelId=").append(channelId);
builder.append(", ");
builder.append("userId=").append(userId);
builder.append(", ");
builder.append("messageTs=").append(messageTs);
if (threadTs != null) {
builder.append(", ");
builder.append("threadTs=").append(threadTs);
}
builder.append(", ");
builder.append("links=").append(links);
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 = "SlackLinkSharedEventIF", generator = "Immutables")
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements SlackLinkSharedEventIF {
@Nullable SlackEventType type;
@Nullable String channelId;
@Nullable String userId;
@Nullable String messageTs;
@Nullable Optional threadTs = Optional.empty();
@Nullable List links = Collections.emptyList();
@JsonProperty
public void setType(SlackEventType type) {
this.type = type;
}
@JsonProperty("channel")
public void setChannelId(String channelId) {
this.channelId = channelId;
}
@JsonProperty("user")
public void setUserId(String userId) {
this.userId = userId;
}
@JsonProperty
public void setMessageTs(String messageTs) {
this.messageTs = messageTs;
}
@JsonProperty
public void setThreadTs(Optional threadTs) {
this.threadTs = threadTs;
}
@JsonProperty
public void setLinks(List links) {
this.links = links;
}
@Override
public SlackEventType getType() { throw new UnsupportedOperationException(); }
@Override
public String getChannelId() { throw new UnsupportedOperationException(); }
@Override
public String getUserId() { throw new UnsupportedOperationException(); }
@Override
public String getMessageTs() { throw new UnsupportedOperationException(); }
@Override
public Optional getThreadTs() { throw new UnsupportedOperationException(); }
@Override
public List getLinks() { 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 SlackLinkSharedEvent fromJson(Json json) {
SlackLinkSharedEvent.Builder builder = SlackLinkSharedEvent.builder();
if (json.type != null) {
builder.setType(json.type);
}
if (json.channelId != null) {
builder.setChannelId(json.channelId);
}
if (json.userId != null) {
builder.setUserId(json.userId);
}
if (json.messageTs != null) {
builder.setMessageTs(json.messageTs);
}
if (json.threadTs != null) {
builder.setThreadTs(json.threadTs);
}
if (json.links != null) {
builder.addAllLinks(json.links);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link SlackLinkSharedEventIF} 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 SlackLinkSharedEvent instance
*/
public static SlackLinkSharedEvent copyOf(SlackLinkSharedEventIF instance) {
if (instance instanceof SlackLinkSharedEvent) {
return (SlackLinkSharedEvent) instance;
}
return SlackLinkSharedEvent.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link SlackLinkSharedEvent SlackLinkSharedEvent}.
*
* SlackLinkSharedEvent.builder()
* .setType(com.hubspot.slack.client.models.events.SlackEventType) // required {@link SlackLinkSharedEventIF#getType() type}
* .setChannelId(String) // required {@link SlackLinkSharedEventIF#getChannelId() channelId}
* .setUserId(String) // required {@link SlackLinkSharedEventIF#getUserId() userId}
* .setMessageTs(String) // required {@link SlackLinkSharedEventIF#getMessageTs() messageTs}
* .setThreadTs(String) // optional {@link SlackLinkSharedEventIF#getThreadTs() threadTs}
* .addLinks|addAllLinks(Link) // {@link SlackLinkSharedEventIF#getLinks() links} elements
* .build();
*
* @return A new SlackLinkSharedEvent builder
*/
public static SlackLinkSharedEvent.Builder builder() {
return new SlackLinkSharedEvent.Builder();
}
/**
* Builds instances of type {@link SlackLinkSharedEvent SlackLinkSharedEvent}.
* 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 = "SlackLinkSharedEventIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_TYPE = 0x1L;
private static final long INIT_BIT_CHANNEL_ID = 0x2L;
private static final long INIT_BIT_USER_ID = 0x4L;
private static final long INIT_BIT_MESSAGE_TS = 0x8L;
private long initBits = 0xfL;
private @Nullable SlackEventType type;
private @Nullable String channelId;
private @Nullable String userId;
private @Nullable String messageTs;
private @Nullable String threadTs;
private List links = new ArrayList();
private Builder() {
}
/**
* 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.links.SlackLinkSharedEventIF} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(SlackLinkSharedEventIF 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 SlackEvent) {
SlackEvent instance = (SlackEvent) object;
if ((bits & 0x1L) == 0) {
this.setType(instance.getType());
bits |= 0x1L;
}
}
if (object instanceof SlackLinkSharedEventIF) {
SlackLinkSharedEventIF instance = (SlackLinkSharedEventIF) object;
addAllLinks(instance.getLinks());
if ((bits & 0x1L) == 0) {
this.setType(instance.getType());
bits |= 0x1L;
}
Optional threadTsOptional = instance.getThreadTs();
if (threadTsOptional.isPresent()) {
setThreadTs(threadTsOptional);
}
this.setUserId(instance.getUserId());
this.setMessageTs(instance.getMessageTs());
this.setChannelId(instance.getChannelId());
}
}
/**
* Initializes the value for the {@link SlackLinkSharedEventIF#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 SlackLinkSharedEventIF#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 value for the {@link SlackLinkSharedEventIF#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 SlackLinkSharedEventIF#getMessageTs() messageTs} attribute.
* @param messageTs The value for messageTs
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty
public final Builder setMessageTs(String messageTs) {
this.messageTs = Objects.requireNonNull(messageTs, "messageTs");
initBits &= ~INIT_BIT_MESSAGE_TS;
return this;
}
/**
* Initializes the optional value {@link SlackLinkSharedEventIF#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 SlackLinkSharedEventIF#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;
}
/**
* Adds one element to {@link SlackLinkSharedEventIF#getLinks() links} list.
* @param element A links element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addLinks(Link element) {
this.links.add(Objects.requireNonNull(element, "links element"));
return this;
}
/**
* Adds elements to {@link SlackLinkSharedEventIF#getLinks() links} list.
* @param elements An array of links elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addLinks(Link... elements) {
for (Link element : elements) {
this.links.add(Objects.requireNonNull(element, "links element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link SlackLinkSharedEventIF#getLinks() links} list.
* @param elements An iterable of links elements
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty
public final Builder setLinks(Iterable extends Link> elements) {
this.links.clear();
return addAllLinks(elements);
}
/**
* Adds elements to {@link SlackLinkSharedEventIF#getLinks() links} list.
* @param elements An iterable of links elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllLinks(Iterable extends Link> elements) {
for (Link element : elements) {
this.links.add(Objects.requireNonNull(element, "links element"));
}
return this;
}
/**
* Builds a new {@link SlackLinkSharedEvent SlackLinkSharedEvent}.
* @return An immutable instance of SlackLinkSharedEvent
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public SlackLinkSharedEvent build() {
checkRequiredAttributes();
return new SlackLinkSharedEvent(type, channelId, userId, messageTs, threadTs, createUnmodifiableList(true, links));
}
private boolean typeIsSet() {
return (initBits & INIT_BIT_TYPE) == 0;
}
private boolean channelIdIsSet() {
return (initBits & INIT_BIT_CHANNEL_ID) == 0;
}
private boolean userIdIsSet() {
return (initBits & INIT_BIT_USER_ID) == 0;
}
private boolean messageTsIsSet() {
return (initBits & INIT_BIT_MESSAGE_TS) == 0;
}
private void checkRequiredAttributes() {
if (initBits != 0) {
throw new InvalidImmutableStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if (!typeIsSet()) attributes.add("type");
if (!channelIdIsSet()) attributes.add("channelId");
if (!userIdIsSet()) attributes.add("userId");
if (!messageTsIsSet()) attributes.add("messageTs");
return "Cannot build SlackLinkSharedEvent, 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);
}
}
}
}