
com.hubspot.slack.client.models.blocks.Section 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.immutables.validation.InvalidImmutableStateException;
import com.hubspot.slack.client.models.blocks.elements.BlockElement;
import com.hubspot.slack.client.models.blocks.objects.Text;
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 SectionIF}.
*
* Use the builder to create immutable instances:
* {@code Section.builder()}.
* Use the static factory method to create immutable instances:
* {@code Section.of()}.
*/
@Generated(from = "SectionIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class Section implements SectionIF {
private final @Nullable String blockId;
private transient final String type;
private final @Nullable Text text;
private final List fields;
private final @Nullable BlockElement accessory;
private Section(@Nullable Text text) {
initShim.setText(text);
this.blockId = null;
this.fields = Collections.emptyList();
this.accessory = null;
this.type = initShim.getType();
this.text = initShim.getText();
this.initShim = null;
}
private Section(Section.Builder builder) {
this.blockId = builder.blockId;
this.fields = createUnmodifiableList(true, builder.fields);
this.accessory = builder.accessory;
if (builder.textIsSet()) {
initShim.setText(builder.text);
}
this.type = initShim.getType();
this.text = initShim.getText();
this.initShim = null;
}
private Section(
@Nullable String blockId,
@Nullable Text text,
List fields,
@Nullable BlockElement accessory) {
this.blockId = blockId;
initShim.setText(text);
this.fields = fields;
this.accessory = accessory;
this.type = initShim.getType();
this.text = initShim.getText();
this.initShim = null;
}
private static final byte STAGE_INITIALIZING = -1;
private static final byte STAGE_UNINITIALIZED = 0;
private static final byte STAGE_INITIALIZED = 1;
private transient volatile InitShim initShim = new InitShim();
@Generated(from = "SectionIF", generator = "Immutables")
private final class InitShim {
private byte typeBuildStage = STAGE_UNINITIALIZED;
private String type;
String getType() {
if (typeBuildStage == STAGE_INITIALIZING) throw new InvalidImmutableStateException(formatInitCycleMessage());
if (typeBuildStage == STAGE_UNINITIALIZED) {
typeBuildStage = STAGE_INITIALIZING;
this.type = Objects.requireNonNull(getTypeInitialize(), "type");
typeBuildStage = STAGE_INITIALIZED;
}
return this.type;
}
private byte textBuildStage = STAGE_UNINITIALIZED;
private Text text;
Text getText() {
if (textBuildStage == STAGE_INITIALIZING) throw new InvalidImmutableStateException(formatInitCycleMessage());
if (textBuildStage == STAGE_UNINITIALIZED) {
textBuildStage = STAGE_INITIALIZING;
this.text = getTextInitialize();
textBuildStage = STAGE_INITIALIZED;
}
return this.text;
}
void setText(Text text) {
this.text = text;
textBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
List attributes = new ArrayList<>();
if (typeBuildStage == STAGE_INITIALIZING) attributes.add("type");
if (textBuildStage == STAGE_INITIALIZING) attributes.add("text");
return "Cannot build Section, attribute initializers form cycle " + attributes;
}
}
private String getTypeInitialize() {
return SectionIF.super.getType();
}
private @Nullable Text getTextInitialize() {
return SectionIF.super.getText();
}
/**
* @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() {
InitShim shim = this.initShim;
return shim != null
? shim.getType()
: this.type;
}
/**
* @return The value of the {@code text} attribute
*/
@JsonProperty
@Override
public @Nullable Text getText() {
InitShim shim = this.initShim;
return shim != null
? shim.getText()
: this.text;
}
/**
* @return The value of the {@code fields} attribute
*/
@JsonProperty
@Override
public List getFields() {
return fields;
}
/**
* @return The value of the {@code accessory} attribute
*/
@JsonProperty
@Override
public Optional getAccessory() {
return Optional.ofNullable(accessory);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link SectionIF#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 Section withBlockId(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.blockId, newValue)) return this;
return validate(new Section(newValue, this.text, this.fields, this.accessory));
}
/**
* Copy the current immutable object by setting an optional value for the {@link SectionIF#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 Section withBlockId(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.blockId, value)) return this;
return validate(new Section(value, this.text, this.fields, this.accessory));
}
/**
* Copy the current immutable object by setting a value for the {@link SectionIF#getText() text} 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 text (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final Section withText(@Nullable Text value) {
if (this.text == value) return this;
return validate(new Section(this.blockId, value, this.fields, this.accessory));
}
/**
* Copy the current immutable object with elements that replace the content of {@link SectionIF#getFields() fields}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final Section withFields(Text... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return validate(new Section(this.blockId, this.text, newValue, this.accessory));
}
/**
* Copy the current immutable object with elements that replace the content of {@link SectionIF#getFields() fields}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of fields elements to set
* @return A modified copy of {@code this} object
*/
public final Section withFields(Iterable extends Text> elements) {
if (this.fields == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return validate(new Section(this.blockId, this.text, newValue, this.accessory));
}
/**
* Copy the current immutable object by setting a present value for the optional {@link SectionIF#getAccessory() accessory} attribute.
* @param value The value for accessory, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final Section withAccessory(@Nullable BlockElement value) {
@Nullable BlockElement newValue = value;
if (this.accessory == newValue) return this;
return validate(new Section(this.blockId, this.text, this.fields, newValue));
}
/**
* Copy the current immutable object by setting an optional value for the {@link SectionIF#getAccessory() accessory} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for accessory
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final Section withAccessory(Optional extends BlockElement> optional) {
@Nullable BlockElement value = optional.orElse(null);
if (this.accessory == value) return this;
return validate(new Section(this.blockId, this.text, this.fields, value));
}
/**
* This instance is equal to all instances of {@code Section} 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 Section
&& equalTo(0, (Section) another);
}
private boolean equalTo(int synthetic, Section another) {
return Objects.equals(blockId, another.blockId)
&& type.equals(another.type)
&& Objects.equals(text, another.text)
&& fields.equals(another.fields)
&& Objects.equals(accessory, another.accessory);
}
/**
* Computes a hash code from attributes: {@code blockId}, {@code type}, {@code text}, {@code fields}, {@code accessory}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(blockId);
h += (h << 5) + type.hashCode();
h += (h << 5) + Objects.hashCode(text);
h += (h << 5) + fields.hashCode();
h += (h << 5) + Objects.hashCode(accessory);
return h;
}
/**
* Prints the immutable value {@code Section} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("Section{");
if (blockId != null) {
builder.append("blockId=").append(blockId);
}
if (builder.length() > 8) builder.append(", ");
builder.append("type=").append(type);
if (text != null) {
builder.append(", ");
builder.append("text=").append(text);
}
builder.append(", ");
builder.append("fields=").append(fields);
if (accessory != null) {
builder.append(", ");
builder.append("accessory=").append(accessory);
}
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 = "SectionIF", generator = "Immutables")
@Deprecated
@JsonTypeInfo(use=JsonTypeInfo.Id.NONE)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements SectionIF {
@Nullable Optional blockId = Optional.empty();
@Nullable Text text;
boolean textIsSet;
@Nullable List fields = Collections.emptyList();
@Nullable Optional accessory = Optional.empty();
@JsonProperty
public void setBlockId(Optional blockId) {
this.blockId = blockId;
}
@JsonProperty
public void setText(@Nullable Text text) {
this.text = text;
this.textIsSet = true;
}
@JsonProperty
public void setFields(List fields) {
this.fields = fields;
}
@JsonProperty
public void setAccessory(Optional accessory) {
this.accessory = accessory;
}
@Override
public Optional getBlockId() { throw new UnsupportedOperationException(); }
@JsonIgnore
@Override
public String getType() { throw new UnsupportedOperationException(); }
@Override
public Text getText() { throw new UnsupportedOperationException(); }
@Override
public List getFields() { throw new UnsupportedOperationException(); }
@Override
public Optional getAccessory() { 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 Section fromJson(Json json) {
Section.Builder builder = Section.builder();
if (json.blockId != null) {
builder.setBlockId(json.blockId);
}
if (json.textIsSet) {
builder.setText(json.text);
}
if (json.fields != null) {
builder.addAllFields(json.fields);
}
if (json.accessory != null) {
builder.setAccessory(json.accessory);
}
return builder.build();
}
/**
* Construct a new immutable {@code Section} instance.
* @param text The value for the {@code text} attribute
* @return An immutable Section instance
*/
public static Section of(@Nullable Text text) {
return validate(new Section(text));
}
private static Section validate(Section instance) {
instance.check();
return instance;
}
/**
* Creates an immutable copy of a {@link SectionIF} 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 Section instance
*/
public static Section copyOf(SectionIF instance) {
if (instance instanceof Section) {
return (Section) instance;
}
return Section.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link Section Section}.
*
* Section.builder()
* .setBlockId(String) // optional {@link SectionIF#getBlockId() blockId}
* .setText(com.hubspot.slack.client.models.blocks.objects.Text | null) // nullable {@link SectionIF#getText() text}
* .addFields|addAllFields(com.hubspot.slack.client.models.blocks.objects.Text) // {@link SectionIF#getFields() fields} elements
* .setAccessory(com.hubspot.slack.client.models.blocks.elements.BlockElement) // optional {@link SectionIF#getAccessory() accessory}
* .build();
*
* @return A new Section builder
*/
public static Section.Builder builder() {
return new Section.Builder();
}
/**
* Builds instances of type {@link Section Section}.
* 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 = "SectionIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long OPT_BIT_TEXT = 0x1L;
private long optBits;
private @Nullable String blockId;
private @Nullable Text text;
private List fields = new ArrayList();
private @Nullable BlockElement accessory;
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.SectionIF} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(SectionIF 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 SectionIF) {
SectionIF instance = (SectionIF) object;
if ((bits & 0x1L) == 0) {
Optional blockIdOptional = instance.getBlockId();
if (blockIdOptional.isPresent()) {
setBlockId(blockIdOptional);
}
bits |= 0x1L;
}
@Nullable Text textValue = instance.getText();
if (textValue != null) {
setText(textValue);
}
addAllFields(instance.getFields());
Optional accessoryOptional = instance.getAccessory();
if (accessoryOptional.isPresent()) {
setAccessory(accessoryOptional);
}
}
}
/**
* Initializes the optional value {@link SectionIF#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 SectionIF#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;
}
/**
* Initializes the value for the {@link SectionIF#getText() text} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link SectionIF#getText() text}.
* @param text The value for text (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setText(@Nullable Text text) {
this.text = text;
optBits |= OPT_BIT_TEXT;
return this;
}
/**
* Adds one element to {@link SectionIF#getFields() fields} list.
* @param element A fields element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addFields(Text element) {
this.fields.add(Objects.requireNonNull(element, "fields element"));
return this;
}
/**
* Adds elements to {@link SectionIF#getFields() fields} list.
* @param elements An array of fields elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addFields(Text... elements) {
for (Text element : elements) {
this.fields.add(Objects.requireNonNull(element, "fields element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link SectionIF#getFields() fields} list.
* @param elements An iterable of fields elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setFields(Iterable extends Text> elements) {
this.fields.clear();
return addAllFields(elements);
}
/**
* Adds elements to {@link SectionIF#getFields() fields} list.
* @param elements An iterable of fields elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllFields(Iterable extends Text> elements) {
for (Text element : elements) {
this.fields.add(Objects.requireNonNull(element, "fields element"));
}
return this;
}
/**
* Initializes the optional value {@link SectionIF#getAccessory() accessory} to accessory.
* @param accessory The value for accessory, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setAccessory(@Nullable BlockElement accessory) {
this.accessory = accessory;
return this;
}
/**
* Initializes the optional value {@link SectionIF#getAccessory() accessory} to accessory.
* @param accessory The value for accessory
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setAccessory(Optional extends BlockElement> accessory) {
this.accessory = accessory.orElse(null);
return this;
}
/**
* Builds a new {@link Section Section}.
* @return An immutable instance of Section
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public Section build() {
return Section.validate(new Section(this));
}
private boolean textIsSet() {
return (optBits & OPT_BIT_TEXT) != 0;
}
}
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);
}
}
}
}