
io.resys.hdes.ast.api.nodes.ImmutableStep Maven / Gradle / Ivy
package io.resys.hdes.ast.api.nodes;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
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.Step}.
*
* Use the builder to create immutable instances:
* {@code ImmutableStep.builder()}.
*/
@Generated(from = "FlowNode.Step", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class ImmutableStep implements FlowNode.Step {
private final HdesNode.Token token;
private final InvocationNode.SimpleInvocation id;
private final FlowNode.StepAction action;
private final FlowNode.StepPointer pointer;
private final Boolean await;
private final @Nullable FlowNode.StepAs as;
private ImmutableStep(
HdesNode.Token token,
InvocationNode.SimpleInvocation id,
FlowNode.StepAction action,
FlowNode.StepPointer pointer,
Boolean await,
@Nullable FlowNode.StepAs as) {
this.token = token;
this.id = id;
this.action = action;
this.pointer = pointer;
this.await = await;
this.as = as;
}
/**
* @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 action} attribute
*/
@Override
public FlowNode.StepAction getAction() {
return action;
}
/**
* @return The value of the {@code pointer} attribute
*/
@Override
public FlowNode.StepPointer getPointer() {
return pointer;
}
/**
* @return The value of the {@code await} attribute
*/
@Override
public Boolean getAwait() {
return await;
}
/**
* @return The value of the {@code as} attribute
*/
@Override
public Optional getAs() {
return Optional.ofNullable(as);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowNode.Step#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 ImmutableStep withToken(HdesNode.Token value) {
if (this.token == value) return this;
HdesNode.Token newValue = Objects.requireNonNull(value, "token");
return new ImmutableStep(newValue, this.id, this.action, this.pointer, this.await, this.as);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowNode.Step#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 ImmutableStep withId(InvocationNode.SimpleInvocation value) {
if (this.id == value) return this;
InvocationNode.SimpleInvocation newValue = Objects.requireNonNull(value, "id");
return new ImmutableStep(this.token, newValue, this.action, this.pointer, this.await, this.as);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowNode.Step#getAction() action} 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 action
* @return A modified copy of the {@code this} object
*/
public final ImmutableStep withAction(FlowNode.StepAction value) {
if (this.action == value) return this;
FlowNode.StepAction newValue = Objects.requireNonNull(value, "action");
return new ImmutableStep(this.token, this.id, newValue, this.pointer, this.await, this.as);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowNode.Step#getPointer() pointer} 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 pointer
* @return A modified copy of the {@code this} object
*/
public final ImmutableStep withPointer(FlowNode.StepPointer value) {
if (this.pointer == value) return this;
FlowNode.StepPointer newValue = Objects.requireNonNull(value, "pointer");
return new ImmutableStep(this.token, this.id, this.action, newValue, this.await, this.as);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowNode.Step#getAwait() await} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for await
* @return A modified copy of the {@code this} object
*/
public final ImmutableStep withAwait(Boolean value) {
Boolean newValue = Objects.requireNonNull(value, "await");
if (this.await.equals(newValue)) return this;
return new ImmutableStep(this.token, this.id, this.action, this.pointer, newValue, this.as);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link FlowNode.Step#getAs() as} attribute.
* @param value The value for as
* @return A modified copy of {@code this} object
*/
public final ImmutableStep withAs(FlowNode.StepAs value) {
@Nullable FlowNode.StepAs newValue = Objects.requireNonNull(value, "as");
if (this.as == newValue) return this;
return new ImmutableStep(this.token, this.id, this.action, this.pointer, this.await, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link FlowNode.Step#getAs() as} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for as
* @return A modified copy of {@code this} object
*/
@SuppressWarnings("unchecked") // safe covariant cast
public final ImmutableStep withAs(Optional extends FlowNode.StepAs> optional) {
@Nullable FlowNode.StepAs value = optional.orElse(null);
if (this.as == value) return this;
return new ImmutableStep(this.token, this.id, this.action, this.pointer, this.await, value);
}
/**
* This instance is equal to all instances of {@code ImmutableStep} 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 ImmutableStep
&& equalTo((ImmutableStep) another);
}
private boolean equalTo(ImmutableStep another) {
return token.equals(another.token)
&& id.equals(another.id)
&& action.equals(another.action)
&& pointer.equals(another.pointer)
&& await.equals(another.await)
&& Objects.equals(as, another.as);
}
/**
* Computes a hash code from attributes: {@code token}, {@code id}, {@code action}, {@code pointer}, {@code await}, {@code as}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + token.hashCode();
h += (h << 5) + id.hashCode();
h += (h << 5) + action.hashCode();
h += (h << 5) + pointer.hashCode();
h += (h << 5) + await.hashCode();
h += (h << 5) + Objects.hashCode(as);
return h;
}
/**
* Prints the immutable value {@code Step} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder("Step{");
builder.append("token=").append(token);
builder.append(", ");
builder.append("id=").append(id);
builder.append(", ");
builder.append("action=").append(action);
builder.append(", ");
builder.append("pointer=").append(pointer);
builder.append(", ");
builder.append("await=").append(await);
if (as != null) {
builder.append(", ");
builder.append("as=").append(as);
}
return builder.append("}").toString();
}
/**
* Creates an immutable copy of a {@link FlowNode.Step} 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 Step instance
*/
public static ImmutableStep copyOf(FlowNode.Step instance) {
if (instance instanceof ImmutableStep) {
return (ImmutableStep) instance;
}
return ImmutableStep.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableStep ImmutableStep}.
*
* ImmutableStep.builder()
* .token(io.resys.hdes.ast.api.nodes.HdesNode.Token) // required {@link FlowNode.Step#getToken() token}
* .id(io.resys.hdes.ast.api.nodes.InvocationNode.SimpleInvocation) // required {@link FlowNode.Step#getId() id}
* .action(io.resys.hdes.ast.api.nodes.FlowNode.StepAction) // required {@link FlowNode.Step#getAction() action}
* .pointer(io.resys.hdes.ast.api.nodes.FlowNode.StepPointer) // required {@link FlowNode.Step#getPointer() pointer}
* .await(Boolean) // required {@link FlowNode.Step#getAwait() await}
* .as(io.resys.hdes.ast.api.nodes.FlowNode.StepAs) // optional {@link FlowNode.Step#getAs() as}
* .build();
*
* @return A new ImmutableStep builder
*/
public static ImmutableStep.Builder builder() {
return new ImmutableStep.Builder();
}
/**
* Builds instances of type {@link ImmutableStep ImmutableStep}.
* 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.Step", 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_ACTION = 0x4L;
private static final long INIT_BIT_POINTER = 0x8L;
private static final long INIT_BIT_AWAIT = 0x10L;
private long initBits = 0x1fL;
private @Nullable HdesNode.Token token;
private @Nullable InvocationNode.SimpleInvocation id;
private @Nullable FlowNode.StepAction action;
private @Nullable FlowNode.StepPointer pointer;
private @Nullable Boolean await;
private @Nullable FlowNode.StepAs as;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code io.resys.hdes.ast.api.nodes.FlowNode.Step} 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.Step 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;
}
private void from(Object object) {
if (object instanceof FlowNode.Step) {
FlowNode.Step instance = (FlowNode.Step) object;
await(instance.getAwait());
action(instance.getAction());
pointer(instance.getPointer());
Optional asOptional = instance.getAs();
if (asOptional.isPresent()) {
as(asOptional);
}
id(instance.getId());
}
if (object instanceof HdesNode) {
HdesNode instance = (HdesNode) object;
token(instance.getToken());
}
}
/**
* Initializes the value for the {@link FlowNode.Step#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.Step#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.Step#getAction() action} attribute.
* @param action The value for action
* @return {@code this} builder for use in a chained invocation
*/
public final Builder action(FlowNode.StepAction action) {
this.action = Objects.requireNonNull(action, "action");
initBits &= ~INIT_BIT_ACTION;
return this;
}
/**
* Initializes the value for the {@link FlowNode.Step#getPointer() pointer} attribute.
* @param pointer The value for pointer
* @return {@code this} builder for use in a chained invocation
*/
public final Builder pointer(FlowNode.StepPointer pointer) {
this.pointer = Objects.requireNonNull(pointer, "pointer");
initBits &= ~INIT_BIT_POINTER;
return this;
}
/**
* Initializes the value for the {@link FlowNode.Step#getAwait() await} attribute.
* @param await The value for await
* @return {@code this} builder for use in a chained invocation
*/
public final Builder await(Boolean await) {
this.await = Objects.requireNonNull(await, "await");
initBits &= ~INIT_BIT_AWAIT;
return this;
}
/**
* Initializes the optional value {@link FlowNode.Step#getAs() as} to as.
* @param as The value for as
* @return {@code this} builder for chained invocation
*/
public final Builder as(FlowNode.StepAs as) {
this.as = Objects.requireNonNull(as, "as");
return this;
}
/**
* Initializes the optional value {@link FlowNode.Step#getAs() as} to as.
* @param as The value for as
* @return {@code this} builder for use in a chained invocation
*/
public final Builder as(Optional extends FlowNode.StepAs> as) {
this.as = as.orElse(null);
return this;
}
/**
* Builds a new {@link ImmutableStep ImmutableStep}.
* @return An immutable instance of Step
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableStep build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableStep(token, id, action, pointer, await, as);
}
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_ACTION) != 0) attributes.add("action");
if ((initBits & INIT_BIT_POINTER) != 0) attributes.add("pointer");
if ((initBits & INIT_BIT_AWAIT) != 0) attributes.add("await");
return "Cannot build Step, some of required attributes are not set " + attributes;
}
}
}