com.myperfit.sdk.transactional.domain.responses.PemError Maven / Gradle / Ivy
Show all versions of transactionalsdk Show documentation
package com.myperfit.sdk.transactional.domain.responses;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.ArrayList;
import java.util.List;
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;
/**
* Immutable implementation of {@link AbstractPemError}.
*
* Use the builder to create immutable instances:
* {@code PemError.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Immutable
public final class PemError extends AbstractPemError {
private final Integer status;
private final String type;
private final String message;
private final String moreInfo;
private final Map errors;
private PemError(
Integer status,
String type,
String message,
String moreInfo,
Map errors) {
this.status = status;
this.type = type;
this.message = message;
this.moreInfo = moreInfo;
this.errors = errors;
}
/**
* @return The value of the {@code status} attribute
*/
@JsonProperty("status")
@Override
public Integer status() {
return status;
}
/**
* @return The value of the {@code type} attribute
*/
@JsonProperty("type")
@Override
public String type() {
return type;
}
/**
* @return The value of the {@code message} attribute
*/
@JsonProperty("message")
@Override
public String message() {
return message;
}
/**
* @return The value of the {@code moreInfo} attribute
*/
@JsonProperty("moreInfo")
@Override
public String moreInfo() {
return moreInfo;
}
/**
* @return The value of the {@code errors} attribute
*/
@JsonProperty("errors")
@Override
public Map errors() {
return errors;
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractPemError#status() status} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for status
* @return A modified copy of the {@code this} object
*/
public final PemError withStatus(Integer value) {
if (this.status.equals(value)) return this;
Integer newValue = Objects.requireNonNull(value, "status");
return new PemError(newValue, this.type, this.message, this.moreInfo, this.errors);
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractPemError#type() type} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for type
* @return A modified copy of the {@code this} object
*/
public final PemError withType(String value) {
if (this.type.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "type");
return new PemError(this.status, newValue, this.message, this.moreInfo, this.errors);
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractPemError#message() message} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for message
* @return A modified copy of the {@code this} object
*/
public final PemError withMessage(String value) {
if (this.message.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "message");
return new PemError(this.status, this.type, newValue, this.moreInfo, this.errors);
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractPemError#moreInfo() moreInfo} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for moreInfo
* @return A modified copy of the {@code this} object
*/
public final PemError withMoreInfo(String value) {
if (this.moreInfo.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "moreInfo");
return new PemError(this.status, this.type, this.message, newValue, this.errors);
}
/**
* Copy the current immutable object by setting a value for the {@link AbstractPemError#errors() errors} attribute.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for errors
* @return A modified copy of the {@code this} object
*/
public final PemError withErrors(Map value) {
if (this.errors == value) return this;
Map newValue = Objects.requireNonNull(value, "errors");
return new PemError(this.status, this.type, this.message, this.moreInfo, newValue);
}
/**
* This instance is equal to all instances of {@code PemError} 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 PemError
&& equalTo((PemError) another);
}
private boolean equalTo(PemError another) {
return status.equals(another.status)
&& type.equals(another.type)
&& message.equals(another.message)
&& moreInfo.equals(another.moreInfo)
&& errors.equals(another.errors);
}
/**
* Computes a hash code from attributes: {@code status}, {@code type}, {@code message}, {@code moreInfo}, {@code errors}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + status.hashCode();
h += (h << 5) + type.hashCode();
h += (h << 5) + message.hashCode();
h += (h << 5) + moreInfo.hashCode();
h += (h << 5) + errors.hashCode();
return h;
}
/**
* Prints the immutable value {@code PemError} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "PemError{"
+ "status=" + status
+ ", type=" + type
+ ", message=" + message
+ ", moreInfo=" + moreInfo
+ ", errors=" + errors
+ "}";
}
/**
* 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
*/
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json extends AbstractPemError {
@Nullable Integer status;
@Nullable String type;
@Nullable String message;
@Nullable String moreInfo;
@Nullable Map errors;
@JsonProperty("status")
public void setStatus(Integer status) {
this.status = status;
}
@JsonProperty("type")
public void setType(String type) {
this.type = type;
}
@JsonProperty("message")
public void setMessage(String message) {
this.message = message;
}
@JsonProperty("moreInfo")
public void setMoreInfo(String moreInfo) {
this.moreInfo = moreInfo;
}
@JsonProperty("errors")
public void setErrors(Map errors) {
this.errors = errors;
}
@Override
public Integer status() { throw new UnsupportedOperationException(); }
@Override
public String type() { throw new UnsupportedOperationException(); }
@Override
public String message() { throw new UnsupportedOperationException(); }
@Override
public String moreInfo() { throw new UnsupportedOperationException(); }
@Override
public Map errors() { 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 PemError fromJson(Json json) {
PemError.Builder builder = PemError.builder();
if (json.status != null) {
builder.status(json.status);
}
if (json.type != null) {
builder.type(json.type);
}
if (json.message != null) {
builder.message(json.message);
}
if (json.moreInfo != null) {
builder.moreInfo(json.moreInfo);
}
if (json.errors != null) {
builder.errors(json.errors);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link AbstractPemError} 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 PemError instance
*/
public static PemError copyOf(AbstractPemError instance) {
if (instance instanceof PemError) {
return (PemError) instance;
}
return PemError.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link PemError PemError}.
* @return A new PemError builder
*/
public static PemError.Builder builder() {
return new PemError.Builder();
}
/**
* Builds instances of type {@link PemError PemError}.
* 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.
*/
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_STATUS = 0x1L;
private static final long INIT_BIT_TYPE = 0x2L;
private static final long INIT_BIT_MESSAGE = 0x4L;
private static final long INIT_BIT_MORE_INFO = 0x8L;
private static final long INIT_BIT_ERRORS = 0x10L;
private long initBits = 0x1fL;
private @Nullable Integer status;
private @Nullable String type;
private @Nullable String message;
private @Nullable String moreInfo;
private @Nullable Map errors;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code AbstractPemError} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(AbstractPemError instance) {
Objects.requireNonNull(instance, "instance");
status(instance.status());
type(instance.type());
message(instance.message());
moreInfo(instance.moreInfo());
errors(instance.errors());
return this;
}
/**
* Initializes the value for the {@link AbstractPemError#status() status} attribute.
* @param status The value for status
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("status")
public final Builder status(Integer status) {
this.status = Objects.requireNonNull(status, "status");
initBits &= ~INIT_BIT_STATUS;
return this;
}
/**
* Initializes the value for the {@link AbstractPemError#type() type} attribute.
* @param type The value for type
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("type")
public final Builder type(String type) {
this.type = Objects.requireNonNull(type, "type");
initBits &= ~INIT_BIT_TYPE;
return this;
}
/**
* Initializes the value for the {@link AbstractPemError#message() message} attribute.
* @param message The value for message
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("message")
public final Builder message(String message) {
this.message = Objects.requireNonNull(message, "message");
initBits &= ~INIT_BIT_MESSAGE;
return this;
}
/**
* Initializes the value for the {@link AbstractPemError#moreInfo() moreInfo} attribute.
* @param moreInfo The value for moreInfo
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("moreInfo")
public final Builder moreInfo(String moreInfo) {
this.moreInfo = Objects.requireNonNull(moreInfo, "moreInfo");
initBits &= ~INIT_BIT_MORE_INFO;
return this;
}
/**
* Initializes the value for the {@link AbstractPemError#errors() errors} attribute.
* @param errors The value for errors
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("errors")
public final Builder errors(Map errors) {
this.errors = Objects.requireNonNull(errors, "errors");
initBits &= ~INIT_BIT_ERRORS;
return this;
}
/**
* Builds a new {@link PemError PemError}.
* @return An immutable instance of PemError
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public PemError build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new PemError(status, type, message, moreInfo, errors);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_STATUS) != 0) attributes.add("status");
if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type");
if ((initBits & INIT_BIT_MESSAGE) != 0) attributes.add("message");
if ((initBits & INIT_BIT_MORE_INFO) != 0) attributes.add("moreInfo");
if ((initBits & INIT_BIT_ERRORS) != 0) attributes.add("errors");
return "Cannot build PemError, some of required attributes are not set " + attributes;
}
}
}