All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hubspot.slack.client.models.blocks.Context 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.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.hubspot.slack.client.models.blocks.json.ImageBlockOrTextDeserializer;
import com.hubspot.slack.client.models.blocks.objects.ImageBlockOrText;
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 ContextIF}.
 * 

* Use the builder to create immutable instances: * {@code Context.builder()}. * Use the static factory method to create immutable instances: * {@code Context.of()}. */ @Generated(from = "ContextIF", generator = "Immutables") @SuppressWarnings({"all"}) @SuppressFBWarnings @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable public final class Context implements ContextIF { private final @Nullable String blockId; private transient final String type; private final List elements; private Context(Iterable elements) { this.elements = createUnmodifiableList(false, createSafeList(elements, true, false)); this.blockId = null; this.type = Objects.requireNonNull(ContextIF.super.getType(), "type"); } private Context( @Nullable String blockId, List elements) { this.blockId = blockId; this.elements = elements; this.type = Objects.requireNonNull(ContextIF.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 @JsonDeserialize(contentUsing = ImageBlockOrTextDeserializer.class) @Override public List getElements() { return elements; } /** * Copy the current immutable object by setting a present value for the optional {@link ContextIF#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 Context withBlockId(@Nullable String value) { @Nullable String newValue = value; if (Objects.equals(this.blockId, newValue)) return this; return new Context(newValue, this.elements); } /** * Copy the current immutable object by setting an optional value for the {@link ContextIF#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 Context withBlockId(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.blockId, value)) return this; return new Context(value, this.elements); } /** * Copy the current immutable object with elements that replace the content of {@link ContextIF#getElements() elements}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final Context withElements(ImageBlockOrText... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return new Context(this.blockId, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link ContextIF#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 Context withElements(Iterable elements) { if (this.elements == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return new Context(this.blockId, newValue); } /** * This instance is equal to all instances of {@code Context} 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 Context && equalTo(0, (Context) another); } private boolean equalTo(int synthetic, Context 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 Context} with attribute values. * @return A string representation of the value */ @Override public String toString() { StringBuilder builder = new StringBuilder("Context{"); 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 = "ContextIF", generator = "Immutables") @Deprecated @JsonTypeInfo(use=JsonTypeInfo.Id.NONE) @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements ContextIF { @Nullable Optional blockId = Optional.empty(); @Nullable List elements = Collections.emptyList(); @JsonProperty public void setBlockId(Optional blockId) { this.blockId = blockId; } @JsonProperty @JsonDeserialize(contentUsing = ImageBlockOrTextDeserializer.class) 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 Context fromJson(Json json) { Context.Builder builder = Context.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 Context} instance. * @param elements The value for the {@code elements} attribute * @return An immutable Context instance */ public static Context of(List elements) { return of((Iterable) elements); } /** * Construct a new immutable {@code Context} instance. * @param elements The value for the {@code elements} attribute * @return An immutable Context instance */ public static Context of(Iterable elements) { return new Context(elements); } /** * Creates an immutable copy of a {@link ContextIF} 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 Context instance */ public static Context copyOf(ContextIF instance) { if (instance instanceof Context) { return (Context) instance; } return Context.builder() .from(instance) .build(); } /** * Creates a builder for {@link Context Context}. *

   * Context.builder()
   *    .setBlockId(String) // optional {@link ContextIF#getBlockId() blockId}
   *    .addElements|addAllElements(com.hubspot.slack.client.models.blocks.objects.ImageBlockOrText) // {@link ContextIF#getElements() elements} elements
   *    .build();
   * 
* @return A new Context builder */ public static Context.Builder builder() { return new Context.Builder(); } /** * Builds instances of type {@link Context Context}. * 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 = "ContextIF", 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.ContextIF} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(ContextIF 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 ContextIF) { ContextIF instance = (ContextIF) object; if ((bits & 0x1L) == 0) { Optional blockIdOptional = instance.getBlockId(); if (blockIdOptional.isPresent()) { setBlockId(blockIdOptional); } bits |= 0x1L; } addAllElements(instance.getElements()); } } /** * Initializes the optional value {@link ContextIF#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 ContextIF#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 ContextIF#getElements() elements} list. * @param element A elements element * @return {@code this} builder for use in a chained invocation */ public final Builder addElements(ImageBlockOrText element) { this.elements.add(Objects.requireNonNull(element, "elements element")); return this; } /** * Adds elements to {@link ContextIF#getElements() elements} list. * @param elements An array of elements elements * @return {@code this} builder for use in a chained invocation */ public final Builder addElements(ImageBlockOrText... elements) { for (ImageBlockOrText element : elements) { this.elements.add(Objects.requireNonNull(element, "elements element")); } return this; } /** * Sets or replaces all elements for {@link ContextIF#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 elements) { this.elements.clear(); return addAllElements(elements); } /** * Adds elements to {@link ContextIF#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 elements) { for (ImageBlockOrText element : elements) { this.elements.add(Objects.requireNonNull(element, "elements element")); } return this; } /** * Builds a new {@link Context Context}. * @return An immutable instance of Context * @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing */ public Context build() { return new Context(blockId, createUnmodifiableList(true, elements)); } } private static List createSafeList(Iterable 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); } } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy