edu.isi.nlp.ImmutableStringWithoutNonBmp Maven / Gradle / Ivy
package edu.isi.nlp;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.List;
import javax.annotation.Generated;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
/**
* Immutable implementation of {@link StringWithoutNonBmp}.
*
* Use the builder to create immutable instances:
* {@code new StringWithoutNonBmp.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "StringWithoutNonBmp"})
@Immutable
final class ImmutableStringWithoutNonBmp extends StringWithoutNonBmp {
private final String utf16CodeUnits;
private ImmutableStringWithoutNonBmp(String utf16CodeUnits) {
this.utf16CodeUnits = utf16CodeUnits;
}
/**
* @return The value of the {@code utf16CodeUnits} attribute
*/
@Override
public String utf16CodeUnits() {
return utf16CodeUnits;
}
/**
* Copy the current immutable object by setting a value for the {@link StringWithoutNonBmp#utf16CodeUnits() utf16CodeUnits} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for utf16CodeUnits
* @return A modified copy of the {@code this} object
*/
public final ImmutableStringWithoutNonBmp withUtf16CodeUnits(String value) {
if (this.utf16CodeUnits.equals(value)) return this;
String newValue = Preconditions.checkNotNull(value, "utf16CodeUnits");
return new ImmutableStringWithoutNonBmp(newValue);
}
/**
* Creates an immutable copy of a {@link StringWithoutNonBmp} 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 StringWithoutNonBmp instance
*/
public static StringWithoutNonBmp copyOf(StringWithoutNonBmp instance) {
if (instance instanceof ImmutableStringWithoutNonBmp) {
return (ImmutableStringWithoutNonBmp) instance;
}
return new StringWithoutNonBmp.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link StringWithoutNonBmp StringWithoutNonBmp}.
* 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.
*/
@NotThreadSafe
static class Builder {
private static final long INIT_BIT_UTF16_CODE_UNITS = 0x1L;
private long initBits = 0x1L;
private @Nullable String utf16CodeUnits;
/**
* Creates a builder for {@link StringWithoutNonBmp StringWithoutNonBmp} instances.
*/
Builder() {
if (!(this instanceof StringWithoutNonBmp.Builder)) {
throw new UnsupportedOperationException("Use: new StringWithoutNonBmp.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code edu.isi.nlp.StringWithoutNonBmp} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final StringWithoutNonBmp.Builder from(StringWithoutNonBmp instance) {
Preconditions.checkNotNull(instance, "instance");
from((Object) instance);
return (StringWithoutNonBmp.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code edu.isi.nlp.UnicodeFriendlyString} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final StringWithoutNonBmp.Builder from(UnicodeFriendlyString instance) {
Preconditions.checkNotNull(instance, "instance");
from((Object) instance);
return (StringWithoutNonBmp.Builder) this;
}
private void from(Object object) {
long bits = 0;
if (object instanceof StringWithoutNonBmp) {
StringWithoutNonBmp instance = (StringWithoutNonBmp) object;
if ((bits & 0x1L) == 0) {
utf16CodeUnits(instance.utf16CodeUnits());
bits |= 0x1L;
}
}
if (object instanceof UnicodeFriendlyString) {
UnicodeFriendlyString instance = (UnicodeFriendlyString) object;
if ((bits & 0x1L) == 0) {
utf16CodeUnits(instance.utf16CodeUnits());
bits |= 0x1L;
}
}
}
/**
* Initializes the value for the {@link StringWithoutNonBmp#utf16CodeUnits() utf16CodeUnits} attribute.
* @param utf16CodeUnits The value for utf16CodeUnits
* @return {@code this} builder for use in a chained invocation
*/
public final StringWithoutNonBmp.Builder utf16CodeUnits(String utf16CodeUnits) {
this.utf16CodeUnits = Preconditions.checkNotNull(utf16CodeUnits, "utf16CodeUnits");
initBits &= ~INIT_BIT_UTF16_CODE_UNITS;
return (StringWithoutNonBmp.Builder) this;
}
/**
* Builds a new {@link StringWithoutNonBmp StringWithoutNonBmp}.
* @return An immutable instance of StringWithoutNonBmp
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public StringWithoutNonBmp build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableStringWithoutNonBmp(utf16CodeUnits);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_UTF16_CODE_UNITS) != 0) attributes.add("utf16CodeUnits");
return "Cannot build StringWithoutNonBmp, some of required attributes are not set " + attributes;
}
}
}