All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.resys.hdes.client.api.programs.ImmutableDecisionProgram Maven / Gradle / Ivy

There is a newer version: 3.130.78
Show newest version
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 io.resys.hdes.client.api.ast.AstDecision;
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}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableDecisionProgram.builder()}. */ @Generated(from = "DecisionProgram", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableDecisionProgram implements DecisionProgram { private final ImmutableList rows; private final AstDecision.HitPolicy hitPolicy; private ImmutableDecisionProgram( ImmutableList rows, AstDecision.HitPolicy hitPolicy) { this.rows = rows; this.hitPolicy = hitPolicy; } /** * @return The value of the {@code rows} attribute */ @Override public ImmutableList getRows() { return rows; } /** * @return The value of the {@code hitPolicy} attribute */ @Override public AstDecision.HitPolicy getHitPolicy() { return hitPolicy; } /** * Copy the current immutable object with elements that replace the content of {@link DecisionProgram#getRows() rows}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableDecisionProgram withRows(DecisionProgram.DecisionRow... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableDecisionProgram(newValue, this.hitPolicy); } /** * Copy the current immutable object with elements that replace the content of {@link DecisionProgram#getRows() rows}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of rows elements to set * @return A modified copy of {@code this} object */ public final ImmutableDecisionProgram withRows(Iterable elements) { if (this.rows == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableDecisionProgram(newValue, this.hitPolicy); } /** * Copy the current immutable object by setting a value for the {@link DecisionProgram#getHitPolicy() hitPolicy} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for hitPolicy * @return A modified copy of the {@code this} object */ public final ImmutableDecisionProgram withHitPolicy(AstDecision.HitPolicy value) { if (this.hitPolicy == value) return this; AstDecision.HitPolicy newValue = Objects.requireNonNull(value, "hitPolicy"); if (this.hitPolicy.equals(newValue)) return this; return new ImmutableDecisionProgram(this.rows, newValue); } /** * This instance is equal to all instances of {@code ImmutableDecisionProgram} 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 ImmutableDecisionProgram && equalTo((ImmutableDecisionProgram) another); } private boolean equalTo(ImmutableDecisionProgram another) { return rows.equals(another.rows) && hitPolicy.equals(another.hitPolicy); } /** * Computes a hash code from attributes: {@code rows}, {@code hitPolicy}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + rows.hashCode(); h += (h << 5) + hitPolicy.hashCode(); return h; } /** * Prints the immutable value {@code DecisionProgram} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("DecisionProgram") .omitNullValues() .add("rows", rows) .add("hitPolicy", hitPolicy) .toString(); } /** * Creates an immutable copy of a {@link DecisionProgram} 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 DecisionProgram instance */ public static ImmutableDecisionProgram copyOf(DecisionProgram instance) { if (instance instanceof ImmutableDecisionProgram) { return (ImmutableDecisionProgram) instance; } return ImmutableDecisionProgram.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableDecisionProgram ImmutableDecisionProgram}. *

   * ImmutableDecisionProgram.builder()
   *    .addRows|addAllRows(io.resys.hdes.client.api.programs.DecisionProgram.DecisionRow) // {@link DecisionProgram#getRows() rows} elements
   *    .hitPolicy(io.resys.hdes.client.api.ast.AstDecision.HitPolicy) // required {@link DecisionProgram#getHitPolicy() hitPolicy}
   *    .build();
   * 
* @return A new ImmutableDecisionProgram builder */ public static ImmutableDecisionProgram.Builder builder() { return new ImmutableDecisionProgram.Builder(); } /** * Builds instances of type {@link ImmutableDecisionProgram ImmutableDecisionProgram}. * 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", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_HIT_POLICY = 0x1L; private long initBits = 0x1L; private ImmutableList.Builder rows = ImmutableList.builder(); private @Nullable AstDecision.HitPolicy hitPolicy; private Builder() { } /** * Fill a builder with attribute values from the provided {@code DecisionProgram} 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 instance) { Objects.requireNonNull(instance, "instance"); addAllRows(instance.getRows()); hitPolicy(instance.getHitPolicy()); return this; } /** * Adds one element to {@link DecisionProgram#getRows() rows} list. * @param element A rows element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addRows(DecisionProgram.DecisionRow element) { this.rows.add(element); return this; } /** * Adds elements to {@link DecisionProgram#getRows() rows} list. * @param elements An array of rows elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addRows(DecisionProgram.DecisionRow... elements) { this.rows.add(elements); return this; } /** * Sets or replaces all elements for {@link DecisionProgram#getRows() rows} list. * @param elements An iterable of rows elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder rows(Iterable elements) { this.rows = ImmutableList.builder(); return addAllRows(elements); } /** * Adds elements to {@link DecisionProgram#getRows() rows} list. * @param elements An iterable of rows elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder addAllRows(Iterable elements) { this.rows.addAll(elements); return this; } /** * Initializes the value for the {@link DecisionProgram#getHitPolicy() hitPolicy} attribute. * @param hitPolicy The value for hitPolicy * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder hitPolicy(AstDecision.HitPolicy hitPolicy) { this.hitPolicy = Objects.requireNonNull(hitPolicy, "hitPolicy"); initBits &= ~INIT_BIT_HIT_POLICY; return this; } /** * Builds a new {@link ImmutableDecisionProgram ImmutableDecisionProgram}. * @return An immutable instance of DecisionProgram * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableDecisionProgram build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableDecisionProgram(rows.build(), hitPolicy); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_HIT_POLICY) != 0) attributes.add("hitPolicy"); return "Cannot build DecisionProgram, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy