All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.therealmone.tdf4j.model.ebnf.ImmutableNonTerminal Maven / Gradle / Ivy

package io.github.therealmone.tdf4j.model.ebnf;

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 NonTerminal}.
 * 

* Use the builder to create immutable instances: * {@code new NonTerminal.Builder()}. */ @Generated(from = "NonTerminal", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable public final class ImmutableNonTerminal extends NonTerminal { private final String identifier; private ImmutableNonTerminal(String identifier) { this.identifier = identifier; } /** * @return The value of the {@code identifier} attribute */ @Override public String identifier() { return identifier; } /** * Copy the current immutable object by setting a value for the {@link NonTerminal#identifier() identifier} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for identifier * @return A modified copy of the {@code this} object */ public final ImmutableNonTerminal withIdentifier(String value) { String newValue = Objects.requireNonNull(value, "identifier"); if (this.identifier.equals(newValue)) return this; return new ImmutableNonTerminal(newValue); } /** * This instance is equal to all instances of {@code ImmutableNonTerminal} 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 ImmutableNonTerminal && equalTo((ImmutableNonTerminal) another); } private boolean equalTo(ImmutableNonTerminal another) { return identifier.equals(another.identifier); } /** * Computes a hash code from attributes: {@code identifier}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + identifier.hashCode(); return h; } /** * Creates an immutable copy of a {@link NonTerminal} 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 NonTerminal instance */ public static ImmutableNonTerminal copyOf(NonTerminal instance) { if (instance instanceof ImmutableNonTerminal) { return (ImmutableNonTerminal) instance; } return new NonTerminal.Builder() .identifier(instance.identifier()) .build(); } /** * Builds instances of type {@link ImmutableNonTerminal ImmutableNonTerminal}. * 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 = "NonTerminal", generator = "Immutables") @NotThreadSafe public static class Builder { private static final long INIT_BIT_IDENTIFIER = 0x1L; private long initBits = 0x1L; private @Nullable String identifier; /** * Creates a builder for {@link ImmutableNonTerminal ImmutableNonTerminal} instances. */ public Builder() { if (!(this instanceof NonTerminal.Builder)) { throw new UnsupportedOperationException("Use: new NonTerminal.Builder()"); } } /** * Initializes the value for the {@link NonTerminal#identifier() identifier} attribute. * @param identifier The value for identifier * @return {@code this} builder for use in a chained invocation */ public final NonTerminal.Builder identifier(String identifier) { checkNotIsSet(identifierIsSet(), "identifier"); this.identifier = Objects.requireNonNull(identifier, "identifier"); initBits &= ~INIT_BIT_IDENTIFIER; return (NonTerminal.Builder) this; } /** * Builds a new {@link ImmutableNonTerminal ImmutableNonTerminal}. * @return An immutable instance of NonTerminal * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableNonTerminal build() { checkRequiredAttributes(); return new ImmutableNonTerminal(identifier); } private boolean identifierIsSet() { return (initBits & INIT_BIT_IDENTIFIER) == 0; } private static void checkNotIsSet(boolean isSet, String name) { if (isSet) throw new IllegalStateException("Builder of NonTerminal is strict, attribute is already set: ".concat(name)); } private void checkRequiredAttributes() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if (!identifierIsSet()) attributes.add("identifier"); return "Cannot build NonTerminal, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy