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

com.hubspot.slack.client.models.response.SlackErrorResponse Maven / Gradle / Ivy

package com.hubspot.slack.client.models.response;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.hubspot.immutables.validation.InvalidImmutableStateException;
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 SlackErrorResponseIF}.
 * 

* Use the builder to create immutable instances: * {@code SlackErrorResponse.builder()}. */ @Generated(from = "SlackErrorResponseIF", generator = "Immutables") @SuppressWarnings({"all"}) @SuppressFBWarnings @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable public final class SlackErrorResponse implements SlackErrorResponseIF { private final boolean ok; private final @Nullable ResponseMetadata responseMetadata; private final @Nullable SlackError error; private final List errors; private SlackErrorResponse( boolean ok, @Nullable ResponseMetadata responseMetadata, @Nullable SlackError error, List errors) { this.ok = ok; this.responseMetadata = responseMetadata; this.error = error; this.errors = errors; } /** * @return The value of the {@code ok} attribute */ @JsonProperty @Override public boolean isOk() { return ok; } /** * @return The value of the {@code responseMetadata} attribute */ @JsonProperty("response_metadata") @Override public Optional getResponseMetadata() { return Optional.ofNullable(responseMetadata); } /** * @return The value of the {@code error} attribute */ @JsonProperty @Override public Optional getError() { return Optional.ofNullable(error); } /** * @return The value of the {@code errors} attribute */ @JsonProperty @Override public List getErrors() { return errors; } /** * Copy the current immutable object by setting a value for the {@link SlackErrorResponseIF#isOk() ok} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for ok * @return A modified copy of the {@code this} object */ public final SlackErrorResponse withOk(boolean value) { if (this.ok == value) return this; return new SlackErrorResponse(value, this.responseMetadata, this.error, this.errors); } /** * Copy the current immutable object by setting a present value for the optional {@link SlackErrorResponseIF#getResponseMetadata() responseMetadata} attribute. * @param value The value for responseMetadata, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final SlackErrorResponse withResponseMetadata(@Nullable ResponseMetadata value) { @Nullable ResponseMetadata newValue = value; if (this.responseMetadata == newValue) return this; return new SlackErrorResponse(this.ok, newValue, this.error, this.errors); } /** * Copy the current immutable object by setting an optional value for the {@link SlackErrorResponseIF#getResponseMetadata() responseMetadata} 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 responseMetadata * @return A modified copy of {@code this} object */ @SuppressWarnings("unchecked") // safe covariant cast public final SlackErrorResponse withResponseMetadata(Optional optional) { @Nullable ResponseMetadata value = optional.orElse(null); if (this.responseMetadata == value) return this; return new SlackErrorResponse(this.ok, value, this.error, this.errors); } /** * Copy the current immutable object by setting a present value for the optional {@link SlackErrorResponseIF#getError() error} attribute. * @param value The value for error, {@code null} is accepted as {@code java.util.Optional.empty()} * @return A modified copy of {@code this} object */ public final SlackErrorResponse withError(@Nullable SlackError value) { @Nullable SlackError newValue = value; if (this.error == newValue) return this; return new SlackErrorResponse(this.ok, this.responseMetadata, newValue, this.errors); } /** * Copy the current immutable object by setting an optional value for the {@link SlackErrorResponseIF#getError() error} 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 error * @return A modified copy of {@code this} object */ @SuppressWarnings("unchecked") // safe covariant cast public final SlackErrorResponse withError(Optional optional) { @Nullable SlackError value = optional.orElse(null); if (this.error == value) return this; return new SlackErrorResponse(this.ok, this.responseMetadata, value, this.errors); } /** * Copy the current immutable object with elements that replace the content of {@link SlackErrorResponseIF#getErrors() errors}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final SlackErrorResponse withErrors(SlackError... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return new SlackErrorResponse(this.ok, this.responseMetadata, this.error, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link SlackErrorResponseIF#getErrors() errors}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of errors elements to set * @return A modified copy of {@code this} object */ public final SlackErrorResponse withErrors(Iterable elements) { if (this.errors == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return new SlackErrorResponse(this.ok, this.responseMetadata, this.error, newValue); } /** * This instance is equal to all instances of {@code SlackErrorResponse} 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 SlackErrorResponse && equalTo(0, (SlackErrorResponse) another); } private boolean equalTo(int synthetic, SlackErrorResponse another) { return ok == another.ok && Objects.equals(responseMetadata, another.responseMetadata) && Objects.equals(error, another.error) && errors.equals(another.errors); } /** * Computes a hash code from attributes: {@code ok}, {@code responseMetadata}, {@code error}, {@code errors}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Boolean.hashCode(ok); h += (h << 5) + Objects.hashCode(responseMetadata); h += (h << 5) + Objects.hashCode(error); h += (h << 5) + errors.hashCode(); return h; } /** * Prints the immutable value {@code SlackErrorResponse} with attribute values. * @return A string representation of the value */ @Override public String toString() { StringBuilder builder = new StringBuilder("SlackErrorResponse{"); builder.append("ok=").append(ok); if (responseMetadata != null) { builder.append(", "); builder.append("responseMetadata=").append(responseMetadata); } if (error != null) { builder.append(", "); builder.append("error=").append(error); } builder.append(", "); builder.append("errors=").append(errors); 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 = "SlackErrorResponseIF", generator = "Immutables") @Deprecated @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements SlackErrorResponseIF { boolean ok; boolean okIsSet; @Nullable Optional responseMetadata = Optional.empty(); @Nullable Optional error = Optional.empty(); @Nullable List errors = Collections.emptyList(); @JsonProperty public void setOk(boolean ok) { this.ok = ok; this.okIsSet = true; } @JsonProperty("response_metadata") public void setResponseMetadata(Optional responseMetadata) { this.responseMetadata = responseMetadata; } @JsonProperty public void setError(Optional error) { this.error = error; } @JsonProperty public void setErrors(List errors) { this.errors = errors; } @Override public boolean isOk() { throw new UnsupportedOperationException(); } @Override public Optional getResponseMetadata() { throw new UnsupportedOperationException(); } @Override public Optional getError() { throw new UnsupportedOperationException(); } @Override public List getErrors() { 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 SlackErrorResponse fromJson(Json json) { SlackErrorResponse.Builder builder = SlackErrorResponse.builder(); if (json.okIsSet) { builder.setOk(json.ok); } if (json.responseMetadata != null) { builder.setResponseMetadata(json.responseMetadata); } if (json.error != null) { builder.setError(json.error); } if (json.errors != null) { builder.addAllErrors(json.errors); } return builder.build(); } /** * Creates an immutable copy of a {@link SlackErrorResponseIF} 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 SlackErrorResponse instance */ public static SlackErrorResponse copyOf(SlackErrorResponseIF instance) { if (instance instanceof SlackErrorResponse) { return (SlackErrorResponse) instance; } return SlackErrorResponse.builder() .from(instance) .build(); } /** * Creates a builder for {@link SlackErrorResponse SlackErrorResponse}. *

   * SlackErrorResponse.builder()
   *    .setOk(boolean) // required {@link SlackErrorResponseIF#isOk() ok}
   *    .setResponseMetadata(ResponseMetadata) // optional {@link SlackErrorResponseIF#getResponseMetadata() responseMetadata}
   *    .setError(SlackError) // optional {@link SlackErrorResponseIF#getError() error}
   *    .addErrors|addAllErrors(SlackError) // {@link SlackErrorResponseIF#getErrors() errors} elements
   *    .build();
   * 
* @return A new SlackErrorResponse builder */ public static SlackErrorResponse.Builder builder() { return new SlackErrorResponse.Builder(); } /** * Builds instances of type {@link SlackErrorResponse SlackErrorResponse}. * 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 = "SlackErrorResponseIF", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_OK = 0x1L; private long initBits = 0x1L; private boolean ok; private @Nullable ResponseMetadata responseMetadata; private @Nullable SlackError error; private List errors = new ArrayList(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code com.hubspot.slack.client.models.response.SlackErrorResponseIF} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(SlackErrorResponseIF 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.response.SlackResponse} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(SlackResponse 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 SlackErrorResponseIF) { SlackErrorResponseIF instance = (SlackErrorResponseIF) object; if ((bits & 0x1L) == 0) { Optional responseMetadataOptional = instance.getResponseMetadata(); if (responseMetadataOptional.isPresent()) { setResponseMetadata(responseMetadataOptional); } bits |= 0x1L; } Optional errorOptional = instance.getError(); if (errorOptional.isPresent()) { setError(errorOptional); } if ((bits & 0x2L) == 0) { this.setOk(instance.isOk()); bits |= 0x2L; } addAllErrors(instance.getErrors()); } if (object instanceof SlackResponse) { SlackResponse instance = (SlackResponse) object; if ((bits & 0x2L) == 0) { this.setOk(instance.isOk()); bits |= 0x2L; } if ((bits & 0x1L) == 0) { Optional responseMetadataOptional = instance.getResponseMetadata(); if (responseMetadataOptional.isPresent()) { setResponseMetadata(responseMetadataOptional); } bits |= 0x1L; } } } /** * Initializes the value for the {@link SlackErrorResponseIF#isOk() ok} attribute. * @param ok The value for ok * @return {@code this} builder for use in a chained invocation */ public final Builder setOk(boolean ok) { this.ok = ok; initBits &= ~INIT_BIT_OK; return this; } /** * Initializes the optional value {@link SlackErrorResponseIF#getResponseMetadata() responseMetadata} to responseMetadata. * @param responseMetadata The value for responseMetadata, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ public final Builder setResponseMetadata(@Nullable ResponseMetadata responseMetadata) { this.responseMetadata = responseMetadata; return this; } /** * Initializes the optional value {@link SlackErrorResponseIF#getResponseMetadata() responseMetadata} to responseMetadata. * @param responseMetadata The value for responseMetadata * @return {@code this} builder for use in a chained invocation */ public final Builder setResponseMetadata(Optional responseMetadata) { this.responseMetadata = responseMetadata.orElse(null); return this; } /** * Initializes the optional value {@link SlackErrorResponseIF#getError() error} to error. * @param error The value for error, {@code null} is accepted as {@code java.util.Optional.empty()} * @return {@code this} builder for chained invocation */ public final Builder setError(@Nullable SlackError error) { this.error = error; return this; } /** * Initializes the optional value {@link SlackErrorResponseIF#getError() error} to error. * @param error The value for error * @return {@code this} builder for use in a chained invocation */ public final Builder setError(Optional error) { this.error = error.orElse(null); return this; } /** * Adds one element to {@link SlackErrorResponseIF#getErrors() errors} list. * @param element A errors element * @return {@code this} builder for use in a chained invocation */ public final Builder addErrors(SlackError element) { this.errors.add(Objects.requireNonNull(element, "errors element")); return this; } /** * Adds elements to {@link SlackErrorResponseIF#getErrors() errors} list. * @param elements An array of errors elements * @return {@code this} builder for use in a chained invocation */ public final Builder addErrors(SlackError... elements) { for (SlackError element : elements) { this.errors.add(Objects.requireNonNull(element, "errors element")); } return this; } /** * Sets or replaces all elements for {@link SlackErrorResponseIF#getErrors() errors} list. * @param elements An iterable of errors elements * @return {@code this} builder for use in a chained invocation */ public final Builder setErrors(Iterable elements) { this.errors.clear(); return addAllErrors(elements); } /** * Adds elements to {@link SlackErrorResponseIF#getErrors() errors} list. * @param elements An iterable of errors elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllErrors(Iterable elements) { for (SlackError element : elements) { this.errors.add(Objects.requireNonNull(element, "errors element")); } return this; } /** * Builds a new {@link SlackErrorResponse SlackErrorResponse}. * @return An immutable instance of SlackErrorResponse * @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing */ public SlackErrorResponse build() { checkRequiredAttributes(); return new SlackErrorResponse(ok, responseMetadata, error, createUnmodifiableList(true, errors)); } private boolean okIsSet() { return (initBits & INIT_BIT_OK) == 0; } private void checkRequiredAttributes() { if (initBits != 0) { throw new InvalidImmutableStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if (!okIsSet()) attributes.add("ok"); return "Cannot build SlackErrorResponse, some of required attributes are not set " + attributes; } } 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