io.resys.hdes.client.api.programs.ImmutableDecisionRow Maven / Gradle / Ivy
package io.resys.hdes.client.api.programs;
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 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 DecisionProgram.DecisionRow}.
*
* Use the builder to create immutable instances:
* {@code ImmutableDecisionRow.builder()}.
*/
@Generated(from = "DecisionProgram.DecisionRow", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableDecisionRow
implements DecisionProgram.DecisionRow {
private final int order;
private final ImmutableList accepts;
private final ImmutableList returns;
private ImmutableDecisionRow(
int order,
ImmutableList accepts,
ImmutableList returns) {
this.order = order;
this.accepts = accepts;
this.returns = returns;
}
/**
* @return The value of the {@code order} attribute
*/
@Override
public int getOrder() {
return order;
}
/**
* @return The value of the {@code accepts} attribute
*/
@Override
public ImmutableList getAccepts() {
return accepts;
}
/**
* @return The value of the {@code returns} attribute
*/
@Override
public ImmutableList getReturns() {
return returns;
}
/**
* Copy the current immutable object by setting a value for the {@link DecisionProgram.DecisionRow#getOrder() order} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for order
* @return A modified copy of the {@code this} object
*/
public final ImmutableDecisionRow withOrder(int value) {
if (this.order == value) return this;
return new ImmutableDecisionRow(value, this.accepts, this.returns);
}
/**
* Copy the current immutable object with elements that replace the content of {@link DecisionProgram.DecisionRow#getAccepts() accepts}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableDecisionRow withAccepts(DecisionProgram.DecisionRowAccepts... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableDecisionRow(this.order, newValue, this.returns);
}
/**
* Copy the current immutable object with elements that replace the content of {@link DecisionProgram.DecisionRow#getAccepts() accepts}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of accepts elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableDecisionRow withAccepts(Iterable extends DecisionProgram.DecisionRowAccepts> elements) {
if (this.accepts == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableDecisionRow(this.order, newValue, this.returns);
}
/**
* Copy the current immutable object with elements that replace the content of {@link DecisionProgram.DecisionRow#getReturns() returns}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableDecisionRow withReturns(DecisionProgram.DecisionRowReturns... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableDecisionRow(this.order, this.accepts, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link DecisionProgram.DecisionRow#getReturns() returns}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of returns elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableDecisionRow withReturns(Iterable extends DecisionProgram.DecisionRowReturns> elements) {
if (this.returns == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableDecisionRow(this.order, this.accepts, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableDecisionRow} 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 ImmutableDecisionRow
&& equalTo((ImmutableDecisionRow) another);
}
private boolean equalTo(ImmutableDecisionRow another) {
return order == another.order
&& accepts.equals(another.accepts)
&& returns.equals(another.returns);
}
/**
* Computes a hash code from attributes: {@code order}, {@code accepts}, {@code returns}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + order;
h += (h << 5) + accepts.hashCode();
h += (h << 5) + returns.hashCode();
return h;
}
/**
* Prints the immutable value {@code DecisionRow} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("DecisionRow")
.omitNullValues()
.add("order", order)
.add("accepts", accepts)
.add("returns", returns)
.toString();
}
/**
* Creates an immutable copy of a {@link DecisionProgram.DecisionRow} 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 DecisionRow instance
*/
public static ImmutableDecisionRow copyOf(DecisionProgram.DecisionRow instance) {
if (instance instanceof ImmutableDecisionRow) {
return (ImmutableDecisionRow) instance;
}
return ImmutableDecisionRow.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableDecisionRow ImmutableDecisionRow}.
*
* ImmutableDecisionRow.builder()
* .order(int) // required {@link DecisionProgram.DecisionRow#getOrder() order}
* .addAccepts|addAllAccepts(io.resys.hdes.client.api.programs.DecisionProgram.DecisionRowAccepts) // {@link DecisionProgram.DecisionRow#getAccepts() accepts} elements
* .addReturns|addAllReturns(io.resys.hdes.client.api.programs.DecisionProgram.DecisionRowReturns) // {@link DecisionProgram.DecisionRow#getReturns() returns} elements
* .build();
*
* @return A new ImmutableDecisionRow builder
*/
public static ImmutableDecisionRow.Builder builder() {
return new ImmutableDecisionRow.Builder();
}
/**
* Builds instances of type {@link ImmutableDecisionRow ImmutableDecisionRow}.
* 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 = "DecisionProgram.DecisionRow", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_ORDER = 0x1L;
private long initBits = 0x1L;
private int order;
private ImmutableList.Builder accepts = ImmutableList.builder();
private ImmutableList.Builder returns = ImmutableList.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code DecisionRow} 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(DecisionProgram.DecisionRow instance) {
Objects.requireNonNull(instance, "instance");
order(instance.getOrder());
addAllAccepts(instance.getAccepts());
addAllReturns(instance.getReturns());
return this;
}
/**
* Initializes the value for the {@link DecisionProgram.DecisionRow#getOrder() order} attribute.
* @param order The value for order
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder order(int order) {
this.order = order;
initBits &= ~INIT_BIT_ORDER;
return this;
}
/**
* Adds one element to {@link DecisionProgram.DecisionRow#getAccepts() accepts} list.
* @param element A accepts element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAccepts(DecisionProgram.DecisionRowAccepts element) {
this.accepts.add(element);
return this;
}
/**
* Adds elements to {@link DecisionProgram.DecisionRow#getAccepts() accepts} list.
* @param elements An array of accepts elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAccepts(DecisionProgram.DecisionRowAccepts... elements) {
this.accepts.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link DecisionProgram.DecisionRow#getAccepts() accepts} list.
* @param elements An iterable of accepts elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder accepts(Iterable extends DecisionProgram.DecisionRowAccepts> elements) {
this.accepts = ImmutableList.builder();
return addAllAccepts(elements);
}
/**
* Adds elements to {@link DecisionProgram.DecisionRow#getAccepts() accepts} list.
* @param elements An iterable of accepts elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllAccepts(Iterable extends DecisionProgram.DecisionRowAccepts> elements) {
this.accepts.addAll(elements);
return this;
}
/**
* Adds one element to {@link DecisionProgram.DecisionRow#getReturns() returns} list.
* @param element A returns element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addReturns(DecisionProgram.DecisionRowReturns element) {
this.returns.add(element);
return this;
}
/**
* Adds elements to {@link DecisionProgram.DecisionRow#getReturns() returns} list.
* @param elements An array of returns elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addReturns(DecisionProgram.DecisionRowReturns... elements) {
this.returns.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link DecisionProgram.DecisionRow#getReturns() returns} list.
* @param elements An iterable of returns elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder returns(Iterable extends DecisionProgram.DecisionRowReturns> elements) {
this.returns = ImmutableList.builder();
return addAllReturns(elements);
}
/**
* Adds elements to {@link DecisionProgram.DecisionRow#getReturns() returns} list.
* @param elements An iterable of returns elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllReturns(Iterable extends DecisionProgram.DecisionRowReturns> elements) {
this.returns.addAll(elements);
return this;
}
/**
* Builds a new {@link ImmutableDecisionRow ImmutableDecisionRow}.
* @return An immutable instance of DecisionRow
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableDecisionRow build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableDecisionRow(order, accepts.build(), returns.build());
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_ORDER) != 0) attributes.add("order");
return "Cannot build DecisionRow, some of required attributes are not set " + attributes;
}
}
}