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