edu.isi.nlp.parameters.serifstyle.ImmutableSerifStyleParameterFileLoader Maven / Gradle / Ivy
package edu.isi.nlp.parameters.serifstyle;
import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.primitives.Booleans;
import java.io.File;
import java.util.ArrayList;
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 SerifStyleParameterFileLoader}.
*
* Use the builder to create immutable instances:
* {@code new SerifStyleParameterFileLoader.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "SerifStyleParameterFileLoader"})
@Immutable
final class ImmutableSerifStyleParameterFileLoader
extends SerifStyleParameterFileLoader {
private final boolean crashOnUndeclaredOverrides;
private final boolean interpolateEnvironmentalVariables;
private ImmutableSerifStyleParameterFileLoader(ImmutableSerifStyleParameterFileLoader.Builder builder) {
if (builder.crashOnUndeclaredOverridesIsSet()) {
initShim.crashOnUndeclaredOverrides(builder.crashOnUndeclaredOverrides);
}
if (builder.interpolateEnvironmentalVariablesIsSet()) {
initShim.interpolateEnvironmentalVariables(builder.interpolateEnvironmentalVariables);
}
this.crashOnUndeclaredOverrides = initShim.crashOnUndeclaredOverrides();
this.interpolateEnvironmentalVariables = initShim.interpolateEnvironmentalVariables();
this.initShim = null;
}
private ImmutableSerifStyleParameterFileLoader(boolean crashOnUndeclaredOverrides, boolean interpolateEnvironmentalVariables) {
this.crashOnUndeclaredOverrides = crashOnUndeclaredOverrides;
this.interpolateEnvironmentalVariables = interpolateEnvironmentalVariables;
this.initShim = null;
}
private static final int STAGE_INITIALIZING = -1;
private static final int STAGE_UNINITIALIZED = 0;
private static final int STAGE_INITIALIZED = 1;
private transient volatile InitShim initShim = new InitShim();
private final class InitShim {
private boolean crashOnUndeclaredOverrides;
private int crashOnUndeclaredOverridesStage;
boolean crashOnUndeclaredOverrides() {
if (crashOnUndeclaredOverridesStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (crashOnUndeclaredOverridesStage == STAGE_UNINITIALIZED) {
crashOnUndeclaredOverridesStage = STAGE_INITIALIZING;
this.crashOnUndeclaredOverrides = ImmutableSerifStyleParameterFileLoader.super.crashOnUndeclaredOverrides();
crashOnUndeclaredOverridesStage = STAGE_INITIALIZED;
}
return this.crashOnUndeclaredOverrides;
}
void crashOnUndeclaredOverrides(boolean crashOnUndeclaredOverrides) {
this.crashOnUndeclaredOverrides = crashOnUndeclaredOverrides;
crashOnUndeclaredOverridesStage = STAGE_INITIALIZED;
}
private boolean interpolateEnvironmentalVariables;
private int interpolateEnvironmentalVariablesStage;
boolean interpolateEnvironmentalVariables() {
if (interpolateEnvironmentalVariablesStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (interpolateEnvironmentalVariablesStage == STAGE_UNINITIALIZED) {
interpolateEnvironmentalVariablesStage = STAGE_INITIALIZING;
this.interpolateEnvironmentalVariables = ImmutableSerifStyleParameterFileLoader.super.interpolateEnvironmentalVariables();
interpolateEnvironmentalVariablesStage = STAGE_INITIALIZED;
}
return this.interpolateEnvironmentalVariables;
}
void interpolateEnvironmentalVariables(boolean interpolateEnvironmentalVariables) {
this.interpolateEnvironmentalVariables = interpolateEnvironmentalVariables;
interpolateEnvironmentalVariablesStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
ArrayList attributes = Lists.newArrayList();
if (crashOnUndeclaredOverridesStage == STAGE_INITIALIZING) attributes.add("crashOnUndeclaredOverrides");
if (interpolateEnvironmentalVariablesStage == STAGE_INITIALIZING) attributes.add("interpolateEnvironmentalVariables");
return "Cannot build SerifStyleParameterFileLoader, attribute initializers form cycle" + attributes;
}
}
/**
* @return The value of the {@code crashOnUndeclaredOverrides} attribute
*/
@Override
public boolean crashOnUndeclaredOverrides() {
InitShim shim = this.initShim;
return shim != null
? shim.crashOnUndeclaredOverrides()
: this.crashOnUndeclaredOverrides;
}
/**
* @return The value of the {@code interpolateEnvironmentalVariables} attribute
*/
@Override
public boolean interpolateEnvironmentalVariables() {
InitShim shim = this.initShim;
return shim != null
? shim.interpolateEnvironmentalVariables()
: this.interpolateEnvironmentalVariables;
}
/**
* Copy the current immutable object by setting a value for the {@link SerifStyleParameterFileLoader#crashOnUndeclaredOverrides() crashOnUndeclaredOverrides} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for crashOnUndeclaredOverrides
* @return A modified copy of the {@code this} object
*/
public final ImmutableSerifStyleParameterFileLoader withCrashOnUndeclaredOverrides(boolean value) {
if (this.crashOnUndeclaredOverrides == value) return this;
return new ImmutableSerifStyleParameterFileLoader(value, this.interpolateEnvironmentalVariables);
}
/**
* Copy the current immutable object by setting a value for the {@link SerifStyleParameterFileLoader#interpolateEnvironmentalVariables() interpolateEnvironmentalVariables} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for interpolateEnvironmentalVariables
* @return A modified copy of the {@code this} object
*/
public final ImmutableSerifStyleParameterFileLoader withInterpolateEnvironmentalVariables(boolean value) {
if (this.interpolateEnvironmentalVariables == value) return this;
return new ImmutableSerifStyleParameterFileLoader(this.crashOnUndeclaredOverrides, value);
}
/**
* This instance is equal to all instances of {@code ImmutableSerifStyleParameterFileLoader} 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 ImmutableSerifStyleParameterFileLoader
&& equalTo((ImmutableSerifStyleParameterFileLoader) another);
}
private boolean equalTo(ImmutableSerifStyleParameterFileLoader another) {
return crashOnUndeclaredOverrides == another.crashOnUndeclaredOverrides
&& interpolateEnvironmentalVariables == another.interpolateEnvironmentalVariables;
}
/**
* Computes a hash code from attributes: {@code crashOnUndeclaredOverrides}, {@code interpolateEnvironmentalVariables}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + Booleans.hashCode(crashOnUndeclaredOverrides);
h = h * 17 + Booleans.hashCode(interpolateEnvironmentalVariables);
return h;
}
/**
* Prints the immutable value {@code SerifStyleParameterFileLoader} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SerifStyleParameterFileLoader")
.omitNullValues()
.add("crashOnUndeclaredOverrides", crashOnUndeclaredOverrides)
.add("interpolateEnvironmentalVariables", interpolateEnvironmentalVariables)
.toString();
}
/**
* Creates an immutable copy of a {@link SerifStyleParameterFileLoader} 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 SerifStyleParameterFileLoader instance
*/
public static SerifStyleParameterFileLoader copyOf(SerifStyleParameterFileLoader instance) {
if (instance instanceof ImmutableSerifStyleParameterFileLoader) {
return (ImmutableSerifStyleParameterFileLoader) instance;
}
return new SerifStyleParameterFileLoader.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link SerifStyleParameterFileLoader SerifStyleParameterFileLoader}.
* 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 OPT_BIT_CRASH_ON_UNDECLARED_OVERRIDES = 0x1L;
private static final long OPT_BIT_INTERPOLATE_ENVIRONMENTAL_VARIABLES = 0x2L;
private long optBits;
private boolean crashOnUndeclaredOverrides;
private boolean interpolateEnvironmentalVariables;
/**
* Creates a builder for {@link SerifStyleParameterFileLoader SerifStyleParameterFileLoader} instances.
*/
Builder() {
if (!(this instanceof SerifStyleParameterFileLoader.Builder)) {
throw new UnsupportedOperationException("Use: new SerifStyleParameterFileLoader.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code SerifStyleParameterFileLoader} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final SerifStyleParameterFileLoader.Builder from(SerifStyleParameterFileLoader instance) {
Preconditions.checkNotNull(instance, "instance");
crashOnUndeclaredOverrides(instance.crashOnUndeclaredOverrides());
interpolateEnvironmentalVariables(instance.interpolateEnvironmentalVariables());
return (SerifStyleParameterFileLoader.Builder) this;
}
/**
* Initializes the value for the {@link SerifStyleParameterFileLoader#crashOnUndeclaredOverrides() crashOnUndeclaredOverrides} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link SerifStyleParameterFileLoader#crashOnUndeclaredOverrides() crashOnUndeclaredOverrides}.
* @param crashOnUndeclaredOverrides The value for crashOnUndeclaredOverrides
* @return {@code this} builder for use in a chained invocation
*/
public final SerifStyleParameterFileLoader.Builder crashOnUndeclaredOverrides(boolean crashOnUndeclaredOverrides) {
this.crashOnUndeclaredOverrides = crashOnUndeclaredOverrides;
optBits |= OPT_BIT_CRASH_ON_UNDECLARED_OVERRIDES;
return (SerifStyleParameterFileLoader.Builder) this;
}
/**
* Initializes the value for the {@link SerifStyleParameterFileLoader#interpolateEnvironmentalVariables() interpolateEnvironmentalVariables} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link SerifStyleParameterFileLoader#interpolateEnvironmentalVariables() interpolateEnvironmentalVariables}.
* @param interpolateEnvironmentalVariables The value for interpolateEnvironmentalVariables
* @return {@code this} builder for use in a chained invocation
*/
public final SerifStyleParameterFileLoader.Builder interpolateEnvironmentalVariables(boolean interpolateEnvironmentalVariables) {
this.interpolateEnvironmentalVariables = interpolateEnvironmentalVariables;
optBits |= OPT_BIT_INTERPOLATE_ENVIRONMENTAL_VARIABLES;
return (SerifStyleParameterFileLoader.Builder) this;
}
/**
* Builds a new {@link SerifStyleParameterFileLoader SerifStyleParameterFileLoader}.
* @return An immutable instance of SerifStyleParameterFileLoader
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public SerifStyleParameterFileLoader build() {
return new ImmutableSerifStyleParameterFileLoader(this);
}
private boolean crashOnUndeclaredOverridesIsSet() {
return (optBits & OPT_BIT_CRASH_ON_UNDECLARED_OVERRIDES) != 0;
}
private boolean interpolateEnvironmentalVariablesIsSet() {
return (optBits & OPT_BIT_INTERPOLATE_ENVIRONMENTAL_VARIABLES) != 0;
}
}
/**
* Immutable implementation of {@link SerifStyleParameterFileLoader.ParseIssue}.
*
* Use the builder to create immutable instances:
* {@code ImmutableSerifStyleParameterFileLoader.ParseIssue.builder()}.
*/
@Immutable
static final class ParseIssue
extends SerifStyleParameterFileLoader.ParseIssue {
private final ImmutableList includeStack;
private final int line;
private final String message;
private ParseIssue(
ImmutableList includeStack,
int line,
String message) {
this.includeStack = includeStack;
this.line = line;
this.message = message;
}
/**
* @return The value of the {@code includeStack} attribute
*/
@Override
ImmutableList includeStack() {
return includeStack;
}
/**
* @return The value of the {@code line} attribute
*/
@Override
int line() {
return line;
}
/**
* @return The value of the {@code message} attribute
*/
@Override
String message() {
return message;
}
/**
* Copy the current immutable object with elements that replace the content of {@link SerifStyleParameterFileLoader.ParseIssue#includeStack() includeStack}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableSerifStyleParameterFileLoader.ParseIssue withIncludeStack(File... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableSerifStyleParameterFileLoader.ParseIssue(newValue, this.line, this.message);
}
/**
* Copy the current immutable object with elements that replace the content of {@link SerifStyleParameterFileLoader.ParseIssue#includeStack() includeStack}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of includeStack elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableSerifStyleParameterFileLoader.ParseIssue withIncludeStack(Iterable extends File> elements) {
if (this.includeStack == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableSerifStyleParameterFileLoader.ParseIssue(newValue, this.line, this.message);
}
/**
* Copy the current immutable object by setting a value for the {@link SerifStyleParameterFileLoader.ParseIssue#line() line} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for line
* @return A modified copy of the {@code this} object
*/
public final ImmutableSerifStyleParameterFileLoader.ParseIssue withLine(int value) {
if (this.line == value) return this;
return new ImmutableSerifStyleParameterFileLoader.ParseIssue(this.includeStack, value, this.message);
}
/**
* Copy the current immutable object by setting a value for the {@link SerifStyleParameterFileLoader.ParseIssue#message() message} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for message
* @return A modified copy of the {@code this} object
*/
public final ImmutableSerifStyleParameterFileLoader.ParseIssue withMessage(String value) {
if (this.message.equals(value)) return this;
String newValue = Preconditions.checkNotNull(value, "message");
return new ImmutableSerifStyleParameterFileLoader.ParseIssue(this.includeStack, this.line, newValue);
}
/**
* This instance is equal to all instances of {@code ParseIssue} 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 ImmutableSerifStyleParameterFileLoader.ParseIssue
&& equalTo((ImmutableSerifStyleParameterFileLoader.ParseIssue) another);
}
private boolean equalTo(ImmutableSerifStyleParameterFileLoader.ParseIssue another) {
return includeStack.equals(another.includeStack)
&& line == another.line
&& message.equals(another.message);
}
/**
* Computes a hash code from attributes: {@code includeStack}, {@code line}, {@code message}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 31;
h = h * 17 + includeStack.hashCode();
h = h * 17 + line;
h = h * 17 + message.hashCode();
return h;
}
/**
* Prints the immutable value {@code ParseIssue} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ParseIssue")
.omitNullValues()
.add("includeStack", includeStack)
.add("line", line)
.add("message", message)
.toString();
}
/**
* Creates an immutable copy of a {@link SerifStyleParameterFileLoader.ParseIssue} 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 ParseIssue instance
*/
public static SerifStyleParameterFileLoader.ParseIssue copyOf(SerifStyleParameterFileLoader.ParseIssue instance) {
if (instance instanceof ImmutableSerifStyleParameterFileLoader.ParseIssue) {
return (ImmutableSerifStyleParameterFileLoader.ParseIssue) instance;
}
return ImmutableSerifStyleParameterFileLoader.ParseIssue.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link SerifStyleParameterFileLoader.ParseIssue ParseIssue}.
* @return A new ParseIssue builder
*/
public static ImmutableSerifStyleParameterFileLoader.ParseIssue.Builder builder() {
return new ImmutableSerifStyleParameterFileLoader.ParseIssue.Builder();
}
/**
* Builds instances of type {@link SerifStyleParameterFileLoader.ParseIssue ParseIssue}.
* 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 final class Builder {
private static final long INIT_BIT_LINE = 0x1L;
private static final long INIT_BIT_MESSAGE = 0x2L;
private long initBits = 0x3L;
private ImmutableList.Builder includeStack = ImmutableList.builder();
private int line;
private @Nullable String message;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code ParseIssue} 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
*/
public final Builder from(SerifStyleParameterFileLoader.ParseIssue instance) {
Preconditions.checkNotNull(instance, "instance");
addAllIncludeStack(instance.includeStack());
line(instance.line());
message(instance.message());
return this;
}
/**
* Adds one element to {@link SerifStyleParameterFileLoader.ParseIssue#includeStack() includeStack} list.
* @param element A includeStack element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addIncludeStack(File element) {
this.includeStack.add(element);
return this;
}
/**
* Adds elements to {@link SerifStyleParameterFileLoader.ParseIssue#includeStack() includeStack} list.
* @param elements An array of includeStack elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addIncludeStack(File... elements) {
this.includeStack.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link SerifStyleParameterFileLoader.ParseIssue#includeStack() includeStack} list.
* @param elements An iterable of includeStack elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder includeStack(Iterable extends File> elements) {
this.includeStack = ImmutableList.builder();
return addAllIncludeStack(elements);
}
/**
* Adds elements to {@link SerifStyleParameterFileLoader.ParseIssue#includeStack() includeStack} list.
* @param elements An iterable of includeStack elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllIncludeStack(Iterable extends File> elements) {
this.includeStack.addAll(elements);
return this;
}
/**
* Initializes the value for the {@link SerifStyleParameterFileLoader.ParseIssue#line() line} attribute.
* @param line The value for line
* @return {@code this} builder for use in a chained invocation
*/
public final Builder line(int line) {
this.line = line;
initBits &= ~INIT_BIT_LINE;
return this;
}
/**
* Initializes the value for the {@link SerifStyleParameterFileLoader.ParseIssue#message() message} attribute.
* @param message The value for message
* @return {@code this} builder for use in a chained invocation
*/
public final Builder message(String message) {
this.message = Preconditions.checkNotNull(message, "message");
initBits &= ~INIT_BIT_MESSAGE;
return this;
}
/**
* Builds a new {@link SerifStyleParameterFileLoader.ParseIssue ParseIssue}.
* @return An immutable instance of ParseIssue
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public SerifStyleParameterFileLoader.ParseIssue build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableSerifStyleParameterFileLoader.ParseIssue(includeStack.build(), line, message);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_LINE) != 0) attributes.add("line");
if ((initBits & INIT_BIT_MESSAGE) != 0) attributes.add("message");
return "Cannot build ParseIssue, some of required attributes are not set " + attributes;
}
}
}
}