io.resys.hdes.ast.spi.antlr.visitors.ImmutableRedundentIterateAction Maven / Gradle / Ivy
package io.resys.hdes.ast.spi.antlr.visitors;
import io.resys.hdes.ast.api.nodes.FlowNode;
import io.resys.hdes.ast.api.nodes.HdesNode;
import io.resys.hdes.ast.api.nodes.InvocationNode;
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 FlowParserVisitor.RedundentIterateAction}.
*
* Use the builder to create immutable instances:
* {@code ImmutableRedundentIterateAction.builder()}.
*/
@Generated(from = "FlowParserVisitor.RedundentIterateAction", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
final class ImmutableRedundentIterateAction
implements FlowParserVisitor.RedundentIterateAction {
private final HdesNode.Token token;
private final InvocationNode over;
private final List steps;
private ImmutableRedundentIterateAction(
HdesNode.Token token,
InvocationNode over,
List steps) {
this.token = token;
this.over = over;
this.steps = steps;
}
/**
* @return The value of the {@code token} attribute
*/
@Override
public HdesNode.Token getToken() {
return token;
}
/**
* @return The value of the {@code over} attribute
*/
@Override
public InvocationNode getOver() {
return over;
}
/**
* @return The value of the {@code steps} attribute
*/
@Override
public List getSteps() {
return steps;
}
/**
* Copy the current immutable object by setting a value for the {@link FlowParserVisitor.RedundentIterateAction#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 ImmutableRedundentIterateAction withToken(HdesNode.Token value) {
if (this.token == value) return this;
HdesNode.Token newValue = Objects.requireNonNull(value, "token");
return new ImmutableRedundentIterateAction(newValue, this.over, this.steps);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowParserVisitor.RedundentIterateAction#getOver() over} 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 over
* @return A modified copy of the {@code this} object
*/
public final ImmutableRedundentIterateAction withOver(InvocationNode value) {
if (this.over == value) return this;
InvocationNode newValue = Objects.requireNonNull(value, "over");
return new ImmutableRedundentIterateAction(this.token, newValue, this.steps);
}
/**
* Copy the current immutable object with elements that replace the content of {@link FlowParserVisitor.RedundentIterateAction#getSteps() steps}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableRedundentIterateAction withSteps(FlowNode.Step... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new ImmutableRedundentIterateAction(this.token, this.over, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link FlowParserVisitor.RedundentIterateAction#getSteps() steps}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of steps elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableRedundentIterateAction withSteps(Iterable extends FlowNode.Step> elements) {
if (this.steps == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return new ImmutableRedundentIterateAction(this.token, this.over, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableRedundentIterateAction} 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 ImmutableRedundentIterateAction
&& equalTo((ImmutableRedundentIterateAction) another);
}
private boolean equalTo(ImmutableRedundentIterateAction another) {
return token.equals(another.token)
&& over.equals(another.over)
&& steps.equals(another.steps);
}
/**
* Computes a hash code from attributes: {@code token}, {@code over}, {@code steps}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + token.hashCode();
h += (h << 5) + over.hashCode();
h += (h << 5) + steps.hashCode();
return h;
}
/**
* Prints the immutable value {@code RedundentIterateAction} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "RedundentIterateAction{"
+ "token=" + token
+ ", over=" + over
+ ", steps=" + steps
+ "}";
}
/**
* Creates an immutable copy of a {@link FlowParserVisitor.RedundentIterateAction} 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 RedundentIterateAction instance
*/
public static ImmutableRedundentIterateAction copyOf(FlowParserVisitor.RedundentIterateAction instance) {
if (instance instanceof ImmutableRedundentIterateAction) {
return (ImmutableRedundentIterateAction) instance;
}
return ImmutableRedundentIterateAction.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableRedundentIterateAction ImmutableRedundentIterateAction}.
*
* ImmutableRedundentIterateAction.builder()
* .token(io.resys.hdes.ast.api.nodes.HdesNode.Token) // required {@link FlowParserVisitor.RedundentIterateAction#getToken() token}
* .over(io.resys.hdes.ast.api.nodes.InvocationNode) // required {@link FlowParserVisitor.RedundentIterateAction#getOver() over}
* .addSteps|addAllSteps(io.resys.hdes.ast.api.nodes.FlowNode.Step) // {@link FlowParserVisitor.RedundentIterateAction#getSteps() steps} elements
* .build();
*
* @return A new ImmutableRedundentIterateAction builder
*/
public static ImmutableRedundentIterateAction.Builder builder() {
return new ImmutableRedundentIterateAction.Builder();
}
/**
* Builds instances of type {@link ImmutableRedundentIterateAction ImmutableRedundentIterateAction}.
* 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 = "FlowParserVisitor.RedundentIterateAction", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_TOKEN = 0x1L;
private static final long INIT_BIT_OVER = 0x2L;
private long initBits = 0x3L;
private @Nullable HdesNode.Token token;
private @Nullable InvocationNode over;
private List steps = new ArrayList();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code io.resys.hdes.ast.spi.antlr.visitors.FlowParserVisitor.RedundentIterateAction} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(FlowParserVisitor.RedundentIterateAction 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.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;
}
private void from(Object object) {
if (object instanceof FlowParserVisitor.RedundentIterateAction) {
FlowParserVisitor.RedundentIterateAction instance = (FlowParserVisitor.RedundentIterateAction) object;
over(instance.getOver());
addAllSteps(instance.getSteps());
}
if (object instanceof HdesNode) {
HdesNode instance = (HdesNode) object;
token(instance.getToken());
}
}
/**
* Initializes the value for the {@link FlowParserVisitor.RedundentIterateAction#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 FlowParserVisitor.RedundentIterateAction#getOver() over} attribute.
* @param over The value for over
* @return {@code this} builder for use in a chained invocation
*/
public final Builder over(InvocationNode over) {
this.over = Objects.requireNonNull(over, "over");
initBits &= ~INIT_BIT_OVER;
return this;
}
/**
* Adds one element to {@link FlowParserVisitor.RedundentIterateAction#getSteps() steps} list.
* @param element A steps element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addSteps(FlowNode.Step element) {
this.steps.add(Objects.requireNonNull(element, "steps element"));
return this;
}
/**
* Adds elements to {@link FlowParserVisitor.RedundentIterateAction#getSteps() steps} list.
* @param elements An array of steps elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addSteps(FlowNode.Step... elements) {
for (FlowNode.Step element : elements) {
this.steps.add(Objects.requireNonNull(element, "steps element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link FlowParserVisitor.RedundentIterateAction#getSteps() steps} list.
* @param elements An iterable of steps elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder steps(Iterable extends FlowNode.Step> elements) {
this.steps.clear();
return addAllSteps(elements);
}
/**
* Adds elements to {@link FlowParserVisitor.RedundentIterateAction#getSteps() steps} list.
* @param elements An iterable of steps elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllSteps(Iterable extends FlowNode.Step> elements) {
for (FlowNode.Step element : elements) {
this.steps.add(Objects.requireNonNull(element, "steps element"));
}
return this;
}
/**
* Builds a new {@link ImmutableRedundentIterateAction ImmutableRedundentIterateAction}.
* @return An immutable instance of RedundentIterateAction
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableRedundentIterateAction build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableRedundentIterateAction(token, over, createUnmodifiableList(true, steps));
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_TOKEN) != 0) attributes.add("token");
if ((initBits & INIT_BIT_OVER) != 0) attributes.add("over");
return "Cannot build RedundentIterateAction, some of required attributes are not set " + attributes;
}
}
private static List createSafeList(Iterable extends T> 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);
}
}
}
}