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

io.resys.hdes.ast.api.nodes.ImmutableHitPolicyMapping 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.HitPolicyMapping}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableHitPolicyMapping.builder()}. */ @Generated(from = "DecisionTableNode.HitPolicyMapping", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable public final class ImmutableHitPolicyMapping implements DecisionTableNode.HitPolicyMapping { private final HdesNode.Token token; private final BodyNode.ScalarType defFrom; private final BodyNode.ScalarType defTo; private final DecisionTableNode.WhenRuleRow when; private final List mapsTo; private ImmutableHitPolicyMapping( HdesNode.Token token, BodyNode.ScalarType defFrom, BodyNode.ScalarType defTo, DecisionTableNode.WhenRuleRow when, List mapsTo) { this.token = token; this.defFrom = defFrom; this.defTo = defTo; this.when = when; this.mapsTo = mapsTo; } /** * @return The value of the {@code token} attribute */ @Override public HdesNode.Token getToken() { return token; } /** * @return The value of the {@code defFrom} attribute */ @Override public BodyNode.ScalarType getDefFrom() { return defFrom; } /** * @return The value of the {@code defTo} attribute */ @Override public BodyNode.ScalarType getDefTo() { return defTo; } /** * @return The value of the {@code when} attribute */ @Override public DecisionTableNode.WhenRuleRow getWhen() { return when; } /** * @return The value of the {@code mapsTo} attribute */ @Override public List getMapsTo() { return mapsTo; } /** * Copy the current immutable object by setting a value for the {@link DecisionTableNode.HitPolicyMapping#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 ImmutableHitPolicyMapping withToken(HdesNode.Token value) { if (this.token == value) return this; HdesNode.Token newValue = Objects.requireNonNull(value, "token"); return new ImmutableHitPolicyMapping(newValue, this.defFrom, this.defTo, this.when, this.mapsTo); } /** * Copy the current immutable object by setting a value for the {@link DecisionTableNode.HitPolicyMapping#getDefFrom() defFrom} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for defFrom * @return A modified copy of the {@code this} object */ public final ImmutableHitPolicyMapping withDefFrom(BodyNode.ScalarType value) { if (this.defFrom == value) return this; BodyNode.ScalarType newValue = Objects.requireNonNull(value, "defFrom"); if (this.defFrom.equals(newValue)) return this; return new ImmutableHitPolicyMapping(this.token, newValue, this.defTo, this.when, this.mapsTo); } /** * Copy the current immutable object by setting a value for the {@link DecisionTableNode.HitPolicyMapping#getDefTo() defTo} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for defTo * @return A modified copy of the {@code this} object */ public final ImmutableHitPolicyMapping withDefTo(BodyNode.ScalarType value) { if (this.defTo == value) return this; BodyNode.ScalarType newValue = Objects.requireNonNull(value, "defTo"); if (this.defTo.equals(newValue)) return this; return new ImmutableHitPolicyMapping(this.token, this.defFrom, newValue, this.when, this.mapsTo); } /** * Copy the current immutable object by setting a value for the {@link DecisionTableNode.HitPolicyMapping#getWhen() when} 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 when * @return A modified copy of the {@code this} object */ public final ImmutableHitPolicyMapping withWhen(DecisionTableNode.WhenRuleRow value) { if (this.when == value) return this; DecisionTableNode.WhenRuleRow newValue = Objects.requireNonNull(value, "when"); return new ImmutableHitPolicyMapping(this.token, this.defFrom, this.defTo, newValue, this.mapsTo); } /** * Copy the current immutable object with elements that replace the content of {@link DecisionTableNode.HitPolicyMapping#getMapsTo() mapsTo}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableHitPolicyMapping withMapsTo(DecisionTableNode.MappingRow... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return new ImmutableHitPolicyMapping(this.token, this.defFrom, this.defTo, this.when, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link DecisionTableNode.HitPolicyMapping#getMapsTo() mapsTo}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of mapsTo elements to set * @return A modified copy of {@code this} object */ public final ImmutableHitPolicyMapping withMapsTo(Iterable elements) { if (this.mapsTo == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return new ImmutableHitPolicyMapping(this.token, this.defFrom, this.defTo, this.when, newValue); } /** * This instance is equal to all instances of {@code ImmutableHitPolicyMapping} 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 ImmutableHitPolicyMapping && equalTo((ImmutableHitPolicyMapping) another); } private boolean equalTo(ImmutableHitPolicyMapping another) { return token.equals(another.token) && defFrom.equals(another.defFrom) && defTo.equals(another.defTo) && when.equals(another.when) && mapsTo.equals(another.mapsTo); } /** * Computes a hash code from attributes: {@code token}, {@code defFrom}, {@code defTo}, {@code when}, {@code mapsTo}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + token.hashCode(); h += (h << 5) + defFrom.hashCode(); h += (h << 5) + defTo.hashCode(); h += (h << 5) + when.hashCode(); h += (h << 5) + mapsTo.hashCode(); return h; } /** * Prints the immutable value {@code HitPolicyMapping} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "HitPolicyMapping{" + "token=" + token + ", defFrom=" + defFrom + ", defTo=" + defTo + ", when=" + when + ", mapsTo=" + mapsTo + "}"; } /** * Creates an immutable copy of a {@link DecisionTableNode.HitPolicyMapping} 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 HitPolicyMapping instance */ public static ImmutableHitPolicyMapping copyOf(DecisionTableNode.HitPolicyMapping instance) { if (instance instanceof ImmutableHitPolicyMapping) { return (ImmutableHitPolicyMapping) instance; } return ImmutableHitPolicyMapping.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableHitPolicyMapping ImmutableHitPolicyMapping}. *

   * ImmutableHitPolicyMapping.builder()
   *    .token(io.resys.hdes.ast.api.nodes.HdesNode.Token) // required {@link DecisionTableNode.HitPolicyMapping#getToken() token}
   *    .defFrom(io.resys.hdes.ast.api.nodes.BodyNode.ScalarType) // required {@link DecisionTableNode.HitPolicyMapping#getDefFrom() defFrom}
   *    .defTo(io.resys.hdes.ast.api.nodes.BodyNode.ScalarType) // required {@link DecisionTableNode.HitPolicyMapping#getDefTo() defTo}
   *    .when(io.resys.hdes.ast.api.nodes.DecisionTableNode.WhenRuleRow) // required {@link DecisionTableNode.HitPolicyMapping#getWhen() when}
   *    .addMapsTo|addAllMapsTo(io.resys.hdes.ast.api.nodes.DecisionTableNode.MappingRow) // {@link DecisionTableNode.HitPolicyMapping#getMapsTo() mapsTo} elements
   *    .build();
   * 
* @return A new ImmutableHitPolicyMapping builder */ public static ImmutableHitPolicyMapping.Builder builder() { return new ImmutableHitPolicyMapping.Builder(); } /** * Builds instances of type {@link ImmutableHitPolicyMapping ImmutableHitPolicyMapping}. * 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.HitPolicyMapping", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_TOKEN = 0x1L; private static final long INIT_BIT_DEF_FROM = 0x2L; private static final long INIT_BIT_DEF_TO = 0x4L; private static final long INIT_BIT_WHEN = 0x8L; private long initBits = 0xfL; private @Nullable HdesNode.Token token; private @Nullable BodyNode.ScalarType defFrom; private @Nullable BodyNode.ScalarType defTo; private @Nullable DecisionTableNode.WhenRuleRow when; private List mapsTo = 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.HitPolicyMapping} 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.HitPolicyMapping 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.HitPolicyMapping) { DecisionTableNode.HitPolicyMapping instance = (DecisionTableNode.HitPolicyMapping) object; defTo(instance.getDefTo()); defFrom(instance.getDefFrom()); addAllMapsTo(instance.getMapsTo()); when(instance.getWhen()); } } /** * Initializes the value for the {@link DecisionTableNode.HitPolicyMapping#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; } /** * Initializes the value for the {@link DecisionTableNode.HitPolicyMapping#getDefFrom() defFrom} attribute. * @param defFrom The value for defFrom * @return {@code this} builder for use in a chained invocation */ public final Builder defFrom(BodyNode.ScalarType defFrom) { this.defFrom = Objects.requireNonNull(defFrom, "defFrom"); initBits &= ~INIT_BIT_DEF_FROM; return this; } /** * Initializes the value for the {@link DecisionTableNode.HitPolicyMapping#getDefTo() defTo} attribute. * @param defTo The value for defTo * @return {@code this} builder for use in a chained invocation */ public final Builder defTo(BodyNode.ScalarType defTo) { this.defTo = Objects.requireNonNull(defTo, "defTo"); initBits &= ~INIT_BIT_DEF_TO; return this; } /** * Initializes the value for the {@link DecisionTableNode.HitPolicyMapping#getWhen() when} attribute. * @param when The value for when * @return {@code this} builder for use in a chained invocation */ public final Builder when(DecisionTableNode.WhenRuleRow when) { this.when = Objects.requireNonNull(when, "when"); initBits &= ~INIT_BIT_WHEN; return this; } /** * Adds one element to {@link DecisionTableNode.HitPolicyMapping#getMapsTo() mapsTo} list. * @param element A mapsTo element * @return {@code this} builder for use in a chained invocation */ public final Builder addMapsTo(DecisionTableNode.MappingRow element) { this.mapsTo.add(Objects.requireNonNull(element, "mapsTo element")); return this; } /** * Adds elements to {@link DecisionTableNode.HitPolicyMapping#getMapsTo() mapsTo} list. * @param elements An array of mapsTo elements * @return {@code this} builder for use in a chained invocation */ public final Builder addMapsTo(DecisionTableNode.MappingRow... elements) { for (DecisionTableNode.MappingRow element : elements) { this.mapsTo.add(Objects.requireNonNull(element, "mapsTo element")); } return this; } /** * Sets or replaces all elements for {@link DecisionTableNode.HitPolicyMapping#getMapsTo() mapsTo} list. * @param elements An iterable of mapsTo elements * @return {@code this} builder for use in a chained invocation */ public final Builder mapsTo(Iterable elements) { this.mapsTo.clear(); return addAllMapsTo(elements); } /** * Adds elements to {@link DecisionTableNode.HitPolicyMapping#getMapsTo() mapsTo} list. * @param elements An iterable of mapsTo elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllMapsTo(Iterable elements) { for (DecisionTableNode.MappingRow element : elements) { this.mapsTo.add(Objects.requireNonNull(element, "mapsTo element")); } return this; } /** * Builds a new {@link ImmutableHitPolicyMapping ImmutableHitPolicyMapping}. * @return An immutable instance of HitPolicyMapping * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableHitPolicyMapping build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableHitPolicyMapping(token, defFrom, defTo, when, createUnmodifiableList(true, mapsTo)); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_TOKEN) != 0) attributes.add("token"); if ((initBits & INIT_BIT_DEF_FROM) != 0) attributes.add("defFrom"); if ((initBits & INIT_BIT_DEF_TO) != 0) attributes.add("defTo"); if ((initBits & INIT_BIT_WHEN) != 0) attributes.add("when"); return "Cannot build HitPolicyMapping, 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