io.resys.hdes.ast.spi.antlr.visitors.ImmutableRedundentAccepts Maven / Gradle / Ivy
package io.resys.hdes.ast.spi.antlr.visitors;
import io.resys.hdes.ast.api.nodes.BodyNode;
import io.resys.hdes.ast.api.nodes.HdesNode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
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 HdesParserVisitor.RedundentAccepts}.
*
* Use the builder to create immutable instances:
* {@code ImmutableRedundentAccepts.builder()}.
*/
@Generated(from = "HdesParserVisitor.RedundentAccepts", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
public final class ImmutableRedundentAccepts
implements HdesParserVisitor.RedundentAccepts {
private final HdesNode.Token token;
private final List values;
private ImmutableRedundentAccepts(
HdesNode.Token token,
List values) {
this.token = token;
this.values = values;
}
/**
* @return The value of the {@code token} attribute
*/
@Override
public HdesNode.Token getToken() {
return token;
}
/**
* @return The value of the {@code values} attribute
*/
@Override
public List getValues() {
return values;
}
/**
* Copy the current immutable object by setting a value for the {@link HdesParserVisitor.RedundentAccepts#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 ImmutableRedundentAccepts withToken(HdesNode.Token value) {
if (this.token == value) return this;
HdesNode.Token newValue = Objects.requireNonNull(value, "token");
return new ImmutableRedundentAccepts(newValue, this.values);
}
/**
* Copy the current immutable object with elements that replace the content of {@link HdesParserVisitor.RedundentAccepts#getValues() values}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableRedundentAccepts withValues(BodyNode.TypeDef... elements) {
List newValue = createUnmodifiableList(false, createSafeList(Arrays.asList(elements), true, false));
return new ImmutableRedundentAccepts(this.token, newValue);
}
/**
* Copy the current immutable object with elements that replace the content of {@link HdesParserVisitor.RedundentAccepts#getValues() values}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of values elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableRedundentAccepts withValues(Iterable extends BodyNode.TypeDef> elements) {
if (this.values == elements) return this;
List newValue = createUnmodifiableList(false, createSafeList(elements, true, false));
return new ImmutableRedundentAccepts(this.token, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableRedundentAccepts} 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 ImmutableRedundentAccepts
&& equalTo((ImmutableRedundentAccepts) another);
}
private boolean equalTo(ImmutableRedundentAccepts another) {
return token.equals(another.token)
&& values.equals(another.values);
}
/**
* Computes a hash code from attributes: {@code token}, {@code values}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + token.hashCode();
h += (h << 5) + values.hashCode();
return h;
}
/**
* Prints the immutable value {@code RedundentAccepts} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "RedundentAccepts{"
+ "token=" + token
+ ", values=" + values
+ "}";
}
/**
* Creates an immutable copy of a {@link HdesParserVisitor.RedundentAccepts} 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 RedundentAccepts instance
*/
public static ImmutableRedundentAccepts copyOf(HdesParserVisitor.RedundentAccepts instance) {
if (instance instanceof ImmutableRedundentAccepts) {
return (ImmutableRedundentAccepts) instance;
}
return ImmutableRedundentAccepts.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableRedundentAccepts ImmutableRedundentAccepts}.
*
* ImmutableRedundentAccepts.builder()
* .token(io.resys.hdes.ast.api.nodes.HdesNode.Token) // required {@link HdesParserVisitor.RedundentAccepts#getToken() token}
* .addValues|addAllValues(io.resys.hdes.ast.api.nodes.BodyNode.TypeDef) // {@link HdesParserVisitor.RedundentAccepts#getValues() values} elements
* .build();
*
* @return A new ImmutableRedundentAccepts builder
*/
public static ImmutableRedundentAccepts.Builder builder() {
return new ImmutableRedundentAccepts.Builder();
}
/**
* Builds instances of type {@link ImmutableRedundentAccepts ImmutableRedundentAccepts}.
* 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 = "HdesParserVisitor.RedundentAccepts", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_TOKEN = 0x1L;
private long initBits = 0x1L;
private @Nullable HdesNode.Token token;
private List values = new ArrayList();
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.spi.antlr.visitors.HdesParserVisitor.RedundentAccepts} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(HdesParserVisitor.RedundentAccepts 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 HdesParserVisitor.RedundentAccepts) {
HdesParserVisitor.RedundentAccepts instance = (HdesParserVisitor.RedundentAccepts) object;
addAllValues(instance.getValues());
}
}
/**
* Initializes the value for the {@link HdesParserVisitor.RedundentAccepts#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;
}
/**
* Adds one element to {@link HdesParserVisitor.RedundentAccepts#getValues() values} list.
* @param element A values element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addValues(BodyNode.TypeDef element) {
this.values.add(Objects.requireNonNull(element, "values element"));
return this;
}
/**
* Adds elements to {@link HdesParserVisitor.RedundentAccepts#getValues() values} list.
* @param elements An array of values elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addValues(BodyNode.TypeDef... elements) {
for (BodyNode.TypeDef element : elements) {
this.values.add(Objects.requireNonNull(element, "values element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link HdesParserVisitor.RedundentAccepts#getValues() values} list.
* @param elements An iterable of values elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder values(Iterable extends BodyNode.TypeDef> elements) {
this.values.clear();
return addAllValues(elements);
}
/**
* Adds elements to {@link HdesParserVisitor.RedundentAccepts#getValues() values} list.
* @param elements An iterable of values elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllValues(Iterable extends BodyNode.TypeDef> elements) {
for (BodyNode.TypeDef element : elements) {
this.values.add(Objects.requireNonNull(element, "values element"));
}
return this;
}
/**
* Builds a new {@link ImmutableRedundentAccepts ImmutableRedundentAccepts}.
* @return An immutable instance of RedundentAccepts
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableRedundentAccepts build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableRedundentAccepts(token, createUnmodifiableList(true, values));
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_TOKEN) != 0) attributes.add("token");
return "Cannot build RedundentAccepts, some of required attributes are not set " + attributes;
}
}
private static List createSafeList(Iterable extends T> iterable, boolean checkNulls, boolean skipNulls) {
ArrayList list;
if (iterable instanceof Collection>) {
int size = ((Collection>) iterable).size();
if (size == 0) return Collections.emptyList();
list = new ArrayList<>();
} else {
list = new ArrayList<>();
}
for (T element : iterable) {
if (skipNulls && element == null) continue;
if (checkNulls) Objects.requireNonNull(element, "element");
list.add(element);
}
return list;
}
private static List createUnmodifiableList(boolean clone, List list) {
switch(list.size()) {
case 0: return Collections.emptyList();
case 1: return Collections.singletonList(list.get(0));
default:
if (clone) {
return Collections.unmodifiableList(new ArrayList<>(list));
} else {
if (list instanceof ArrayList>) {
((ArrayList>) list).trimToSize();
}
return Collections.unmodifiableList(list);
}
}
}
}