
com.hubspot.slack.client.models.interaction.ViewResponseAction Maven / Gradle / Ivy
package com.hubspot.slack.client.models.interaction;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.hubspot.immutables.validation.InvalidImmutableStateException;
import com.hubspot.slack.client.models.views.ModalViewPayload;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
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 ViewResponseActionIF}.
*
* Use the builder to create immutable instances:
* {@code ViewResponseAction.builder()}.
*/
@Generated(from = "ViewResponseActionIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class ViewResponseAction
implements ViewResponseActionIF {
private final String responseAction;
private final @Nullable ModalViewPayload view;
private final Map errors;
private ViewResponseAction(
String responseAction,
@Nullable ModalViewPayload view,
Map errors) {
this.responseAction = responseAction;
this.view = view;
this.errors = errors;
}
/**
* @return The value of the {@code responseAction} attribute
*/
@JsonProperty
@Override
public String getResponseAction() {
return responseAction;
}
/**
* @return The value of the {@code view} attribute
*/
@JsonProperty
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Override
public Optional getView() {
return Optional.ofNullable(view);
}
/**
* @return The value of the {@code errors} attribute
*/
@JsonProperty
@JsonInclude(JsonInclude.Include.NON_EMPTY)
@Override
public Map getErrors() {
return errors;
}
/**
* Copy the current immutable object by setting a value for the {@link ViewResponseActionIF#getResponseAction() responseAction} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for responseAction
* @return A modified copy of the {@code this} object
*/
public final ViewResponseAction withResponseAction(String value) {
String newValue = Objects.requireNonNull(value, "responseAction");
if (this.responseAction.equals(newValue)) return this;
return new ViewResponseAction(newValue, this.view, this.errors);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ViewResponseActionIF#getView() view} attribute.
* @param value The value for view, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return A modified copy of {@code this} object
*/
public final ViewResponseAction withView(@Nullable ModalViewPayload value) {
@Nullable ModalViewPayload newValue = value;
if (this.view == newValue) return this;
return new ViewResponseAction(this.responseAction, newValue, this.errors);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ViewResponseActionIF#getView() view} 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 view
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final ViewResponseAction withView(Optional extends ModalViewPayload> optional) {
@Nullable ModalViewPayload value = optional.orElse(null);
if (this.view == value) return this;
return new ViewResponseAction(this.responseAction, value, this.errors);
}
/**
* Copy the current immutable object by replacing the {@link ViewResponseActionIF#getErrors() errors} map with the specified map.
* Nulls are not permitted as keys or values.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param entries The entries to be added to the errors map
* @return A modified copy of {@code this} object
*/
public final ViewResponseAction withErrors(Map entries) {
if (this.errors == entries) return this;
Map newValue = createUnmodifiableMap(true, false, entries);
return new ViewResponseAction(this.responseAction, this.view, newValue);
}
/**
* This instance is equal to all instances of {@code ViewResponseAction} 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 ViewResponseAction
&& equalTo(0, (ViewResponseAction) another);
}
private boolean equalTo(int synthetic, ViewResponseAction another) {
return responseAction.equals(another.responseAction)
&& Objects.equals(view, another.view)
&& errors.equals(another.errors);
}
/**
* Computes a hash code from attributes: {@code responseAction}, {@code view}, {@code errors}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + responseAction.hashCode();
h += (h << 5) + Objects.hashCode(view);
h += (h << 5) + errors.hashCode();
return h;
}
/**
* Prints the immutable value {@code ViewResponseAction} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("ViewResponseAction{");
builder.append("responseAction=").append(responseAction);
if (view != null) {
builder.append(", ");
builder.append("view=").append(view);
}
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 = "ViewResponseActionIF", generator = "Immutables")
@Deprecated
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements ViewResponseActionIF {
@Nullable String responseAction;
@Nullable Optional view = Optional.empty();
@Nullable Map errors = Collections.emptyMap();
@JsonProperty
public void setResponseAction(String responseAction) {
this.responseAction = responseAction;
}
@JsonProperty
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public void setView(Optional view) {
this.view = view;
}
@JsonProperty
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public void setErrors(Map errors) {
this.errors = errors;
}
@Override
public String getResponseAction() { throw new UnsupportedOperationException(); }
@Override
public Optional getView() { throw new UnsupportedOperationException(); }
@Override
public Map 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 ViewResponseAction fromJson(Json json) {
ViewResponseAction.Builder builder = ViewResponseAction.builder();
if (json.responseAction != null) {
builder.setResponseAction(json.responseAction);
}
if (json.view != null) {
builder.setView(json.view);
}
if (json.errors != null) {
builder.putAllErrors(json.errors);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link ViewResponseActionIF} 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 ViewResponseAction instance
*/
public static ViewResponseAction copyOf(ViewResponseActionIF instance) {
if (instance instanceof ViewResponseAction) {
return (ViewResponseAction) instance;
}
return ViewResponseAction.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ViewResponseAction ViewResponseAction}.
*
* ViewResponseAction.builder()
* .setResponseAction(String) // required {@link ViewResponseActionIF#getResponseAction() responseAction}
* .setView(com.hubspot.slack.client.models.views.ModalViewPayload) // optional {@link ViewResponseActionIF#getView() view}
* .putErrors|putAllErrors(String => String) // {@link ViewResponseActionIF#getErrors() errors} mappings
* .build();
*
* @return A new ViewResponseAction builder
*/
public static ViewResponseAction.Builder builder() {
return new ViewResponseAction.Builder();
}
/**
* Builds instances of type {@link ViewResponseAction ViewResponseAction}.
* 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 = "ViewResponseActionIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_RESPONSE_ACTION = 0x1L;
private long initBits = 0x1L;
private @Nullable String responseAction;
private @Nullable ModalViewPayload view;
private Map errors = new LinkedHashMap();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ViewResponseActionIF} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(ViewResponseActionIF instance) {
Objects.requireNonNull(instance, "instance");
this.setResponseAction(instance.getResponseAction());
Optional viewOptional = instance.getView();
if (viewOptional.isPresent()) {
setView(viewOptional);
}
putAllErrors(instance.getErrors());
return this;
}
/**
* Initializes the value for the {@link ViewResponseActionIF#getResponseAction() responseAction} attribute.
* @param responseAction The value for responseAction
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setResponseAction(String responseAction) {
this.responseAction = Objects.requireNonNull(responseAction, "responseAction");
initBits &= ~INIT_BIT_RESPONSE_ACTION;
return this;
}
/**
* Initializes the optional value {@link ViewResponseActionIF#getView() view} to view.
* @param view The value for view, {@code null} is accepted as {@code java.util.Optional.empty()}
* @return {@code this} builder for chained invocation
*/
public final Builder setView(@Nullable ModalViewPayload view) {
this.view = view;
return this;
}
/**
* Initializes the optional value {@link ViewResponseActionIF#getView() view} to view.
* @param view The value for view
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setView(Optional extends ModalViewPayload> view) {
this.view = view.orElse(null);
return this;
}
/**
* Put one entry to the {@link ViewResponseActionIF#getErrors() errors} map.
* @param key The key in the errors map
* @param value The associated value in the errors map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putErrors(String key, String value) {
this.errors.put(
Objects.requireNonNull(key, "errors key"),
Objects.requireNonNull(value, value == null ? "errors value for key: " + key : null));
return this;
}
/**
* Put one entry to the {@link ViewResponseActionIF#getErrors() errors} map. Nulls are not permitted
* @param entry The key and value entry
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putErrors(Map.Entry entry) {
String k = entry.getKey();
String v = entry.getValue();
this.errors.put(
Objects.requireNonNull(k, "errors key"),
Objects.requireNonNull(v, v == null ? "errors value for key: " + k : null));
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link ViewResponseActionIF#getErrors() errors} map. Nulls are not permitted
* @param entries The entries that will be added to the errors map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setErrors(Map entries) {
this.errors.clear();
return putAllErrors(entries);
}
/**
* Put all mappings from the specified map as entries to {@link ViewResponseActionIF#getErrors() errors} map. Nulls are not permitted
* @param entries The entries that will be added to the errors map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putAllErrors(Map entries) {
for (Map.Entry e : entries.entrySet()) {
String k = e.getKey();
String v = e.getValue();
this.errors.put(
Objects.requireNonNull(k, "errors key"),
Objects.requireNonNull(v, v == null ? "errors value for key: " + k : null));
}
return this;
}
/**
* Builds a new {@link ViewResponseAction ViewResponseAction}.
* @return An immutable instance of ViewResponseAction
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public ViewResponseAction build() {
checkRequiredAttributes();
return new ViewResponseAction(responseAction, view, createUnmodifiableMap(false, false, errors));
}
private boolean responseActionIsSet() {
return (initBits & INIT_BIT_RESPONSE_ACTION) == 0;
}
private void checkRequiredAttributes() {
if (initBits != 0) {
throw new InvalidImmutableStateException(formatRequiredAttributesMessage());
}
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if (!responseActionIsSet()) attributes.add("responseAction");
return "Cannot build ViewResponseAction, some of required attributes are not set " + attributes;
}
}
private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, Map extends K, ? extends V> map) {
switch (map.size()) {
case 0: return Collections.emptyMap();
case 1: {
Map.Entry extends K, ? extends V> e = map.entrySet().iterator().next();
K k = e.getKey();
V v = e.getValue();
if (checkNulls) {
Objects.requireNonNull(k, "key");
Objects.requireNonNull(v, v == null ? "value for key: " + k : null);
}
if (skipNulls && (k == null || v == null)) {
return Collections.emptyMap();
}
return Collections.singletonMap(k, v);
}
default: {
Map linkedMap = new LinkedHashMap<>(map.size() * 4 / 3 + 1);
if (skipNulls || checkNulls) {
for (Map.Entry extends K, ? extends V> e : map.entrySet()) {
K k = e.getKey();
V v = e.getValue();
if (skipNulls) {
if (k == null || v == null) continue;
} else if (checkNulls) {
Objects.requireNonNull(k, "key");
Objects.requireNonNull(v, v == null ? "value for key: " + k : null);
}
linkedMap.put(k, v);
}
} else {
linkedMap.putAll(map);
}
return Collections.unmodifiableMap(linkedMap);
}
}
}
}