
com.hubspot.slack.client.models.events.SlackEventSkeleton 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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
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 SlackEventSkeletonIF}.
*
* Use the builder to create immutable instances:
* {@code SlackEventSkeleton.builder()}.
*/
@Generated(from = "SlackEventSkeletonIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class SlackEventSkeleton implements SlackEventSkeletonIF {
private final SlackEventType type;
private final String ts;
private final @Nullable String channelMaybe;
private SlackEventSkeleton(
SlackEventType type,
String ts,
@Nullable String channelMaybe) {
this.type = type;
this.ts = ts;
this.channelMaybe = channelMaybe;
}
/**
* @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 channelMaybe} attribute
*/
@JsonProperty("channel")
@Override
public Optional getChannelMaybe() {
return Optional.ofNullable(channelMaybe);
}
/**
* Copy the current immutable object by setting a value for the {@link SlackEventSkeletonIF#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 SlackEventSkeleton withType(SlackEventType value) {
SlackEventType newValue = Objects.requireNonNull(value, "type");
if (this.type == newValue) return this;
return new SlackEventSkeleton(newValue, this.ts, this.channelMaybe);
}
/**
* Copy the current immutable object by setting a value for the {@link SlackEventSkeletonIF#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 SlackEventSkeleton withTs(String value) {
String newValue = Objects.requireNonNull(value, "ts");
if (this.ts.equals(newValue)) return this;
return new SlackEventSkeleton(this.type, newValue, this.channelMaybe);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link SlackEventSkeletonIF#getChannelMaybe() channelMaybe} attribute.
* @param value The value for channelMaybe, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final SlackEventSkeleton withChannelMaybe(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.channelMaybe, newValue)) return this;
return new SlackEventSkeleton(this.type, this.ts, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link SlackEventSkeletonIF#getChannelMaybe() channelMaybe} 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 channelMaybe
* @return A modified copy of {@code this} object
*/
public final SlackEventSkeleton withChannelMaybe(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.channelMaybe, value)) return this;
return new SlackEventSkeleton(this.type, this.ts, value);
}
/**
* This instance is equal to all instances of {@code SlackEventSkeleton} 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 SlackEventSkeleton
&& equalTo(0, (SlackEventSkeleton) another);
}
private boolean equalTo(int synthetic, SlackEventSkeleton another) {
return type.equals(another.type)
&& ts.equals(another.ts)
&& Objects.equals(channelMaybe, another.channelMaybe);
}
/**
* Computes a hash code from attributes: {@code type}, {@code ts}, {@code channelMaybe}.
* @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(channelMaybe);
return h;
}
/**
* Prints the immutable value {@code SlackEventSkeleton} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("SlackEventSkeleton{");
builder.append("type=").append(type);
builder.append(", ");
builder.append("ts=").append(ts);
if (channelMaybe != null) {
builder.append(", ");
builder.append("channelMaybe=").append(channelMaybe);
}
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 = "SlackEventSkeletonIF", generator = "Immutables")
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements SlackEventSkeletonIF {
@Nullable SlackEventType type;
@Nullable String ts;
@Nullable Optional channelMaybe = Optional.empty();
@JsonProperty
public void setType(SlackEventType type) {
this.type = type;
}
@JsonProperty
public void setTs(String ts) {
this.ts = ts;
}
@JsonProperty("channel")
public void setChannelMaybe(Optional channelMaybe) {
this.channelMaybe = channelMaybe;
}
@Override
public SlackEventType getType() { throw new UnsupportedOperationException(); }
@Override
public String getTs() { throw new UnsupportedOperationException(); }
@Override
public Optional getChannelMaybe() { 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 SlackEventSkeleton fromJson(Json json) {
SlackEventSkeleton.Builder builder = SlackEventSkeleton.builder();
if (json.type != null) {
builder.setType(json.type);
}
if (json.ts != null) {
builder.setTs(json.ts);
}
if (json.channelMaybe != null) {
builder.setChannelMaybe(json.channelMaybe);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link SlackEventSkeletonIF} 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 SlackEventSkeleton instance
*/
public static SlackEventSkeleton copyOf(SlackEventSkeletonIF instance) {
if (instance instanceof SlackEventSkeleton) {
return (SlackEventSkeleton) instance;
}
return SlackEventSkeleton.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link SlackEventSkeleton SlackEventSkeleton}.
*
* SlackEventSkeleton.builder()
* .setType(com.hubspot.slack.client.models.events.SlackEventType) // required {@link SlackEventSkeletonIF#getType() type}
* .setTs(String) // required {@link SlackEventSkeletonIF#getTs() ts}
* .setChannelMaybe(String) // optional {@link SlackEventSkeletonIF#getChannelMaybe() channelMaybe}
* .build();
*
* @return A new SlackEventSkeleton builder
*/
public static SlackEventSkeleton.Builder builder() {
return new SlackEventSkeleton.Builder();
}
/**
* Builds instances of type {@link SlackEventSkeleton SlackEventSkeleton}.
* 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 = "SlackEventSkeletonIF", 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 long initBits = 0x3L;
private @Nullable SlackEventType type;
private @Nullable String ts;
private @Nullable String channelMaybe;
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.SlackEventSkeletonIF} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(SlackEventSkeletonIF 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 ((bits & 0x2L) == 0) {
this.setTs(instance.getTs());
bits |= 0x2L;
}
}
if (object instanceof SlackEventSkeletonIF) {
SlackEventSkeletonIF instance = (SlackEventSkeletonIF) object;
if ((bits & 0x1L) == 0) {
this.setType(instance.getType());
bits |= 0x1L;
}
Optional channelMaybeOptional = instance.getChannelMaybe();
if (channelMaybeOptional.isPresent()) {
setChannelMaybe(channelMaybeOptional);
}
if ((bits & 0x2L) == 0) {
this.setTs(instance.getTs());
bits |= 0x2L;
}
}
}
/**
* Initializes the value for the {@link SlackEventSkeletonIF#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 SlackEventSkeletonIF#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 SlackEventSkeletonIF#getChannelMaybe() channelMaybe} to channelMaybe.
* @param channelMaybe The value for channelMaybe, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setChannelMaybe(@Nullable String channelMaybe) {
this.channelMaybe = channelMaybe;
return this;
}
/**
* Initializes the optional value {@link SlackEventSkeletonIF#getChannelMaybe() channelMaybe} to channelMaybe.
* @param channelMaybe The value for channelMaybe
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("channel")
public final Builder setChannelMaybe(Optional channelMaybe) {
this.channelMaybe = channelMaybe.orElse(null);
return this;
}
/**
* Builds a new {@link SlackEventSkeleton SlackEventSkeleton}.
* @return An immutable instance of SlackEventSkeleton
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public SlackEventSkeleton build() {
checkRequiredAttributes();
return new SlackEventSkeleton(type, ts, channelMaybe);
}
private boolean typeIsSet() {
return (initBits & INIT_BIT_TYPE) == 0;
}
private boolean tsIsSet() {
return (initBits & INIT_BIT_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 (!tsIsSet()) attributes.add("ts");
return "Cannot build SlackEventSkeleton, some of required attributes are not set " + attributes;
}
}
}