io.resys.hdes.client.api.ast.ImmutableCommandsAndChanges Maven / Gradle / Ivy
package io.resys.hdes.client.api.ast;
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 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 AstChangeset.CommandsAndChanges}.
*
* Use the builder to create immutable instances:
* {@code ImmutableCommandsAndChanges.builder()}.
*/
@Generated(from = "AstChangeset.CommandsAndChanges", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableCommandsAndChanges
implements AstChangeset.CommandsAndChanges {
private final ImmutableList commands;
private final ImmutableList src;
private ImmutableCommandsAndChanges(
ImmutableList commands,
ImmutableList src) {
this.commands = commands;
this.src = src;
}
/**
* @return The value of the {@code commands} attribute
*/
@Override
public ImmutableList getCommands() {
return commands;
}
/**
* @return The value of the {@code src} attribute
*/
@Override
public ImmutableList getSrc() {
return src;
}
/**
* Copy the current immutable object with elements that replace the content of {@link AstChangeset.CommandsAndChanges#getCommands() commands}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableCommandsAndChanges withCommands(AstCommand... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableCommandsAndChanges(newValue, this.src);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AstChangeset.CommandsAndChanges#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 ImmutableCommandsAndChanges withCommands(Iterable extends AstCommand> elements) {
if (this.commands == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableCommandsAndChanges(newValue, this.src);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AstChangeset.CommandsAndChanges#getSrc() src}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableCommandsAndChanges withSrc(AstChangeset... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableCommandsAndChanges(this.commands, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link AstChangeset.CommandsAndChanges#getSrc() src}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of src elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableCommandsAndChanges withSrc(Iterable extends AstChangeset> elements) {
if (this.src == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableCommandsAndChanges(this.commands, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableCommandsAndChanges} 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 ImmutableCommandsAndChanges
&& equalTo((ImmutableCommandsAndChanges) another);
}
private boolean equalTo(ImmutableCommandsAndChanges another) {
return commands.equals(another.commands)
&& src.equals(another.src);
}
/**
* Computes a hash code from attributes: {@code commands}, {@code src}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + commands.hashCode();
h += (h << 5) + src.hashCode();
return h;
}
/**
* Prints the immutable value {@code CommandsAndChanges} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("CommandsAndChanges")
.omitNullValues()
.add("commands", commands)
.add("src", src)
.toString();
}
/**
* Creates an immutable copy of a {@link AstChangeset.CommandsAndChanges} 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 CommandsAndChanges instance
*/
public static ImmutableCommandsAndChanges copyOf(AstChangeset.CommandsAndChanges instance) {
if (instance instanceof ImmutableCommandsAndChanges) {
return (ImmutableCommandsAndChanges) instance;
}
return ImmutableCommandsAndChanges.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableCommandsAndChanges ImmutableCommandsAndChanges}.
*
* ImmutableCommandsAndChanges.builder()
* .addCommands|addAllCommands(io.resys.hdes.client.api.ast.AstCommand) // {@link AstChangeset.CommandsAndChanges#getCommands() commands} elements
* .addSrc|addAllSrc(io.resys.hdes.client.api.ast.AstChangeset) // {@link AstChangeset.CommandsAndChanges#getSrc() src} elements
* .build();
*
* @return A new ImmutableCommandsAndChanges builder
*/
public static ImmutableCommandsAndChanges.Builder builder() {
return new ImmutableCommandsAndChanges.Builder();
}
/**
* Builds instances of type {@link ImmutableCommandsAndChanges ImmutableCommandsAndChanges}.
* 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 = "AstChangeset.CommandsAndChanges", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private ImmutableList.Builder commands = ImmutableList.builder();
private ImmutableList.Builder src = ImmutableList.builder();
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code CommandsAndChanges} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(AstChangeset.CommandsAndChanges instance) {
Objects.requireNonNull(instance, "instance");
addAllCommands(instance.getCommands());
addAllSrc(instance.getSrc());
return this;
}
/**
* Adds one element to {@link AstChangeset.CommandsAndChanges#getCommands() commands} list.
* @param element A commands element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addCommands(AstCommand element) {
this.commands.add(element);
return this;
}
/**
* Adds elements to {@link AstChangeset.CommandsAndChanges#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(AstCommand... elements) {
this.commands.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link AstChangeset.CommandsAndChanges#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 AstCommand> elements) {
this.commands = ImmutableList.builder();
return addAllCommands(elements);
}
/**
* Adds elements to {@link AstChangeset.CommandsAndChanges#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 AstCommand> elements) {
this.commands.addAll(elements);
return this;
}
/**
* Adds one element to {@link AstChangeset.CommandsAndChanges#getSrc() src} list.
* @param element A src element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addSrc(AstChangeset element) {
this.src.add(element);
return this;
}
/**
* Adds elements to {@link AstChangeset.CommandsAndChanges#getSrc() src} list.
* @param elements An array of src elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addSrc(AstChangeset... elements) {
this.src.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link AstChangeset.CommandsAndChanges#getSrc() src} list.
* @param elements An iterable of src elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder src(Iterable extends AstChangeset> elements) {
this.src = ImmutableList.builder();
return addAllSrc(elements);
}
/**
* Adds elements to {@link AstChangeset.CommandsAndChanges#getSrc() src} list.
* @param elements An iterable of src elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllSrc(Iterable extends AstChangeset> elements) {
this.src.addAll(elements);
return this;
}
/**
* Builds a new {@link ImmutableCommandsAndChanges ImmutableCommandsAndChanges}.
* @return An immutable instance of CommandsAndChanges
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableCommandsAndChanges build() {
return new ImmutableCommandsAndChanges(commands.build(), src.build());
}
}
}