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