io.resys.wrench.assets.flow.api.model.ImmutableFlowAst Maven / Gradle / Ivy
package io.resys.wrench.assets.flow.api.model;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import io.resys.wrench.assets.datatype.api.AstType;
import io.resys.wrench.assets.flow.api.FlowAstFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
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 FlowAst}.
*
* Use the builder to create immutable instances:
* {@code ImmutableFlowAst.builder()}.
*/
@Generated(from = "FlowAst", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableFlowAst implements FlowAst {
private final String name;
private final int rev;
private final @Nullable String description;
private final FlowAstFactory.Node src;
private final ImmutableList commands;
private final ImmutableList messages;
private final ImmutableList autocomplete;
private ImmutableFlowAst(
String name,
int rev,
@Nullable String description,
FlowAstFactory.Node src,
ImmutableList commands,
ImmutableList messages,
ImmutableList autocomplete) {
this.name = name;
this.rev = rev;
this.description = description;
this.src = src;
this.commands = commands;
this.messages = messages;
this.autocomplete = autocomplete;
}
/**
* @return The value of the {@code name} attribute
*/
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code rev} attribute
*/
@Override
public int getRev() {
return rev;
}
/**
* @return The value of the {@code description} attribute
*/
@Override
public @Nullable String getDescription() {
return description;
}
/**
* @return The value of the {@code src} attribute
*/
@Override
public FlowAstFactory.Node getSrc() {
return src;
}
/**
* @return The value of the {@code commands} attribute
*/
@Override
public ImmutableList getCommands() {
return commands;
}
/**
* @return The value of the {@code messages} attribute
*/
@Override
public ImmutableList getMessages() {
return messages;
}
/**
* @return The value of the {@code autocomplete} attribute
*/
@Override
public ImmutableList getAutocomplete() {
return autocomplete;
}
/**
* Copy the current immutable object by setting a value for the {@link FlowAst#getName() name} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for name
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowAst withName(String value) {
String newValue = Objects.requireNonNull(value, "name");
if (this.name.equals(newValue)) return this;
return new ImmutableFlowAst(newValue, this.rev, this.description, this.src, this.commands, this.messages, this.autocomplete);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowAst#getRev() rev} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for rev
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowAst withRev(int value) {
if (this.rev == value) return this;
return new ImmutableFlowAst(this.name, value, this.description, this.src, this.commands, this.messages, this.autocomplete);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowAst#getDescription() description} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for description (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowAst withDescription(@Nullable String value) {
if (Objects.equals(this.description, value)) return this;
return new ImmutableFlowAst(this.name, this.rev, value, this.src, this.commands, this.messages, this.autocomplete);
}
/**
* Copy the current immutable object by setting a value for the {@link FlowAst#getSrc() src} 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 src
* @return A modified copy of the {@code this} object
*/
public final ImmutableFlowAst withSrc(FlowAstFactory.Node value) {
if (this.src == value) return this;
FlowAstFactory.Node newValue = Objects.requireNonNull(value, "src");
return new ImmutableFlowAst(
this.name,
this.rev,
this.description,
newValue,
this.commands,
this.messages,
this.autocomplete);
}
/**
* Copy the current immutable object with elements that replace the content of {@link FlowAst#getCommands() commands}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableFlowAst withCommands(FlowAst.FlowCommand... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableFlowAst(this.name, this.rev, this.description, this.src, newValue, this.messages, this.autocomplete);
}
/**
* Copy the current immutable object with elements that replace the content of {@link FlowAst#getCommands() commands}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of commands elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableFlowAst withCommands(Iterable extends FlowAst.FlowCommand> elements) {
if (this.commands == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableFlowAst(this.name, this.rev, this.description, this.src, newValue, this.messages, this.autocomplete);
}
/**
* Copy the current immutable object with elements that replace the content of {@link FlowAst#getMessages() messages}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableFlowAst withMessages(FlowAst.FlowCommandMessage... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableFlowAst(this.name, this.rev, this.description, this.src, this.commands, newValue, this.autocomplete);
}
/**
* Copy the current immutable object with elements that replace the content of {@link FlowAst#getMessages() messages}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of messages elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableFlowAst withMessages(Iterable extends FlowAst.FlowCommandMessage> elements) {
if (this.messages == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableFlowAst(this.name, this.rev, this.description, this.src, this.commands, newValue, this.autocomplete);
}
/**
* Copy the current immutable object with elements that replace the content of {@link FlowAst#getAutocomplete() autocomplete}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableFlowAst withAutocomplete(FlowAst.FlowAutocomplete... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableFlowAst(this.name, this.rev, this.description, this.src, this.commands, this.messages, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link FlowAst#getAutocomplete() autocomplete}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of autocomplete elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableFlowAst withAutocomplete(Iterable extends FlowAst.FlowAutocomplete> elements) {
if (this.autocomplete == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableFlowAst(this.name, this.rev, this.description, this.src, this.commands, this.messages, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableFlowAst} 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 ImmutableFlowAst
&& equalTo((ImmutableFlowAst) another);
}
private boolean equalTo(ImmutableFlowAst another) {
return name.equals(another.name)
&& rev == another.rev
&& Objects.equals(description, another.description)
&& src.equals(another.src)
&& commands.equals(another.commands)
&& messages.equals(another.messages)
&& autocomplete.equals(another.autocomplete);
}
/**
* Computes a hash code from attributes: {@code name}, {@code rev}, {@code description}, {@code src}, {@code commands}, {@code messages}, {@code autocomplete}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + name.hashCode();
h += (h << 5) + rev;
h += (h << 5) + Objects.hashCode(description);
h += (h << 5) + src.hashCode();
h += (h << 5) + commands.hashCode();
h += (h << 5) + messages.hashCode();
h += (h << 5) + autocomplete.hashCode();
return h;
}
/**
* Prints the immutable value {@code FlowAst} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("FlowAst")
.omitNullValues()
.add("name", name)
.add("rev", rev)
.add("description", description)
.add("src", src)
.add("commands", commands)
.add("messages", messages)
.add("autocomplete", autocomplete)
.toString();
}
/**
* Creates an immutable copy of a {@link FlowAst} 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 FlowAst instance
*/
public static ImmutableFlowAst copyOf(FlowAst instance) {
if (instance instanceof ImmutableFlowAst) {
return (ImmutableFlowAst) instance;
}
return ImmutableFlowAst.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableFlowAst ImmutableFlowAst}.
*
* ImmutableFlowAst.builder()
* .name(String) // required {@link FlowAst#getName() name}
* .rev(int) // required {@link FlowAst#getRev() rev}
* .description(String | null) // nullable {@link FlowAst#getDescription() description}
* .src(io.resys.wrench.assets.flow.api.FlowAstFactory.Node) // required {@link FlowAst#getSrc() src}
* .addCommands|addAllCommands(io.resys.wrench.assets.flow.api.model.FlowAst.FlowCommand) // {@link FlowAst#getCommands() commands} elements
* .addMessages|addAllMessages(io.resys.wrench.assets.flow.api.model.FlowAst.FlowCommandMessage) // {@link FlowAst#getMessages() messages} elements
* .addAutocomplete|addAllAutocomplete(io.resys.wrench.assets.flow.api.model.FlowAst.FlowAutocomplete) // {@link FlowAst#getAutocomplete() autocomplete} elements
* .build();
*
* @return A new ImmutableFlowAst builder
*/
public static ImmutableFlowAst.Builder builder() {
return new ImmutableFlowAst.Builder();
}
/**
* Builds instances of type {@link ImmutableFlowAst ImmutableFlowAst}.
* 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 = "FlowAst", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private static final long INIT_BIT_REV = 0x2L;
private static final long INIT_BIT_SRC = 0x4L;
private long initBits = 0x7L;
private @Nullable String name;
private int rev;
private @Nullable String description;
private @Nullable FlowAstFactory.Node src;
private ImmutableList.Builder commands = ImmutableList.builder();
private ImmutableList.Builder messages = ImmutableList.builder();
private ImmutableList.Builder autocomplete = ImmutableList.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code io.resys.wrench.assets.flow.api.model.FlowAst} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(FlowAst instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code io.resys.wrench.assets.datatype.api.AstType} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(AstType instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof FlowAst) {
FlowAst instance = (FlowAst) object;
addAllMessages(instance.getMessages());
src(instance.getSrc());
addAllAutocomplete(instance.getAutocomplete());
addAllCommands(instance.getCommands());
}
if (object instanceof AstType) {
AstType instance = (AstType) object;
name(instance.getName());
@Nullable String descriptionValue = instance.getDescription();
if (descriptionValue != null) {
description(descriptionValue);
}
rev(instance.getRev());
}
}
/**
* Initializes the value for the {@link FlowAst#getName() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes the value for the {@link FlowAst#getRev() rev} attribute.
* @param rev The value for rev
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder rev(int rev) {
this.rev = rev;
initBits &= ~INIT_BIT_REV;
return this;
}
/**
* Initializes the value for the {@link FlowAst#getDescription() description} attribute.
* @param description The value for description (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder description(@Nullable String description) {
this.description = description;
return this;
}
/**
* Initializes the value for the {@link FlowAst#getSrc() src} attribute.
* @param src The value for src
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder src(FlowAstFactory.Node src) {
this.src = Objects.requireNonNull(src, "src");
initBits &= ~INIT_BIT_SRC;
return this;
}
/**
* Adds one element to {@link FlowAst#getCommands() commands} list.
* @param element A commands element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addCommands(FlowAst.FlowCommand element) {
this.commands.add(element);
return this;
}
/**
* Adds elements to {@link FlowAst#getCommands() commands} list.
* @param elements An array of commands elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addCommands(FlowAst.FlowCommand... elements) {
this.commands.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link FlowAst#getCommands() commands} list.
* @param elements An iterable of commands elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder commands(Iterable extends FlowAst.FlowCommand> elements) {
this.commands = ImmutableList.builder();
return addAllCommands(elements);
}
/**
* Adds elements to {@link FlowAst#getCommands() commands} list.
* @param elements An iterable of commands elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllCommands(Iterable extends FlowAst.FlowCommand> elements) {
this.commands.addAll(elements);
return this;
}
/**
* Adds one element to {@link FlowAst#getMessages() messages} list.
* @param element A messages element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addMessages(FlowAst.FlowCommandMessage element) {
this.messages.add(element);
return this;
}
/**
* Adds elements to {@link FlowAst#getMessages() messages} list.
* @param elements An array of messages elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addMessages(FlowAst.FlowCommandMessage... elements) {
this.messages.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link FlowAst#getMessages() messages} list.
* @param elements An iterable of messages elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder messages(Iterable extends FlowAst.FlowCommandMessage> elements) {
this.messages = ImmutableList.builder();
return addAllMessages(elements);
}
/**
* Adds elements to {@link FlowAst#getMessages() messages} list.
* @param elements An iterable of messages elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllMessages(Iterable extends FlowAst.FlowCommandMessage> elements) {
this.messages.addAll(elements);
return this;
}
/**
* Adds one element to {@link FlowAst#getAutocomplete() autocomplete} list.
* @param element A autocomplete element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAutocomplete(FlowAst.FlowAutocomplete element) {
this.autocomplete.add(element);
return this;
}
/**
* Adds elements to {@link FlowAst#getAutocomplete() autocomplete} list.
* @param elements An array of autocomplete elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAutocomplete(FlowAst.FlowAutocomplete... elements) {
this.autocomplete.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link FlowAst#getAutocomplete() autocomplete} list.
* @param elements An iterable of autocomplete elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder autocomplete(Iterable extends FlowAst.FlowAutocomplete> elements) {
this.autocomplete = ImmutableList.builder();
return addAllAutocomplete(elements);
}
/**
* Adds elements to {@link FlowAst#getAutocomplete() autocomplete} list.
* @param elements An iterable of autocomplete elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllAutocomplete(Iterable extends FlowAst.FlowAutocomplete> elements) {
this.autocomplete.addAll(elements);
return this;
}
/**
* Builds a new {@link ImmutableFlowAst ImmutableFlowAst}.
* @return An immutable instance of FlowAst
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableFlowAst build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableFlowAst(name, rev, description, src, commands.build(), messages.build(), autocomplete.build());
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
if ((initBits & INIT_BIT_REV) != 0) attributes.add("rev");
if ((initBits & INIT_BIT_SRC) != 0) attributes.add("src");
return "Cannot build FlowAst, some of required attributes are not set " + attributes;
}
}
}