io.thestencil.iam.api.ImmutableUserTask Maven / Gradle / Ivy
package io.thestencil.iam.api;
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 com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.time.ZonedDateTime;
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 UserActionsClient.UserTask}.
*
* Use the builder to create immutable instances:
* {@code ImmutableUserTask.builder()}.
*/
@Generated(from = "UserActionsClient.UserTask", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableUserTask implements UserActionsClient.UserTask {
private final String id;
private final String status;
private final @Nullable String taskRef;
private final ZonedDateTime created;
private final @Nullable ZonedDateTime updated;
private ImmutableUserTask(
String id,
String status,
@Nullable String taskRef,
ZonedDateTime created,
@Nullable ZonedDateTime updated) {
this.id = id;
this.status = status;
this.taskRef = taskRef;
this.created = created;
this.updated = updated;
}
/**
* @return The value of the {@code id} attribute
*/
@JsonProperty("id")
@Override
public String getId() {
return id;
}
/**
* @return The value of the {@code status} attribute
*/
@JsonProperty("status")
@Override
public String getStatus() {
return status;
}
/**
* @return The value of the {@code taskRef} attribute
*/
@JsonProperty("taskRef")
@Override
public @Nullable String getTaskRef() {
return taskRef;
}
/**
* @return The value of the {@code created} attribute
*/
@JsonProperty("created")
@Override
public ZonedDateTime getCreated() {
return created;
}
/**
* @return The value of the {@code updated} attribute
*/
@JsonProperty("updated")
@Override
public @Nullable ZonedDateTime getUpdated() {
return updated;
}
/**
* Copy the current immutable object by setting a value for the {@link UserActionsClient.UserTask#getId() id} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for id
* @return A modified copy of the {@code this} object
*/
public final ImmutableUserTask withId(String value) {
String newValue = Objects.requireNonNull(value, "id");
if (this.id.equals(newValue)) return this;
return new ImmutableUserTask(newValue, this.status, this.taskRef, this.created, this.updated);
}
/**
* Copy the current immutable object by setting a value for the {@link UserActionsClient.UserTask#getStatus() 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 ImmutableUserTask withStatus(String value) {
String newValue = Objects.requireNonNull(value, "status");
if (this.status.equals(newValue)) return this;
return new ImmutableUserTask(this.id, newValue, this.taskRef, this.created, this.updated);
}
/**
* Copy the current immutable object by setting a value for the {@link UserActionsClient.UserTask#getTaskRef() taskRef} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for taskRef (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableUserTask withTaskRef(@Nullable String value) {
if (Objects.equals(this.taskRef, value)) return this;
return new ImmutableUserTask(this.id, this.status, value, this.created, this.updated);
}
/**
* Copy the current immutable object by setting a value for the {@link UserActionsClient.UserTask#getCreated() created} 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 created
* @return A modified copy of the {@code this} object
*/
public final ImmutableUserTask withCreated(ZonedDateTime value) {
if (this.created == value) return this;
ZonedDateTime newValue = Objects.requireNonNull(value, "created");
return new ImmutableUserTask(this.id, this.status, this.taskRef, newValue, this.updated);
}
/**
* Copy the current immutable object by setting a value for the {@link UserActionsClient.UserTask#getUpdated() updated} 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 updated (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableUserTask withUpdated(@Nullable ZonedDateTime value) {
if (this.updated == value) return this;
return new ImmutableUserTask(this.id, this.status, this.taskRef, this.created, value);
}
/**
* This instance is equal to all instances of {@code ImmutableUserTask} 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 ImmutableUserTask
&& equalTo((ImmutableUserTask) another);
}
private boolean equalTo(ImmutableUserTask another) {
return id.equals(another.id)
&& status.equals(another.status)
&& Objects.equals(taskRef, another.taskRef)
&& created.equals(another.created)
&& Objects.equals(updated, another.updated);
}
/**
* Computes a hash code from attributes: {@code id}, {@code status}, {@code taskRef}, {@code created}, {@code updated}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + id.hashCode();
h += (h << 5) + status.hashCode();
h += (h << 5) + Objects.hashCode(taskRef);
h += (h << 5) + created.hashCode();
h += (h << 5) + Objects.hashCode(updated);
return h;
}
/**
* Prints the immutable value {@code UserTask} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("UserTask")
.omitNullValues()
.add("id", id)
.add("status", status)
.add("taskRef", taskRef)
.add("created", created)
.add("updated", updated)
.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 = "UserActionsClient.UserTask", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements UserActionsClient.UserTask {
@Nullable String id;
@Nullable String status;
@Nullable String taskRef;
@Nullable ZonedDateTime created;
@Nullable ZonedDateTime updated;
@JsonProperty("id")
public void setId(String id) {
this.id = id;
}
@JsonProperty("status")
public void setStatus(String status) {
this.status = status;
}
@JsonProperty("taskRef")
public void setTaskRef(@Nullable String taskRef) {
this.taskRef = taskRef;
}
@JsonProperty("created")
public void setCreated(ZonedDateTime created) {
this.created = created;
}
@JsonProperty("updated")
public void setUpdated(@Nullable ZonedDateTime updated) {
this.updated = updated;
}
@Override
public String getId() { throw new UnsupportedOperationException(); }
@Override
public String getStatus() { throw new UnsupportedOperationException(); }
@Override
public String getTaskRef() { throw new UnsupportedOperationException(); }
@Override
public ZonedDateTime getCreated() { throw new UnsupportedOperationException(); }
@Override
public ZonedDateTime getUpdated() { 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 ImmutableUserTask fromJson(Json json) {
ImmutableUserTask.Builder builder = ImmutableUserTask.builder();
if (json.id != null) {
builder.id(json.id);
}
if (json.status != null) {
builder.status(json.status);
}
if (json.taskRef != null) {
builder.taskRef(json.taskRef);
}
if (json.created != null) {
builder.created(json.created);
}
if (json.updated != null) {
builder.updated(json.updated);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link UserActionsClient.UserTask} 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 UserTask instance
*/
public static ImmutableUserTask copyOf(UserActionsClient.UserTask instance) {
if (instance instanceof ImmutableUserTask) {
return (ImmutableUserTask) instance;
}
return ImmutableUserTask.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableUserTask ImmutableUserTask}.
*
* ImmutableUserTask.builder()
* .id(String) // required {@link UserActionsClient.UserTask#getId() id}
* .status(String) // required {@link UserActionsClient.UserTask#getStatus() status}
* .taskRef(String | null) // nullable {@link UserActionsClient.UserTask#getTaskRef() taskRef}
* .created(java.time.ZonedDateTime) // required {@link UserActionsClient.UserTask#getCreated() created}
* .updated(java.time.ZonedDateTime | null) // nullable {@link UserActionsClient.UserTask#getUpdated() updated}
* .build();
*
* @return A new ImmutableUserTask builder
*/
public static ImmutableUserTask.Builder builder() {
return new ImmutableUserTask.Builder();
}
/**
* Builds instances of type {@link ImmutableUserTask ImmutableUserTask}.
* 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 = "UserActionsClient.UserTask", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_ID = 0x1L;
private static final long INIT_BIT_STATUS = 0x2L;
private static final long INIT_BIT_CREATED = 0x4L;
private long initBits = 0x7L;
private @Nullable String id;
private @Nullable String status;
private @Nullable String taskRef;
private @Nullable ZonedDateTime created;
private @Nullable ZonedDateTime updated;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code UserTask} 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
*/
@CanIgnoreReturnValue
public final Builder from(UserActionsClient.UserTask instance) {
Objects.requireNonNull(instance, "instance");
id(instance.getId());
status(instance.getStatus());
@Nullable String taskRefValue = instance.getTaskRef();
if (taskRefValue != null) {
taskRef(taskRefValue);
}
created(instance.getCreated());
@Nullable ZonedDateTime updatedValue = instance.getUpdated();
if (updatedValue != null) {
updated(updatedValue);
}
return this;
}
/**
* Initializes the value for the {@link UserActionsClient.UserTask#getId() id} attribute.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("id")
public final Builder id(String id) {
this.id = Objects.requireNonNull(id, "id");
initBits &= ~INIT_BIT_ID;
return this;
}
/**
* Initializes the value for the {@link UserActionsClient.UserTask#getStatus() status} attribute.
* @param status The value for status
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("status")
public final Builder status(String status) {
this.status = Objects.requireNonNull(status, "status");
initBits &= ~INIT_BIT_STATUS;
return this;
}
/**
* Initializes the value for the {@link UserActionsClient.UserTask#getTaskRef() taskRef} attribute.
* @param taskRef The value for taskRef (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("taskRef")
public final Builder taskRef(@Nullable String taskRef) {
this.taskRef = taskRef;
return this;
}
/**
* Initializes the value for the {@link UserActionsClient.UserTask#getCreated() created} attribute.
* @param created The value for created
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("created")
public final Builder created(ZonedDateTime created) {
this.created = Objects.requireNonNull(created, "created");
initBits &= ~INIT_BIT_CREATED;
return this;
}
/**
* Initializes the value for the {@link UserActionsClient.UserTask#getUpdated() updated} attribute.
* @param updated The value for updated (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("updated")
public final Builder updated(@Nullable ZonedDateTime updated) {
this.updated = updated;
return this;
}
/**
* Builds a new {@link ImmutableUserTask ImmutableUserTask}.
* @return An immutable instance of UserTask
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableUserTask build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableUserTask(id, status, taskRef, created, updated);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_ID) != 0) attributes.add("id");
if ((initBits & INIT_BIT_STATUS) != 0) attributes.add("status");
if ((initBits & INIT_BIT_CREATED) != 0) attributes.add("created");
return "Cannot build UserTask, some of required attributes are not set " + attributes;
}
}
}