
com.hubspot.slack.client.models.blocks.Actions Maven / Gradle / Ivy
package com.hubspot.slack.client.models.blocks;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.hubspot.slack.client.models.blocks.elements.BlockElement;
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 ActionsIF}.
*
* Use the builder to create immutable instances:
* {@code Actions.builder()}.
* Use the static factory method to create immutable instances:
* {@code Actions.of()}.
*/
@Generated(from = "ActionsIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class Actions implements ActionsIF {
private final @Nullable String blockId;
private transient final String type;
private final List elements;
private Actions(Iterable extends BlockElement> elements) {
this.elements = createUnmodifiableList(false, createSafeList(elements, true, false));
this.blockId = null;
this.type = Objects.requireNonNull(ActionsIF.super.getType(), "type");
}
private Actions(
@Nullable String blockId,
List elements) {
this.blockId = blockId;
this.elements = elements;
this.type = Objects.requireNonNull(ActionsIF.super.getType(), "type");
}
/**
* @return The value of the {@code blockId} attribute
*/
@JsonProperty
@Override
public Optional getBlockId() {
return Optional.ofNullable(blockId);
}
/**
* @return The computed-at-construction value of the {@code type} attribute
*/
@JsonProperty
@Override
public String getType() {
return type;
}
/**
* @return The value of the {@code elements} attribute
*/
@JsonProperty
@Override
public List getElements() {
return elements;
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ActionsIF#getBlockId() blockId} attribute.
* @param value The value for blockId, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final Actions withBlockId(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.blockId, newValue)) return this;
return new Actions(newValue, this.elements);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ActionsIF#getBlockId() blockId} 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 blockId
* @return A modified copy of {@code this} object
*/
public final Actions withBlockId(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.blockId, value)) return this;
return new Actions(value, this.elements);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ActionsIF#getElements() elements}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final Actions withElements(BlockElement... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new Actions(this.blockId, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ActionsIF#getElements() elements}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of elements elements to set
* @return A modified copy of {@code this} object
*/
public final Actions withElements(Iterable extends BlockElement> elements) {
if (this.elements == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return new Actions(this.blockId, newValue);
}
/**
* This instance is equal to all instances of {@code Actions} 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 Actions
&& equalTo(0, (Actions) another);
}
private boolean equalTo(int synthetic, Actions another) {
return Objects.equals(blockId, another.blockId)
&& type.equals(another.type)
&& elements.equals(another.elements);
}
/**
* Computes a hash code from attributes: {@code blockId}, {@code type}, {@code elements}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(blockId);
h += (h << 5) + type.hashCode();
h += (h << 5) + elements.hashCode();
return h;
}
/**
* Prints the immutable value {@code Actions} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("Actions{");
if (blockId != null) {
builder.append("blockId=").append(blockId);
}
if (builder.length() > 8) builder.append(", ");
builder.append("type=").append(type);
builder.append(", ");
builder.append("elements=").append(elements);
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 = "ActionsIF", generator = "Immutables")
@Deprecated
@JsonTypeInfo(use=JsonTypeInfo.Id.NONE)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements ActionsIF {
@Nullable Optional blockId = Optional.empty();
@Nullable List elements = Collections.emptyList();
@JsonProperty
public void setBlockId(Optional blockId) {
this.blockId = blockId;
}
@JsonProperty
public void setElements(List elements) {
this.elements = elements;
}
@Override
public Optional getBlockId() { throw new UnsupportedOperationException(); }
@JsonIgnore
@Override
public String getType() { throw new UnsupportedOperationException(); }
@Override
public List getElements() { 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 Actions fromJson(Json json) {
Actions.Builder builder = Actions.builder();
if (json.blockId != null) {
builder.setBlockId(json.blockId);
}
if (json.elements != null) {
builder.addAllElements(json.elements);
}
return builder.build();
}
/**
* Construct a new immutable {@code Actions} instance.
* @param elements The value for the {@code elements} attribute
* @return An immutable Actions instance
*/
public static Actions of(List elements) {
return of((Iterable extends BlockElement>) elements);
}
/**
* Construct a new immutable {@code Actions} instance.
* @param elements The value for the {@code elements} attribute
* @return An immutable Actions instance
*/
public static Actions of(Iterable extends BlockElement> elements) {
return new Actions(elements);
}
/**
* Creates an immutable copy of a {@link ActionsIF} 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 Actions instance
*/
public static Actions copyOf(ActionsIF instance) {
if (instance instanceof Actions) {
return (Actions) instance;
}
return Actions.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link Actions Actions}.
*
* Actions.builder()
* .setBlockId(String) // optional {@link ActionsIF#getBlockId() blockId}
* .addElements|addAllElements(com.hubspot.slack.client.models.blocks.elements.BlockElement) // {@link ActionsIF#getElements() elements} elements
* .build();
*
* @return A new Actions builder
*/
public static Actions.Builder builder() {
return new Actions.Builder();
}
/**
* Builds instances of type {@link Actions Actions}.
* 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 = "ActionsIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private @Nullable String blockId;
private List elements = new ArrayList();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.hubspot.slack.client.models.blocks.Block} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(Block 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.blocks.ActionsIF} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(ActionsIF 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 Block) {
Block instance = (Block) object;
if ((bits & 0x1L) == 0) {
Optional blockIdOptional = instance.getBlockId();
if (blockIdOptional.isPresent()) {
setBlockId(blockIdOptional);
}
bits |= 0x1L;
}
}
if (object instanceof ActionsIF) {
ActionsIF instance = (ActionsIF) object;
if ((bits & 0x1L) == 0) {
Optional blockIdOptional = instance.getBlockId();
if (blockIdOptional.isPresent()) {
setBlockId(blockIdOptional);
}
bits |= 0x1L;
}
addAllElements(instance.getElements());
}
}
/**
* Initializes the optional value {@link ActionsIF#getBlockId() blockId} to blockId.
* @param blockId The value for blockId, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setBlockId(@Nullable String blockId) {
this.blockId = blockId;
return this;
}
/**
* Initializes the optional value {@link ActionsIF#getBlockId() blockId} to blockId.
* @param blockId The value for blockId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setBlockId(Optional blockId) {
this.blockId = blockId.orElse(null);
return this;
}
/**
* Adds one element to {@link ActionsIF#getElements() elements} list.
* @param element A elements element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addElements(BlockElement element) {
this.elements.add(Objects.requireNonNull(element, "elements element"));
return this;
}
/**
* Adds elements to {@link ActionsIF#getElements() elements} list.
* @param elements An array of elements elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addElements(BlockElement... elements) {
for (BlockElement element : elements) {
this.elements.add(Objects.requireNonNull(element, "elements element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link ActionsIF#getElements() elements} list.
* @param elements An iterable of elements elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setElements(Iterable extends BlockElement> elements) {
this.elements.clear();
return addAllElements(elements);
}
/**
* Adds elements to {@link ActionsIF#getElements() elements} list.
* @param elements An iterable of elements elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllElements(Iterable extends BlockElement> elements) {
for (BlockElement element : elements) {
this.elements.add(Objects.requireNonNull(element, "elements element"));
}
return this;
}
/**
* Builds a new {@link Actions Actions}.
* @return An immutable instance of Actions
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public Actions build() {
return new Actions(blockId, createUnmodifiableList(true, elements));
}
}
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);
}
}
}
}