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

io.resys.hdes.ast.api.nodes.ImmutableHitPolicyAll Maven / Gradle / Ivy

The newest version!
package io.resys.hdes.ast.api.nodes;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
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 DecisionTableNode.HitPolicyAll}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableHitPolicyAll.builder()}. */ @Generated(from = "DecisionTableNode.HitPolicyAll", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable public final class ImmutableHitPolicyAll implements DecisionTableNode.HitPolicyAll { private final HdesNode.Token token; private final List rows; private ImmutableHitPolicyAll( HdesNode.Token token, List rows) { this.token = token; this.rows = rows; } /** * @return The value of the {@code token} attribute */ @Override public HdesNode.Token getToken() { return token; } /** * @return The value of the {@code rows} attribute */ @Override public List getRows() { return rows; } /** * Copy the current immutable object by setting a value for the {@link DecisionTableNode.HitPolicyAll#getToken() token} 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 token * @return A modified copy of the {@code this} object */ public final ImmutableHitPolicyAll withToken(HdesNode.Token value) { if (this.token == value) return this; HdesNode.Token newValue = Objects.requireNonNull(value, "token"); return new ImmutableHitPolicyAll(newValue, this.rows); } /** * Copy the current immutable object with elements that replace the content of {@link DecisionTableNode.HitPolicyAll#getRows() rows}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableHitPolicyAll withRows(DecisionTableNode.RuleRow... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return new ImmutableHitPolicyAll(this.token, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link DecisionTableNode.HitPolicyAll#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 ImmutableHitPolicyAll withRows(Iterable elements) { if (this.rows == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return new ImmutableHitPolicyAll(this.token, newValue); } /** * This instance is equal to all instances of {@code ImmutableHitPolicyAll} 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 ImmutableHitPolicyAll && equalTo((ImmutableHitPolicyAll) another); } private boolean equalTo(ImmutableHitPolicyAll another) { return token.equals(another.token) && rows.equals(another.rows); } /** * Computes a hash code from attributes: {@code token}, {@code rows}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + token.hashCode(); h += (h << 5) + rows.hashCode(); return h; } /** * Prints the immutable value {@code HitPolicyAll} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "HitPolicyAll{" + "token=" + token + ", rows=" + rows + "}"; } /** * Creates an immutable copy of a {@link DecisionTableNode.HitPolicyAll} 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 HitPolicyAll instance */ public static ImmutableHitPolicyAll copyOf(DecisionTableNode.HitPolicyAll instance) { if (instance instanceof ImmutableHitPolicyAll) { return (ImmutableHitPolicyAll) instance; } return ImmutableHitPolicyAll.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableHitPolicyAll ImmutableHitPolicyAll}. *

   * ImmutableHitPolicyAll.builder()
   *    .token(io.resys.hdes.ast.api.nodes.HdesNode.Token) // required {@link DecisionTableNode.HitPolicyAll#getToken() token}
   *    .addRows|addAllRows(io.resys.hdes.ast.api.nodes.DecisionTableNode.RuleRow) // {@link DecisionTableNode.HitPolicyAll#getRows() rows} elements
   *    .build();
   * 
* @return A new ImmutableHitPolicyAll builder */ public static ImmutableHitPolicyAll.Builder builder() { return new ImmutableHitPolicyAll.Builder(); } /** * Builds instances of type {@link ImmutableHitPolicyAll ImmutableHitPolicyAll}. * 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 = "DecisionTableNode.HitPolicyAll", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_TOKEN = 0x1L; private long initBits = 0x1L; private @Nullable HdesNode.Token token; private List rows = new ArrayList(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code io.resys.hdes.ast.api.nodes.HdesNode} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(HdesNode instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } /** * Fill a builder with attribute values from the provided {@code io.resys.hdes.ast.api.nodes.DecisionTableNode.HitPolicyAll} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(DecisionTableNode.HitPolicyAll instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return this; } private void from(Object object) { if (object instanceof HdesNode) { HdesNode instance = (HdesNode) object; token(instance.getToken()); } if (object instanceof DecisionTableNode.HitPolicyAll) { DecisionTableNode.HitPolicyAll instance = (DecisionTableNode.HitPolicyAll) object; addAllRows(instance.getRows()); } } /** * Initializes the value for the {@link DecisionTableNode.HitPolicyAll#getToken() token} attribute. * @param token The value for token * @return {@code this} builder for use in a chained invocation */ public final Builder token(HdesNode.Token token) { this.token = Objects.requireNonNull(token, "token"); initBits &= ~INIT_BIT_TOKEN; return this; } /** * Adds one element to {@link DecisionTableNode.HitPolicyAll#getRows() rows} list. * @param element A rows element * @return {@code this} builder for use in a chained invocation */ public final Builder addRows(DecisionTableNode.RuleRow element) { this.rows.add(Objects.requireNonNull(element, "rows element")); return this; } /** * Adds elements to {@link DecisionTableNode.HitPolicyAll#getRows() rows} list. * @param elements An array of rows elements * @return {@code this} builder for use in a chained invocation */ public final Builder addRows(DecisionTableNode.RuleRow... elements) { for (DecisionTableNode.RuleRow element : elements) { this.rows.add(Objects.requireNonNull(element, "rows element")); } return this; } /** * Sets or replaces all elements for {@link DecisionTableNode.HitPolicyAll#getRows() rows} list. * @param elements An iterable of rows elements * @return {@code this} builder for use in a chained invocation */ public final Builder rows(Iterable elements) { this.rows.clear(); return addAllRows(elements); } /** * Adds elements to {@link DecisionTableNode.HitPolicyAll#getRows() rows} list. * @param elements An iterable of rows elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllRows(Iterable elements) { for (DecisionTableNode.RuleRow element : elements) { this.rows.add(Objects.requireNonNull(element, "rows element")); } return this; } /** * Builds a new {@link ImmutableHitPolicyAll ImmutableHitPolicyAll}. * @return An immutable instance of HitPolicyAll * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableHitPolicyAll build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableHitPolicyAll(token, createUnmodifiableList(true, rows)); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_TOKEN) != 0) attributes.add("token"); return "Cannot build HitPolicyAll, some of required attributes are not set " + attributes; } } private static List createSafeList(Iterable iterable, boolean checkNulls, boolean skipNulls) { ArrayList list; if (iterable instanceof Collection) { int size = ((Collection) iterable).size(); if (size == 0) return Collections.emptyList(); list = new ArrayList<>(); } else { list = new ArrayList<>(); } for (T element : iterable) { if (skipNulls && element == null) continue; if (checkNulls) Objects.requireNonNull(element, "element"); list.add(element); } return list; } private static List createUnmodifiableList(boolean clone, List list) { switch(list.size()) { case 0: return Collections.emptyList(); case 1: return Collections.singletonList(list.get(0)); default: if (clone) { return Collections.unmodifiableList(new ArrayList<>(list)); } else { if (list instanceof ArrayList) { ((ArrayList) list).trimToSize(); } return Collections.unmodifiableList(list); } } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy