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