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

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

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

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 ExpressionParserVisitor.RedundentLambdaExpression}.
 * 

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

   * ImmutableRedundentLambdaExpression.builder()
   *    .token(io.resys.hdes.ast.api.nodes.HdesNode.Token) // required {@link ExpressionParserVisitor.RedundentLambdaExpression#getToken() token}
   *    .addArgs|addAllArgs(io.resys.hdes.ast.api.nodes.InvocationNode.SimpleInvocation) // {@link ExpressionParserVisitor.RedundentLambdaExpression#getArgs() args} elements
   *    .body(io.resys.hdes.ast.api.nodes.HdesNode) // required {@link ExpressionParserVisitor.RedundentLambdaExpression#getBody() body}
   *    .build();
   * 
* @return A new ImmutableRedundentLambdaExpression builder */ public static ImmutableRedundentLambdaExpression.Builder builder() { return new ImmutableRedundentLambdaExpression.Builder(); } /** * Builds instances of type {@link ImmutableRedundentLambdaExpression ImmutableRedundentLambdaExpression}. * 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 = "ExpressionParserVisitor.RedundentLambdaExpression", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_TOKEN = 0x1L; private static final long INIT_BIT_BODY = 0x2L; private long initBits = 0x3L; private @Nullable HdesNode.Token token; private List args = new ArrayList(); private @Nullable HdesNode body; 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.spi.antlr.visitors.ExpressionParserVisitor.RedundentLambdaExpression} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ public final Builder from(ExpressionParserVisitor.RedundentLambdaExpression 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 ExpressionParserVisitor.RedundentLambdaExpression) { ExpressionParserVisitor.RedundentLambdaExpression instance = (ExpressionParserVisitor.RedundentLambdaExpression) object; addAllArgs(instance.getArgs()); body(instance.getBody()); } } /** * Initializes the value for the {@link ExpressionParserVisitor.RedundentLambdaExpression#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 ExpressionParserVisitor.RedundentLambdaExpression#getArgs() args} list. * @param element A args element * @return {@code this} builder for use in a chained invocation */ public final Builder addArgs(InvocationNode.SimpleInvocation element) { this.args.add(Objects.requireNonNull(element, "args element")); return this; } /** * Adds elements to {@link ExpressionParserVisitor.RedundentLambdaExpression#getArgs() args} list. * @param elements An array of args elements * @return {@code this} builder for use in a chained invocation */ public final Builder addArgs(InvocationNode.SimpleInvocation... elements) { for (InvocationNode.SimpleInvocation element : elements) { this.args.add(Objects.requireNonNull(element, "args element")); } return this; } /** * Sets or replaces all elements for {@link ExpressionParserVisitor.RedundentLambdaExpression#getArgs() args} list. * @param elements An iterable of args elements * @return {@code this} builder for use in a chained invocation */ public final Builder args(Iterable elements) { this.args.clear(); return addAllArgs(elements); } /** * Adds elements to {@link ExpressionParserVisitor.RedundentLambdaExpression#getArgs() args} list. * @param elements An iterable of args elements * @return {@code this} builder for use in a chained invocation */ public final Builder addAllArgs(Iterable elements) { for (InvocationNode.SimpleInvocation element : elements) { this.args.add(Objects.requireNonNull(element, "args element")); } return this; } /** * Initializes the value for the {@link ExpressionParserVisitor.RedundentLambdaExpression#getBody() body} attribute. * @param body The value for body * @return {@code this} builder for use in a chained invocation */ public final Builder body(HdesNode body) { this.body = Objects.requireNonNull(body, "body"); initBits &= ~INIT_BIT_BODY; return this; } /** * Builds a new {@link ImmutableRedundentLambdaExpression ImmutableRedundentLambdaExpression}. * @return An immutable instance of RedundentLambdaExpression * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableRedundentLambdaExpression build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableRedundentLambdaExpression(token, createUnmodifiableList(true, args), body); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_TOKEN) != 0) attributes.add("token"); if ((initBits & INIT_BIT_BODY) != 0) attributes.add("body"); return "Cannot build RedundentLambdaExpression, 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