io.resys.hdes.ast.api.nodes.ImmutableMultiplicativeExpression Maven / Gradle / Ivy
package io.resys.hdes.ast.api.nodes;
import java.util.ArrayList;
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 ExpressionNode.MultiplicativeExpression}.
*
* Use the builder to create immutable instances:
* {@code ImmutableMultiplicativeExpression.builder()}.
*/
@Generated(from = "ExpressionNode.MultiplicativeExpression", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class ImmutableMultiplicativeExpression
implements ExpressionNode.MultiplicativeExpression {
private final HdesNode.Token token;
private final ExpressionNode.MultiplicativeType type;
private final HdesNode left;
private final HdesNode right;
private ImmutableMultiplicativeExpression(
HdesNode.Token token,
ExpressionNode.MultiplicativeType type,
HdesNode left,
HdesNode right) {
this.token = token;
this.type = type;
this.left = left;
this.right = right;
}
/**
* @return The value of the {@code token} attribute
*/
@Override
public HdesNode.Token getToken() {
return token;
}
/**
* @return The value of the {@code type} attribute
*/
@Override
public ExpressionNode.MultiplicativeType getType() {
return type;
}
/**
* @return The value of the {@code left} attribute
*/
@Override
public HdesNode getLeft() {
return left;
}
/**
* @return The value of the {@code right} attribute
*/
@Override
public HdesNode getRight() {
return right;
}
/**
* Copy the current immutable object by setting a value for the {@link ExpressionNode.MultiplicativeExpression#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 ImmutableMultiplicativeExpression withToken(HdesNode.Token value) {
if (this.token == value) return this;
HdesNode.Token newValue = Objects.requireNonNull(value, "token");
return new ImmutableMultiplicativeExpression(newValue, this.type, this.left, this.right);
}
/**
* Copy the current immutable object by setting a value for the {@link ExpressionNode.MultiplicativeExpression#getType() type} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for type
* @return A modified copy of the {@code this} object
*/
public final ImmutableMultiplicativeExpression withType(ExpressionNode.MultiplicativeType value) {
if (this.type == value) return this;
ExpressionNode.MultiplicativeType newValue = Objects.requireNonNull(value, "type");
if (this.type.equals(newValue)) return this;
return new ImmutableMultiplicativeExpression(this.token, newValue, this.left, this.right);
}
/**
* Copy the current immutable object by setting a value for the {@link ExpressionNode.MultiplicativeExpression#getLeft() left} 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 left
* @return A modified copy of the {@code this} object
*/
public final ImmutableMultiplicativeExpression withLeft(HdesNode value) {
if (this.left == value) return this;
HdesNode newValue = Objects.requireNonNull(value, "left");
return new ImmutableMultiplicativeExpression(this.token, this.type, newValue, this.right);
}
/**
* Copy the current immutable object by setting a value for the {@link ExpressionNode.MultiplicativeExpression#getRight() right} 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 right
* @return A modified copy of the {@code this} object
*/
public final ImmutableMultiplicativeExpression withRight(HdesNode value) {
if (this.right == value) return this;
HdesNode newValue = Objects.requireNonNull(value, "right");
return new ImmutableMultiplicativeExpression(this.token, this.type, this.left, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableMultiplicativeExpression} 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 ImmutableMultiplicativeExpression
&& equalTo((ImmutableMultiplicativeExpression) another);
}
private boolean equalTo(ImmutableMultiplicativeExpression another) {
return token.equals(another.token)
&& type.equals(another.type)
&& left.equals(another.left)
&& right.equals(another.right);
}
/**
* Computes a hash code from attributes: {@code token}, {@code type}, {@code left}, {@code right}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + token.hashCode();
h += (h << 5) + type.hashCode();
h += (h << 5) + left.hashCode();
h += (h << 5) + right.hashCode();
return h;
}
/**
* Prints the immutable value {@code MultiplicativeExpression} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "MultiplicativeExpression{"
+ "token=" + token
+ ", type=" + type
+ ", left=" + left
+ ", right=" + right
+ "}";
}
/**
* Creates an immutable copy of a {@link ExpressionNode.MultiplicativeExpression} 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 MultiplicativeExpression instance
*/
public static ImmutableMultiplicativeExpression copyOf(ExpressionNode.MultiplicativeExpression instance) {
if (instance instanceof ImmutableMultiplicativeExpression) {
return (ImmutableMultiplicativeExpression) instance;
}
return ImmutableMultiplicativeExpression.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableMultiplicativeExpression ImmutableMultiplicativeExpression}.
*
* ImmutableMultiplicativeExpression.builder()
* .token(io.resys.hdes.ast.api.nodes.HdesNode.Token) // required {@link ExpressionNode.MultiplicativeExpression#getToken() token}
* .type(io.resys.hdes.ast.api.nodes.ExpressionNode.MultiplicativeType) // required {@link ExpressionNode.MultiplicativeExpression#getType() type}
* .left(io.resys.hdes.ast.api.nodes.HdesNode) // required {@link ExpressionNode.MultiplicativeExpression#getLeft() left}
* .right(io.resys.hdes.ast.api.nodes.HdesNode) // required {@link ExpressionNode.MultiplicativeExpression#getRight() right}
* .build();
*
* @return A new ImmutableMultiplicativeExpression builder
*/
public static ImmutableMultiplicativeExpression.Builder builder() {
return new ImmutableMultiplicativeExpression.Builder();
}
/**
* Builds instances of type {@link ImmutableMultiplicativeExpression ImmutableMultiplicativeExpression}.
* 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 = "ExpressionNode.MultiplicativeExpression", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_TOKEN = 0x1L;
private static final long INIT_BIT_TYPE = 0x2L;
private static final long INIT_BIT_LEFT = 0x4L;
private static final long INIT_BIT_RIGHT = 0x8L;
private long initBits = 0xfL;
private @Nullable HdesNode.Token token;
private @Nullable ExpressionNode.MultiplicativeType type;
private @Nullable HdesNode left;
private @Nullable HdesNode right;
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.ExpressionNode.MultiplicativeExpression} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(ExpressionNode.MultiplicativeExpression 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 ExpressionNode.MultiplicativeExpression) {
ExpressionNode.MultiplicativeExpression instance = (ExpressionNode.MultiplicativeExpression) object;
type(instance.getType());
left(instance.getLeft());
right(instance.getRight());
}
}
/**
* Initializes the value for the {@link ExpressionNode.MultiplicativeExpression#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 ExpressionNode.MultiplicativeExpression#getType() type} attribute.
* @param type The value for type
* @return {@code this} builder for use in a chained invocation
*/
public final Builder type(ExpressionNode.MultiplicativeType type) {
this.type = Objects.requireNonNull(type, "type");
initBits &= ~INIT_BIT_TYPE;
return this;
}
/**
* Initializes the value for the {@link ExpressionNode.MultiplicativeExpression#getLeft() left} attribute.
* @param left The value for left
* @return {@code this} builder for use in a chained invocation
*/
public final Builder left(HdesNode left) {
this.left = Objects.requireNonNull(left, "left");
initBits &= ~INIT_BIT_LEFT;
return this;
}
/**
* Initializes the value for the {@link ExpressionNode.MultiplicativeExpression#getRight() right} attribute.
* @param right The value for right
* @return {@code this} builder for use in a chained invocation
*/
public final Builder right(HdesNode right) {
this.right = Objects.requireNonNull(right, "right");
initBits &= ~INIT_BIT_RIGHT;
return this;
}
/**
* Builds a new {@link ImmutableMultiplicativeExpression ImmutableMultiplicativeExpression}.
* @return An immutable instance of MultiplicativeExpression
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableMultiplicativeExpression build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableMultiplicativeExpression(token, type, left, right);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_TOKEN) != 0) attributes.add("token");
if ((initBits & INIT_BIT_TYPE) != 0) attributes.add("type");
if ((initBits & INIT_BIT_LEFT) != 0) attributes.add("left");
if ((initBits & INIT_BIT_RIGHT) != 0) attributes.add("right");
return "Cannot build MultiplicativeExpression, some of required attributes are not set " + attributes;
}
}
}