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