
com.hubspot.slack.client.models.interaction.StateValuesPayload 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.JsonProperty;
import com.hubspot.slack.client.models.interaction.views.ViewInput;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
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 StateValuesPayloadIF}.
*
* Use the builder to create immutable instances:
* {@code StateValuesPayload.builder()}.
*/
@Generated(from = "StateValuesPayloadIF", generator = "Immutables")
@SuppressWarnings({"all"})
@SuppressFBWarnings
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class StateValuesPayload
implements StateValuesPayloadIF {
private final Map> blockIdToActionIdToValues;
private StateValuesPayload(
Map> blockIdToActionIdToValues) {
this.blockIdToActionIdToValues = blockIdToActionIdToValues;
}
/**
* @return The value of the {@code blockIdToActionIdToValues} attribute
*/
@JsonProperty("values")
@Override
public Map> getBlockIdToActionIdToValues() {
return blockIdToActionIdToValues;
}
/**
* Copy the current immutable object by replacing the {@link StateValuesPayloadIF#getBlockIdToActionIdToValues() blockIdToActionIdToValues} 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 blockIdToActionIdToValues map
* @return A modified copy of {@code this} object
*/
public final StateValuesPayload withBlockIdToActionIdToValues(Map> entries) {
if (this.blockIdToActionIdToValues == entries) return this;
Map> newValue = createUnmodifiableMap(true, false, entries);
return new StateValuesPayload(newValue);
}
/**
* This instance is equal to all instances of {@code StateValuesPayload} 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 StateValuesPayload
&& equalTo(0, (StateValuesPayload) another);
}
private boolean equalTo(int synthetic, StateValuesPayload another) {
return blockIdToActionIdToValues.equals(another.blockIdToActionIdToValues);
}
/**
* Computes a hash code from attributes: {@code blockIdToActionIdToValues}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + blockIdToActionIdToValues.hashCode();
return h;
}
/**
* Prints the immutable value {@code StateValuesPayload} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "StateValuesPayload{"
+ "blockIdToActionIdToValues=" + blockIdToActionIdToValues
+ "}";
}
/**
* 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 = "StateValuesPayloadIF", generator = "Immutables")
@Deprecated
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements StateValuesPayloadIF {
@Nullable Map> blockIdToActionIdToValues = Collections.emptyMap();
@JsonProperty("values")
public void setBlockIdToActionIdToValues(Map> blockIdToActionIdToValues) {
this.blockIdToActionIdToValues = blockIdToActionIdToValues;
}
@Override
public Map> getBlockIdToActionIdToValues() { 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 StateValuesPayload fromJson(Json json) {
StateValuesPayload.Builder builder = StateValuesPayload.builder();
if (json.blockIdToActionIdToValues != null) {
builder.putAllBlockIdToActionIdToValues(json.blockIdToActionIdToValues);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link StateValuesPayloadIF} 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 StateValuesPayload instance
*/
public static StateValuesPayload copyOf(StateValuesPayloadIF instance) {
if (instance instanceof StateValuesPayload) {
return (StateValuesPayload) instance;
}
return StateValuesPayload.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link StateValuesPayload StateValuesPayload}.
*
* StateValuesPayload.builder()
* .putBlockIdToActionIdToValues|putAllBlockIdToActionIdToValues(String => Map<String, com.hubspot.slack.client.models.interaction.views.ViewInput>) // {@link StateValuesPayloadIF#getBlockIdToActionIdToValues() blockIdToActionIdToValues} mappings
* .build();
*
* @return A new StateValuesPayload builder
*/
public static StateValuesPayload.Builder builder() {
return new StateValuesPayload.Builder();
}
/**
* Builds instances of type {@link StateValuesPayload StateValuesPayload}.
* 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 = "StateValuesPayloadIF", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private Map> blockIdToActionIdToValues = new LinkedHashMap>();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code StateValuesPayloadIF} 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(StateValuesPayloadIF instance) {
Objects.requireNonNull(instance, "instance");
putAllBlockIdToActionIdToValues(instance.getBlockIdToActionIdToValues());
return this;
}
/**
* Put one entry to the {@link StateValuesPayloadIF#getBlockIdToActionIdToValues() blockIdToActionIdToValues} map.
* @param key The key in the blockIdToActionIdToValues map
* @param value The associated value in the blockIdToActionIdToValues map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putBlockIdToActionIdToValues(String key, Map value) {
this.blockIdToActionIdToValues.put(
Objects.requireNonNull(key, "blockIdToActionIdToValues key"),
Objects.requireNonNull(value, value == null ? "blockIdToActionIdToValues value for key: " + key : null));
return this;
}
/**
* Put one entry to the {@link StateValuesPayloadIF#getBlockIdToActionIdToValues() blockIdToActionIdToValues} 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 putBlockIdToActionIdToValues(Map.Entry> entry) {
String k = entry.getKey();
Map v = entry.getValue();
this.blockIdToActionIdToValues.put(
Objects.requireNonNull(k, "blockIdToActionIdToValues key"),
Objects.requireNonNull(v, v == null ? "blockIdToActionIdToValues value for key: " + k : null));
return this;
}
/**
* Sets or replaces all mappings from the specified map as entries for the {@link StateValuesPayloadIF#getBlockIdToActionIdToValues() blockIdToActionIdToValues} map. Nulls are not permitted
* @param entries The entries that will be added to the blockIdToActionIdToValues map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder setBlockIdToActionIdToValues(Map> entries) {
this.blockIdToActionIdToValues.clear();
return putAllBlockIdToActionIdToValues(entries);
}
/**
* Put all mappings from the specified map as entries to {@link StateValuesPayloadIF#getBlockIdToActionIdToValues() blockIdToActionIdToValues} map. Nulls are not permitted
* @param entries The entries that will be added to the blockIdToActionIdToValues map
* @return {@code this} builder for use in a chained invocation
*/
public final Builder putAllBlockIdToActionIdToValues(Map> entries) {
for (Map.Entry> e : entries.entrySet()) {
String k = e.getKey();
Map v = e.getValue();
this.blockIdToActionIdToValues.put(
Objects.requireNonNull(k, "blockIdToActionIdToValues key"),
Objects.requireNonNull(v, v == null ? "blockIdToActionIdToValues value for key: " + k : null));
}
return this;
}
/**
* Builds a new {@link StateValuesPayload StateValuesPayload}.
* @return An immutable instance of StateValuesPayload
* @throws com.hubspot.immutables.validation.InvalidImmutableStateException if any required attributes are missing
*/
public StateValuesPayload build() {
return new StateValuesPayload(createUnmodifiableMap(false, false, blockIdToActionIdToValues));
}
}
private static Map createUnmodifiableMap(boolean checkNulls, boolean skipNulls, Map map) {
switch (map.size()) {
case 0: return Collections.emptyMap();
case 1: {
Map.Entry 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 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);
}
}
}
}