io.resys.thena.docdb.api.actions.ImmutableObjectsResult Maven / Gradle / Ivy
package io.resys.thena.docdb.api.actions;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import io.resys.thena.docdb.api.models.Message;
import io.resys.thena.docdb.api.models.Repo;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
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 ObjectsActions.ObjectsResult}.
*
* Use the builder to create immutable instances:
* {@code ImmutableObjectsResult.builder()}.
*/
@Generated(from = "ObjectsActions.ObjectsResult", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableObjectsResult
implements ObjectsActions.ObjectsResult {
private final @Nullable Repo repo;
private final @Nullable T objects;
private final ObjectsActions.ObjectsStatus status;
private final ImmutableList messages;
private ImmutableObjectsResult(
@Nullable Repo repo,
@Nullable T objects,
ObjectsActions.ObjectsStatus status,
ImmutableList messages) {
this.repo = repo;
this.objects = objects;
this.status = status;
this.messages = messages;
}
/**
* @return The value of the {@code repo} attribute
*/
@Override
public @Nullable Repo getRepo() {
return repo;
}
/**
* @return The value of the {@code objects} attribute
*/
@Override
public @Nullable T getObjects() {
return objects;
}
/**
* @return The value of the {@code status} attribute
*/
@Override
public ObjectsActions.ObjectsStatus getStatus() {
return status;
}
/**
* @return The value of the {@code messages} attribute
*/
@Override
public ImmutableList getMessages() {
return messages;
}
/**
* Copy the current immutable object by setting a value for the {@link ObjectsActions.ObjectsResult#getRepo() repo} 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 repo (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableObjectsResult withRepo(@Nullable Repo value) {
if (this.repo == value) return this;
return new ImmutableObjectsResult<>(value, this.objects, this.status, this.messages);
}
/**
* Copy the current immutable object by setting a value for the {@link ObjectsActions.ObjectsResult#getObjects() objects} 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 objects (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableObjectsResult withObjects(@Nullable T value) {
if (this.objects == value) return this;
return new ImmutableObjectsResult<>(this.repo, value, this.status, this.messages);
}
/**
* Copy the current immutable object by setting a value for the {@link ObjectsActions.ObjectsResult#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 ImmutableObjectsResult withStatus(ObjectsActions.ObjectsStatus value) {
ObjectsActions.ObjectsStatus newValue = Objects.requireNonNull(value, "status");
if (this.status == newValue) return this;
return new ImmutableObjectsResult<>(this.repo, this.objects, newValue, this.messages);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ObjectsActions.ObjectsResult#getMessages() messages}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableObjectsResult withMessages(Message... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableObjectsResult<>(this.repo, this.objects, this.status, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link ObjectsActions.ObjectsResult#getMessages() messages}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of messages elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableObjectsResult withMessages(Iterable extends Message> elements) {
if (this.messages == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableObjectsResult<>(this.repo, this.objects, this.status, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableObjectsResult} 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 ImmutableObjectsResult>
&& equalTo(0, (ImmutableObjectsResult>) another);
}
private boolean equalTo(int synthetic, ImmutableObjectsResult> another) {
return Objects.equals(repo, another.repo)
&& Objects.equals(objects, another.objects)
&& status.equals(another.status)
&& messages.equals(another.messages);
}
/**
* Computes a hash code from attributes: {@code repo}, {@code objects}, {@code status}, {@code messages}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + Objects.hashCode(repo);
h += (h << 5) + Objects.hashCode(objects);
h += (h << 5) + status.hashCode();
h += (h << 5) + messages.hashCode();
return h;
}
/**
* Prints the immutable value {@code ObjectsResult} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ObjectsResult")
.omitNullValues()
.add("repo", repo)
.add("objects", objects)
.add("status", status)
.add("messages", messages)
.toString();
}
/**
* Creates an immutable copy of a {@link ObjectsActions.ObjectsResult} value.
* Uses accessors to get values to initialize the new immutable instance.
* If an instance is already immutable, it is returned as is.
* @param generic parameter T
* @param instance The instance to copy
* @return A copied immutable ObjectsResult instance
*/
public static ImmutableObjectsResult copyOf(ObjectsActions.ObjectsResult instance) {
if (instance instanceof ImmutableObjectsResult>) {
return (ImmutableObjectsResult) instance;
}
return ImmutableObjectsResult.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableObjectsResult ImmutableObjectsResult}.
*
* ImmutableObjectsResult.<T>builder()
* .repo(io.resys.thena.docdb.api.models.Repo | null) // nullable {@link ObjectsActions.ObjectsResult#getRepo() repo}
* .objects(T | null) // nullable {@link ObjectsActions.ObjectsResult#getObjects() objects}
* .status(io.resys.thena.docdb.api.actions.ObjectsActions.ObjectsStatus) // required {@link ObjectsActions.ObjectsResult#getStatus() status}
* .addMessages|addAllMessages(io.resys.thena.docdb.api.models.Message) // {@link ObjectsActions.ObjectsResult#getMessages() messages} elements
* .build();
*
* @param generic parameter T
* @return A new ImmutableObjectsResult builder
*/
public static ImmutableObjectsResult.Builder builder() {
return new ImmutableObjectsResult.Builder<>();
}
/**
* Builds instances of type {@link ImmutableObjectsResult ImmutableObjectsResult}.
* 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 = "ObjectsActions.ObjectsResult", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_STATUS = 0x1L;
private long initBits = 0x1L;
private @Nullable Repo repo;
private @Nullable T objects;
private @Nullable ObjectsActions.ObjectsStatus status;
private ImmutableList.Builder messages = ImmutableList.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ObjectsResult} 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
*/
@CanIgnoreReturnValue
public final Builder from(ObjectsActions.ObjectsResult instance) {
Objects.requireNonNull(instance, "instance");
@Nullable Repo repoValue = instance.getRepo();
if (repoValue != null) {
repo(repoValue);
}
@Nullable T objectsValue = instance.getObjects();
if (objectsValue != null) {
objects(objectsValue);
}
this.status(instance.getStatus());
addAllMessages(instance.getMessages());
return this;
}
/**
* Initializes the value for the {@link ObjectsActions.ObjectsResult#getRepo() repo} attribute.
* @param repo The value for repo (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder repo(@Nullable Repo repo) {
this.repo = repo;
return this;
}
/**
* Initializes the value for the {@link ObjectsActions.ObjectsResult#getObjects() objects} attribute.
* @param objects The value for objects (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder objects(@Nullable T objects) {
this.objects = objects;
return this;
}
/**
* Initializes the value for the {@link ObjectsActions.ObjectsResult#getStatus() status} attribute.
* @param status The value for status
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder status(ObjectsActions.ObjectsStatus status) {
this.status = Objects.requireNonNull(status, "status");
initBits &= ~INIT_BIT_STATUS;
return this;
}
/**
* Adds one element to {@link ObjectsActions.ObjectsResult#getMessages() messages} list.
* @param element A messages element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addMessages(Message element) {
this.messages.add(element);
return this;
}
/**
* Adds elements to {@link ObjectsActions.ObjectsResult#getMessages() messages} list.
* @param elements An array of messages elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addMessages(Message... elements) {
this.messages.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link ObjectsActions.ObjectsResult#getMessages() messages} list.
* @param elements An iterable of messages elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder messages(Iterable extends Message> elements) {
this.messages = ImmutableList.builder();
return addAllMessages(elements);
}
/**
* Adds elements to {@link ObjectsActions.ObjectsResult#getMessages() messages} list.
* @param elements An iterable of messages elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllMessages(Iterable extends Message> elements) {
this.messages.addAll(elements);
return this;
}
/**
* Builds a new {@link ImmutableObjectsResult ImmutableObjectsResult}.
* @return An immutable instance of ObjectsResult
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableObjectsResult build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableObjectsResult<>(repo, objects, status, messages.build());
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_STATUS) != 0) attributes.add("status");
return "Cannot build ObjectsResult, some of required attributes are not set " + attributes;
}
}
}