io.resys.wrench.assets.flow.api.model.ImmutableFlowModel Maven / Gradle / Ivy
package io.resys.wrench.assets.flow.api.model;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import io.resys.wrench.assets.datatype.api.DataTypeRepository;
import java.util.ArrayList;
import java.util.Collection;
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 FlowModel}.
*
* Use the builder to create immutable instances:
* {@code ImmutableFlowModel.builder()}.
*/
@Generated(from = "FlowModel", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableFlowModel implements FlowModel {
private final String id;
private final int rev;
private final @Nullable String description;
private final String src;
private final Collection inputs;
private final FlowModel.FlowTaskModel task;
private final Collection tasks;
private ImmutableFlowModel(
String id,
int rev,
@Nullable String description,
String src,
Collection inputs,
FlowModel.FlowTaskModel task,
Collection tasks) {
this.id = id;
this.rev = rev;
this.description = description;
this.src = src;
this.inputs = inputs;
this.task = task;
this.tasks = tasks;
}
/**
* @return The value of the {@code id} attribute
*/
@Override
public String getId() {
return id;
}
/**
* @return The value of the {@code rev} attribute
*/
@Override
public int getRev() {
return rev;
}
/**
* @return The value of the {@code description} attribute
*/
@Override
public @Nullable String getDescription() {
return description;
}
/**
* @return The value of the {@code src} attribute
*/
@Override
public String getSrc() {
return src;
}
/**
* @return The value of the {@code inputs} attribute
*/
@Override
public Collection getInputs() {
return inputs;
}
/**
* @return The value of the {@code task} attribute
*/
@Override
public FlowModel.FlowTaskModel getTask() {
return task;
}
/**
* @return The value of the {@code tasks} attribute
*/
@Override
public Collection getTasks() {
return tasks;
}
/**
* Copy the current immutable object by setting a value for the {@link FlowModel#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 ImmutableFlowModel withId(String value) {
String newValue = Objects.requireNonNull(value, "id");
if (this.id.equals(newValue)) return this;
return new ImmutableFlowModel(newValue, this.rev, this.description, this.src, this.inputs, this.task, this.tasks);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowModel#getRev() rev} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for rev
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowModel withRev(int value) {
if (this.rev == value) return this;
return new ImmutableFlowModel(this.id, value, this.description, this.src, this.inputs, this.task, this.tasks);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowModel#getDescription() description} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for description (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowModel withDescription(@Nullable String value) {
if (Objects.equals(this.description, value)) return this;
return new ImmutableFlowModel(this.id, this.rev, value, this.src, this.inputs, this.task, this.tasks);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowModel#getSrc() src} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for src
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowModel withSrc(String value) {
String newValue = Objects.requireNonNull(value, "src");
if (this.src.equals(newValue)) return this;
return new ImmutableFlowModel(this.id, this.rev, this.description, newValue, this.inputs, this.task, this.tasks);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowModel#getInputs() inputs} 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 inputs
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowModel withInputs(Collection value) {
if (this.inputs == value) return this;
Collection newValue = Objects.requireNonNull(value, "inputs");
return new ImmutableFlowModel(this.id, this.rev, this.description, this.src, newValue, this.task, this.tasks);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowModel#getTask() task} 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 task
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowModel withTask(FlowModel.FlowTaskModel value) {
if (this.task == value) return this;
FlowModel.FlowTaskModel newValue = Objects.requireNonNull(value, "task");
return new ImmutableFlowModel(this.id, this.rev, this.description, this.src, this.inputs, newValue, this.tasks);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowModel#getTasks() tasks} 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 tasks
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowModel withTasks(Collection value) {
if (this.tasks == value) return this;
Collection newValue = Objects.requireNonNull(value, "tasks");
return new ImmutableFlowModel(this.id, this.rev, this.description, this.src, this.inputs, this.task, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableFlowModel} 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 ImmutableFlowModel
&& equalTo((ImmutableFlowModel) another);
}
private boolean equalTo(ImmutableFlowModel another) {
return id.equals(another.id)
&& rev == another.rev
&& Objects.equals(description, another.description)
&& src.equals(another.src)
&& inputs.equals(another.inputs)
&& task.equals(another.task)
&& tasks.equals(another.tasks);
}
/**
* Computes a hash code from attributes: {@code id}, {@code rev}, {@code description}, {@code src}, {@code inputs}, {@code task}, {@code tasks}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + id.hashCode();
h += (h << 5) + rev;
h += (h << 5) + Objects.hashCode(description);
h += (h << 5) + src.hashCode();
h += (h << 5) + inputs.hashCode();
h += (h << 5) + task.hashCode();
h += (h << 5) + tasks.hashCode();
return h;
}
/**
* Prints the immutable value {@code FlowModel} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("FlowModel")
.omitNullValues()
.add("id", id)
.add("rev", rev)
.add("description", description)
.add("src", src)
.add("inputs", inputs)
.add("task", task)
.add("tasks", tasks)
.toString();
}
/**
* Creates an immutable copy of a {@link FlowModel} 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 FlowModel instance
*/
public static ImmutableFlowModel copyOf(FlowModel instance) {
if (instance instanceof ImmutableFlowModel) {
return (ImmutableFlowModel) instance;
}
return ImmutableFlowModel.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableFlowModel ImmutableFlowModel}.
*
* ImmutableFlowModel.builder()
* .id(String) // required {@link FlowModel#getId() id}
* .rev(int) // required {@link FlowModel#getRev() rev}
* .description(String | null) // nullable {@link FlowModel#getDescription() description}
* .src(String) // required {@link FlowModel#getSrc() src}
* .inputs(Collection<io.resys.wrench.assets.datatype.api.DataTypeRepository.DataType>) // required {@link FlowModel#getInputs() inputs}
* .task(io.resys.wrench.assets.flow.api.model.FlowModel.FlowTaskModel) // required {@link FlowModel#getTask() task}
* .tasks(Collection<io.resys.wrench.assets.flow.api.model.FlowModel.FlowTaskModel>) // required {@link FlowModel#getTasks() tasks}
* .build();
*
* @return A new ImmutableFlowModel builder
*/
public static ImmutableFlowModel.Builder builder() {
return new ImmutableFlowModel.Builder();
}
/**
* Builds instances of type {@link ImmutableFlowModel ImmutableFlowModel}.
* 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 = "FlowModel", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_ID = 0x1L;
private static final long INIT_BIT_REV = 0x2L;
private static final long INIT_BIT_SRC = 0x4L;
private static final long INIT_BIT_INPUTS = 0x8L;
private static final long INIT_BIT_TASK = 0x10L;
private static final long INIT_BIT_TASKS = 0x20L;
private long initBits = 0x3fL;
private @Nullable String id;
private int rev;
private @Nullable String description;
private @Nullable String src;
private @Nullable Collection inputs;
private @Nullable FlowModel.FlowTaskModel task;
private @Nullable Collection tasks;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code FlowModel} 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(FlowModel instance) {
Objects.requireNonNull(instance, "instance");
id(instance.getId());
rev(instance.getRev());
@Nullable String descriptionValue = instance.getDescription();
if (descriptionValue != null) {
description(descriptionValue);
}
src(instance.getSrc());
inputs(instance.getInputs());
task(instance.getTask());
tasks(instance.getTasks());
return this;
}
/**
* Initializes the value for the {@link FlowModel#getId() id} attribute.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder id(String id) {
this.id = Objects.requireNonNull(id, "id");
initBits &= ~INIT_BIT_ID;
return this;
}
/**
* Initializes the value for the {@link FlowModel#getRev() rev} attribute.
* @param rev The value for rev
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder rev(int rev) {
this.rev = rev;
initBits &= ~INIT_BIT_REV;
return this;
}
/**
* Initializes the value for the {@link FlowModel#getDescription() description} attribute.
* @param description The value for description (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder description(@Nullable String description) {
this.description = description;
return this;
}
/**
* Initializes the value for the {@link FlowModel#getSrc() src} attribute.
* @param src The value for src
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder src(String src) {
this.src = Objects.requireNonNull(src, "src");
initBits &= ~INIT_BIT_SRC;
return this;
}
/**
* Initializes the value for the {@link FlowModel#getInputs() inputs} attribute.
* @param inputs The value for inputs
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder inputs(Collection inputs) {
this.inputs = Objects.requireNonNull(inputs, "inputs");
initBits &= ~INIT_BIT_INPUTS;
return this;
}
/**
* Initializes the value for the {@link FlowModel#getTask() task} attribute.
* @param task The value for task
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder task(FlowModel.FlowTaskModel task) {
this.task = Objects.requireNonNull(task, "task");
initBits &= ~INIT_BIT_TASK;
return this;
}
/**
* Initializes the value for the {@link FlowModel#getTasks() tasks} attribute.
* @param tasks The value for tasks
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder tasks(Collection tasks) {
this.tasks = Objects.requireNonNull(tasks, "tasks");
initBits &= ~INIT_BIT_TASKS;
return this;
}
/**
* Builds a new {@link ImmutableFlowModel ImmutableFlowModel}.
* @return An immutable instance of FlowModel
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableFlowModel build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableFlowModel(id, rev, description, src, inputs, task, tasks);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_ID) != 0) attributes.add("id");
if ((initBits & INIT_BIT_REV) != 0) attributes.add("rev");
if ((initBits & INIT_BIT_SRC) != 0) attributes.add("src");
if ((initBits & INIT_BIT_INPUTS) != 0) attributes.add("inputs");
if ((initBits & INIT_BIT_TASK) != 0) attributes.add("task");
if ((initBits & INIT_BIT_TASKS) != 0) attributes.add("tasks");
return "Cannot build FlowModel, some of required attributes are not set " + attributes;
}
}
}