
org.cloudfoundry.multiapps.controller.api.model.ImmutableAsyncUploadResult Maven / Gradle / Ivy
package org.cloudfoundry.multiapps.controller.api.model;
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.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.cloudfoundry.multiapps.common.Nullable;
/**
* Immutable implementation of {@link AsyncUploadResult}.
*
* Use the builder to create immutable instances:
* {@code ImmutableAsyncUploadResult.builder()}.
*/
@SuppressWarnings({"all"})
public final class ImmutableAsyncUploadResult
implements AsyncUploadResult {
private final AsyncUploadResult.JobStatus status;
private final @Nullable Long bytes;
private final @Nullable String error;
private final @Nullable FileMetadata file;
private final @Nullable String mtaId;
private final @Nullable List clientActions;
private ImmutableAsyncUploadResult(
AsyncUploadResult.JobStatus status,
@Nullable Long bytes,
@Nullable String error,
@Nullable FileMetadata file,
@Nullable String mtaId,
@Nullable List clientActions) {
this.status = status;
this.bytes = bytes;
this.error = error;
this.file = file;
this.mtaId = mtaId;
this.clientActions = clientActions;
}
/**
* @return The value of the {@code status} attribute
*/
@JsonProperty("status")
@Override
public AsyncUploadResult.JobStatus getStatus() {
return status;
}
/**
* @return The value of the {@code bytes} attribute
*/
@JsonProperty("bytes_processed")
@Override
public @Nullable Long getBytes() {
return bytes;
}
/**
* @return The value of the {@code error} attribute
*/
@JsonProperty("error")
@Override
public @Nullable String getError() {
return error;
}
/**
* @return The value of the {@code file} attribute
*/
@JsonProperty("file")
@Override
public @Nullable FileMetadata getFile() {
return file;
}
/**
* @return The value of the {@code mtaId} attribute
*/
@JsonProperty("mta_id")
@Override
public @Nullable String getMtaId() {
return mtaId;
}
/**
* @return The value of the {@code clientActions} attribute
*/
@JsonProperty("client_actions")
@Override
public @Nullable List getClientActions() {
return clientActions;
}
/**
* Copy the current immutable object by setting a value for the {@link AsyncUploadResult#getStatus() status} attribute.
* A value equality check is 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 ImmutableAsyncUploadResult withStatus(AsyncUploadResult.JobStatus value) {
AsyncUploadResult.JobStatus newValue = Objects.requireNonNull(value, "status");
if (this.status == newValue) return this;
return new ImmutableAsyncUploadResult(newValue, this.bytes, this.error, this.file, this.mtaId, this.clientActions);
}
/**
* Copy the current immutable object by setting a value for the {@link AsyncUploadResult#getBytes() bytes} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for bytes (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableAsyncUploadResult withBytes(@Nullable Long value) {
if (Objects.equals(this.bytes, value)) return this;
return new ImmutableAsyncUploadResult(this.status, value, this.error, this.file, this.mtaId, this.clientActions);
}
/**
* Copy the current immutable object by setting a value for the {@link AsyncUploadResult#getError() error} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for error (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableAsyncUploadResult withError(@Nullable String value) {
if (Objects.equals(this.error, value)) return this;
return new ImmutableAsyncUploadResult(this.status, this.bytes, value, this.file, this.mtaId, this.clientActions);
}
/**
* Copy the current immutable object by setting a value for the {@link AsyncUploadResult#getFile() file} 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 file (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableAsyncUploadResult withFile(@Nullable FileMetadata value) {
if (this.file == value) return this;
return new ImmutableAsyncUploadResult(this.status, this.bytes, this.error, value, this.mtaId, this.clientActions);
}
/**
* Copy the current immutable object by setting a value for the {@link AsyncUploadResult#getMtaId() mtaId} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for mtaId (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableAsyncUploadResult withMtaId(@Nullable String value) {
if (Objects.equals(this.mtaId, value)) return this;
return new ImmutableAsyncUploadResult(this.status, this.bytes, this.error, this.file, value, this.clientActions);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AsyncUploadResult#getClientActions() clientActions}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableAsyncUploadResult withClientActions(@Nullable AsyncUploadResult.ClientAction... elements) {
if (elements == null) {
return new ImmutableAsyncUploadResult(this.status, this.bytes, this.error, this.file, this.mtaId, null);
}
@Nullable List newValue = Arrays.asList(elements) == null ? null : createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new ImmutableAsyncUploadResult(this.status, this.bytes, this.error, this.file, this.mtaId, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AsyncUploadResult#getClientActions() clientActions}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of clientActions elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableAsyncUploadResult withClientActions(@Nullable Iterable extends AsyncUploadResult.ClientAction> elements) {
if (this.clientActions == elements) return this;
@Nullable List newValue = elements == null ? null : createUnmodifiableList(false, createSafeList(elements, true, false));
return new ImmutableAsyncUploadResult(this.status, this.bytes, this.error, this.file, this.mtaId, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableAsyncUploadResult} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(Object another) {
if (this == another) return true;
return another instanceof ImmutableAsyncUploadResult
&& equalTo(0, (ImmutableAsyncUploadResult) another);
}
private boolean equalTo(int synthetic, ImmutableAsyncUploadResult another) {
return status.equals(another.status)
&& Objects.equals(bytes, another.bytes)
&& Objects.equals(error, another.error)
&& Objects.equals(file, another.file)
&& Objects.equals(mtaId, another.mtaId)
&& Objects.equals(clientActions, another.clientActions);
}
/**
* Computes a hash code from attributes: {@code status}, {@code bytes}, {@code error}, {@code file}, {@code mtaId}, {@code clientActions}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + status.hashCode();
h += (h << 5) + Objects.hashCode(bytes);
h += (h << 5) + Objects.hashCode(error);
h += (h << 5) + Objects.hashCode(file);
h += (h << 5) + Objects.hashCode(mtaId);
h += (h << 5) + Objects.hashCode(clientActions);
return h;
}
/**
* Prints the immutable value {@code AsyncUploadResult} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "AsyncUploadResult{"
+ "status=" + status
+ ", bytes=" + bytes
+ ", error=" + error
+ ", file=" + file
+ ", mtaId=" + mtaId
+ ", clientActions=" + clientActions
+ "}";
}
/**
* 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 implements AsyncUploadResult {
AsyncUploadResult.JobStatus status;
Long bytes;
String error;
FileMetadata file;
String mtaId;
List clientActions = null;
@JsonProperty("status")
public void setStatus(AsyncUploadResult.JobStatus status) {
this.status = status;
}
@JsonProperty("bytes_processed")
public void setBytes(@Nullable Long bytes) {
this.bytes = bytes;
}
@JsonProperty("error")
public void setError(@Nullable String error) {
this.error = error;
}
@JsonProperty("file")
public void setFile(@Nullable FileMetadata file) {
this.file = file;
}
@JsonProperty("mta_id")
public void setMtaId(@Nullable String mtaId) {
this.mtaId = mtaId;
}
@JsonProperty("client_actions")
public void setClientActions(@Nullable List clientActions) {
this.clientActions = clientActions;
}
@Override
public AsyncUploadResult.JobStatus getStatus() { throw new UnsupportedOperationException(); }
@Override
public Long getBytes() { throw new UnsupportedOperationException(); }
@Override
public String getError() { throw new UnsupportedOperationException(); }
@Override
public FileMetadata getFile() { throw new UnsupportedOperationException(); }
@Override
public String getMtaId() { throw new UnsupportedOperationException(); }
@Override
public List getClientActions() { 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 ImmutableAsyncUploadResult fromJson(Json json) {
ImmutableAsyncUploadResult.Builder builder = ImmutableAsyncUploadResult.builder();
if (json.status != null) {
builder.status(json.status);
}
if (json.bytes != null) {
builder.bytes(json.bytes);
}
if (json.error != null) {
builder.error(json.error);
}
if (json.file != null) {
builder.file(json.file);
}
if (json.mtaId != null) {
builder.mtaId(json.mtaId);
}
if (json.clientActions != null) {
builder.addAllClientActions(json.clientActions);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link AsyncUploadResult} 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 AsyncUploadResult instance
*/
public static ImmutableAsyncUploadResult copyOf(AsyncUploadResult instance) {
if (instance instanceof ImmutableAsyncUploadResult) {
return (ImmutableAsyncUploadResult) instance;
}
return ImmutableAsyncUploadResult.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableAsyncUploadResult ImmutableAsyncUploadResult}.
*
* ImmutableAsyncUploadResult.builder()
* .status(org.cloudfoundry.multiapps.controller.api.model.AsyncUploadResult.JobStatus) // required {@link AsyncUploadResult#getStatus() status}
* .bytes(Long | null) // nullable {@link AsyncUploadResult#getBytes() bytes}
* .error(String | null) // nullable {@link AsyncUploadResult#getError() error}
* .file(org.cloudfoundry.multiapps.controller.api.model.FileMetadata | null) // nullable {@link AsyncUploadResult#getFile() file}
* .mtaId(String | null) // nullable {@link AsyncUploadResult#getMtaId() mtaId}
* .clientActions(List<org.cloudfoundry.multiapps.controller.api.model.AsyncUploadResult.ClientAction> | null) // nullable {@link AsyncUploadResult#getClientActions() clientActions}
* .build();
*
* @return A new ImmutableAsyncUploadResult builder
*/
public static ImmutableAsyncUploadResult.Builder builder() {
return new ImmutableAsyncUploadResult.Builder();
}
/**
* Builds instances of type {@link ImmutableAsyncUploadResult ImmutableAsyncUploadResult}.
* 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.
*/
public static final class Builder {
private static final long INIT_BIT_STATUS = 0x1L;
private long initBits = 0x1L;
private AsyncUploadResult.JobStatus status;
private Long bytes;
private String error;
private FileMetadata file;
private String mtaId;
private List clientActions = null;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code AsyncUploadResult} 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(AsyncUploadResult instance) {
Objects.requireNonNull(instance, "instance");
this.status(instance.getStatus());
@Nullable Long bytesValue = instance.getBytes();
if (bytesValue != null) {
bytes(bytesValue);
}
@Nullable String errorValue = instance.getError();
if (errorValue != null) {
error(errorValue);
}
@Nullable FileMetadata fileValue = instance.getFile();
if (fileValue != null) {
file(fileValue);
}
@Nullable String mtaIdValue = instance.getMtaId();
if (mtaIdValue != null) {
mtaId(mtaIdValue);
}
@Nullable List clientActionsValue = instance.getClientActions();
if (clientActionsValue != null) {
addAllClientActions(clientActionsValue);
}
return this;
}
/**
* Initializes the value for the {@link AsyncUploadResult#getStatus() status} attribute.
* @param status The value for status
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("status")
public final Builder status(AsyncUploadResult.JobStatus status) {
this.status = Objects.requireNonNull(status, "status");
initBits &= ~INIT_BIT_STATUS;
return this;
}
/**
* Initializes the value for the {@link AsyncUploadResult#getBytes() bytes} attribute.
* @param bytes The value for bytes (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("bytes_processed")
public final Builder bytes(@Nullable Long bytes) {
this.bytes = bytes;
return this;
}
/**
* Initializes the value for the {@link AsyncUploadResult#getError() error} attribute.
* @param error The value for error (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("error")
public final Builder error(@Nullable String error) {
this.error = error;
return this;
}
/**
* Initializes the value for the {@link AsyncUploadResult#getFile() file} attribute.
* @param file The value for file (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("file")
public final Builder file(@Nullable FileMetadata file) {
this.file = file;
return this;
}
/**
* Initializes the value for the {@link AsyncUploadResult#getMtaId() mtaId} attribute.
* @param mtaId The value for mtaId (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("mta_id")
public final Builder mtaId(@Nullable String mtaId) {
this.mtaId = mtaId;
return this;
}
/**
* Adds one element to {@link AsyncUploadResult#getClientActions() clientActions} list.
* @param element A clientActions element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addClientAction(AsyncUploadResult.ClientAction element) {
if (this.clientActions == null) {
this.clientActions = new ArrayList();
}
this.clientActions.add(Objects.requireNonNull(element, "clientActions element"));
return this;
}
/**
* Adds elements to {@link AsyncUploadResult#getClientActions() clientActions} list.
* @param elements An array of clientActions elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addClientActions(AsyncUploadResult.ClientAction... elements) {
if (this.clientActions == null) {
this.clientActions = new ArrayList();
}
for (AsyncUploadResult.ClientAction element : elements) {
this.clientActions.add(Objects.requireNonNull(element, "clientActions element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link AsyncUploadResult#getClientActions() clientActions} list.
* @param elements An iterable of clientActions elements
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("client_actions")
public final Builder clientActions(@Nullable Iterable extends AsyncUploadResult.ClientAction> elements) {
if (elements == null) {
this.clientActions = null;
return this;
}
this.clientActions = new ArrayList();
return addAllClientActions(elements);
}
/**
* Adds elements to {@link AsyncUploadResult#getClientActions() clientActions} list.
* @param elements An iterable of clientActions elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllClientActions(Iterable extends AsyncUploadResult.ClientAction> elements) {
Objects.requireNonNull(elements, "clientActions element");
if (this.clientActions == null) {
this.clientActions = new ArrayList();
}
for (AsyncUploadResult.ClientAction element : elements) {
this.clientActions.add(Objects.requireNonNull(element, "clientActions element"));
}
return this;
}
/**
* Builds a new {@link ImmutableAsyncUploadResult ImmutableAsyncUploadResult}.
* @return An immutable instance of AsyncUploadResult
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableAsyncUploadResult build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableAsyncUploadResult(
status,
bytes,
error,
file,
mtaId,
clientActions == null ? null : createUnmodifiableList(true, clientActions));
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_STATUS) != 0) attributes.add("status");
return "Cannot build AsyncUploadResult, some of required attributes are not set " + attributes;
}
}
private static List createSafeList(Iterable extends T> 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);
}
}
}
}