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