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

io.resys.hdes.ast.spi.antlr.visitors.ImmutableStepTree Maven / Gradle / Ivy

The newest version!
package io.resys.hdes.ast.spi.antlr.visitors;

import io.resys.hdes.ast.api.nodes.FlowNode;
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 java.util.Optional;
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 FlowStepParserVisitor.StepTree}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableStepTree.builder()}. */ @Generated(from = "FlowStepParserVisitor.StepTree", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable public final class ImmutableStepTree implements FlowStepParserVisitor.StepTree { private final @Nullable FlowNode.Step step; private final List unclaimed; private ImmutableStepTree( @Nullable FlowNode.Step step, List unclaimed) { this.step = step; this.unclaimed = unclaimed; } /** * @return The value of the {@code step} attribute */ @Override public Optional getStep() { return Optional.ofNullable(step); } /** * @return The value of the {@code unclaimed} attribute */ @Override public List getUnclaimed() { return unclaimed; } /** * Copy the current immutable object by setting a present value for the optional {@link FlowStepParserVisitor.StepTree#getStep() step} attribute. * @param value The value for step * @return A modified copy of {@code this} object */ public final ImmutableStepTree withStep(FlowNode.Step value) { @Nullable FlowNode.Step newValue = Objects.requireNonNull(value, "step"); if (this.step == newValue) return this; return new ImmutableStepTree(newValue, this.unclaimed); } /** * Copy the current immutable object by setting an optional value for the {@link FlowStepParserVisitor.StepTree#getStep() step} attribute. * A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}. * @param optional A value for step * @return A modified copy of {@code this} object */ @SuppressWarnings("unchecked") // safe covariant cast public final ImmutableStepTree withStep(Optional optional) { @Nullable FlowNode.Step value = optional.orElse(null); if (this.step == value) return this; return new ImmutableStepTree(value, this.unclaimed); } /** * Copy the current immutable object with elements that replace the content of {@link FlowStepParserVisitor.StepTree#getUnclaimed() unclaimed}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableStepTree withUnclaimed(FlowNode.Step... elements) { List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false)); return new ImmutableStepTree(this.step, newValue); } /** * Copy the current immutable object with elements that replace the content of {@link FlowStepParserVisitor.StepTree#getUnclaimed() unclaimed}. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param elements An iterable of unclaimed elements to set * @return A modified copy of {@code this} object */ public final ImmutableStepTree withUnclaimed(Iterable elements) { if (this.unclaimed == elements) return this; List newValue = createUnmodifiableList(false, createSafeList(elements, true, false)); return new ImmutableStepTree(this.step, newValue); } /** * This instance is equal to all instances of {@code ImmutableStepTree} 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 ImmutableStepTree && equalTo((ImmutableStepTree) another); } private boolean equalTo(ImmutableStepTree another) { return Objects.equals(step, another.step) && unclaimed.equals(another.unclaimed); } /** * Computes a hash code from attributes: {@code step}, {@code unclaimed}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Objects.hashCode(step); h += (h << 5) + unclaimed.hashCode(); return h; } /** * Prints the immutable value {@code StepTree} with attribute values. * @return A string representation of the value */ @Override public String toString() { StringBuilder builder = new StringBuilder("StepTree{"); if (step != null) { builder.append("step=").append(step); } if (builder.length() > 9) builder.append(", "); builder.append("unclaimed=").append(unclaimed); return builder.append("}").toString(); } /** * Creates an immutable copy of a {@link FlowStepParserVisitor.StepTree} 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 StepTree instance */ public static ImmutableStepTree copyOf(FlowStepParserVisitor.StepTree instance) { if (instance instanceof ImmutableStepTree) { return (ImmutableStepTree) instance; } return ImmutableStepTree.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableStepTree ImmutableStepTree}. *

   * ImmutableStepTree.builder()
   *    .step(io.resys.hdes.ast.api.nodes.FlowNode.Step) // optional {@link FlowStepParserVisitor.StepTree#getStep() step}
   *    .addUnclaimed|addAllUnclaimed(io.resys.hdes.ast.api.nodes.FlowNode.Step) // {@link FlowStepParserVisitor.StepTree#getUnclaimed() unclaimed} elements
   *    .build();
   * 
* @return A new ImmutableStepTree builder */ public static ImmutableStepTree.Builder builder() { return new ImmutableStepTree.Builder(); } /** * Builds instances of type {@link ImmutableStepTree ImmutableStepTree}. * 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 = "FlowStepParserVisitor.StepTree", generator = "Immutables") @NotThreadSafe public static final class Builder { private @Nullable FlowNode.Step step; private List unclaimed = new ArrayList(); private Builder() { } /** * Fill a builder with attribute values from the provided {@code StepTree} 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 */ public final Builder from(FlowStepParserVisitor.StepTree instance) { Objects.requireNonNull(instance, "instance"); Optional stepOptional = instance.getStep(); if (stepOptional.isPresent()) { step(stepOptional); } addAllUnclaimed(instance.getUnclaimed()); return this; } /** * Initializes the optional value {@link FlowStepParserVisitor.StepTree#getStep() step} to step. * @param step The value for step * @return {@code this} builder for chained invocation */ public final Builder step(FlowNode.Step step) { this.step = Objects.requireNonNull(step, "step"); return this; } /** * Initializes the optional value {@link FlowStepParserVisitor.StepTree#getStep() step} to step. * @param step The value for step * @return {@code this} builder for use in a chained invocation */ public final Builder step(Optional step) { this.step = step.orElse(null); return this; } /** * Adds one element to {@link FlowStepParserVisitor.StepTree#getUnclaimed() unclaimed} list. * @param element A unclaimed element * @return {@code this} builder for use in a chained invocation */ public final Builder addUnclaimed(FlowNode.Step element) { this.unclaimed.add(Objects.requireNonNull(element, "unclaimed element")); return this; } /** * Adds elements to {@link FlowStepParserVisitor.StepTree#getUnclaimed() unclaimed} list. * @param elements An array of unclaimed elements * @return {@code this} builder for use in a chained invocation */ public final Builder addUnclaimed(FlowNode.Step... elements) { for (FlowNode.Step element : elements) { this.unclaimed.add(Objects.requireNonNull(element, "unclaimed element")); } return this; } /** * Sets or replaces all elements for {@link FlowStepParserVisitor.StepTree#getUnclaimed() unclaimed} list. * @param elements An iterable of unclaimed elements * @return {@code this} builder for use in a chained invocation */ public final Builder unclaimed(Iterable elements) { this.unclaimed.clear(); return addAllUnclaimed(elements); } /** * Adds elements to {@link FlowStepParserVisitor.StepTree#getUnclaimed() unclaimed} list. * @param elements An iterable of unclaimed elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllUnclaimed(Iterable elements) { for (FlowNode.Step element : elements) { this.unclaimed.add(Objects.requireNonNull(element, "unclaimed element")); } return this; } /** * Builds a new {@link ImmutableStepTree ImmutableStepTree}. * @return An immutable instance of StepTree * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableStepTree build() { return new ImmutableStepTree(step, createUnmodifiableList(true, unclaimed)); } } 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