
com.hubspot.slack.client.models.blocks.Header 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.objects.Text;
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 HeaderIF}.
*
* Use the builder to create immutable instances:
* {@code Header.builder()}.
* Use the static factory method to create immutable instances:
* {@code Header.of()}.
*/
@Generated(from = "HeaderIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class Header implements HeaderIF {
private final @Nullable String blockId;
private transient final String type;
private final Text text;
private Header(Text text) {
this.text = Objects.requireNonNull(text, "text");
this.blockId = null;
this.type = Objects.requireNonNull(HeaderIF.super.getType(), "type");
}
private Header(
@Nullable String blockId,
Text text) {
this.blockId = blockId;
this.text = text;
this.type = Objects.requireNonNull(HeaderIF.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 text} attribute
*/
@JsonProperty
@Override
public Text getText() {
return text;
}
/**
* Copy the current immutable object by setting a present value for the optional {@link HeaderIF#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 Header withBlockId(@Nullable String value) {
@Nullable String newValue = value;
if (Objects.equals(this.blockId, newValue)) return this;
return validate(new Header(newValue, this.text));
}
/**
* Copy the current immutable object by setting an optional value for the {@link HeaderIF#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 Header withBlockId(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.blockId, value)) return this;
return validate(new Header(value, this.text));
}
/**
* Copy the current immutable object by setting a value for the {@link HeaderIF#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
* @return A modified copy of the {@code this} object
*/
public final Header withText(Text value) {
if (this.text == value) return this;
Text newValue = Objects.requireNonNull(value, "text");
return validate(new Header(this.blockId, newValue));
}
/**
* This instance is equal to all instances of {@code Header} 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 Header
&& equalTo(0, (Header) another);
}
private boolean equalTo(int synthetic, Header another) {
return Objects.equals(blockId, another.blockId)
&& type.equals(another.type)
&& text.equals(another.text);
}
/**
* Computes a hash code from attributes: {@code blockId}, {@code type}, {@code text}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(blockId);
h += (h << 5) + type.hashCode();
h += (h << 5) + text.hashCode();
return h;
}
/**
* Prints the immutable value {@code Header} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("Header{");
if (blockId != null) {
builder.append("blockId=").append(blockId);
}
if (builder.length() > 7) builder.append(", ");
builder.append("type=").append(type);
builder.append(", ");
builder.append("text=").append(text);
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 = "HeaderIF", generator = "Immutables")
@Deprecated
@JsonTypeInfo(use=JsonTypeInfo.Id.NONE)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements HeaderIF {
@Nullable Optional blockId = Optional.empty();
@Nullable Text text;
@JsonProperty
public void setBlockId(Optional blockId) {
this.blockId = blockId;
}
@JsonProperty
public void setText(Text text) {
this.text = text;
}
@Override
public Optional getBlockId() { throw new UnsupportedOperationException(); }
@JsonIgnore
@Override
public String getType() { throw new UnsupportedOperationException(); }
@Override
public Text getText() { 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 Header fromJson(Json json) {
Header.Builder builder = Header.builder();
if (json.blockId != null) {
builder.setBlockId(json.blockId);
}
if (json.text != null) {
builder.setText(json.text);
}
return builder.build();
}
/**
* Construct a new immutable {@code Header} instance.
* @param text The value for the {@code text} attribute
* @return An immutable Header instance
*/
public static Header of(Text text) {
return validate(new Header(text));
}
private static Header validate(Header instance) {
instance.check();
return instance;
}
/**
* Creates an immutable copy of a {@link HeaderIF} 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 Header instance
*/
public static Header copyOf(HeaderIF instance) {
if (instance instanceof Header) {
return (Header) instance;
}
return Header.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link Header Header}.
*
* Header.builder()
* .setBlockId(String) // optional {@link HeaderIF#getBlockId() blockId}
* .setText(com.hubspot.slack.client.models.blocks.objects.Text) // required {@link HeaderIF#getText() text}
* .build();
*
* @return A new Header builder
*/
public static Header.Builder builder() {
return new Header.Builder();
}
/**
* Builds instances of type {@link Header Header}.
* 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 = "HeaderIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_TEXT = 0x1L;
private long initBits = 0x1L;
private @Nullable String blockId;
private @Nullable Text text;
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.HeaderIF} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(HeaderIF 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 HeaderIF) {
HeaderIF instance = (HeaderIF) object;
if ((bits & 0x1L) == 0) {
Optional blockIdOptional = instance.getBlockId();
if (blockIdOptional.isPresent()) {
setBlockId(blockIdOptional);
}
bits |= 0x1L;
}
this.setText(instance.getText());
}
}
/**
* Initializes the optional value {@link HeaderIF#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 HeaderIF#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 HeaderIF#getText() text} attribute.
* @param text The value for text
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setText(Text text) {
this.text = Objects.requireNonNull(text, "text");
initBits &= ~INIT_BIT_TEXT;
return this;
}
/**
* Builds a new {@link Header Header}.
* @return An immutable instance of Header
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public Header build() {
checkRequiredAttributes();
return Header.validate(new Header(blockId, text));
}
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 (!textIsSet()) attributes.add("text");
return "Cannot build Header, some of required attributes are not set " + attributes;
}
}
}