dz.jtsgen.processor.model.TSEnumMemberBuilder Maven / Gradle / Ivy
Show all versions of jtsgen-processor Show documentation
package dz.jtsgen.processor.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.Generated;
/**
* Immutable implementation of {@link TSEnumMember}.
*
* Use the builder to create immutable instances:
* {@code TSEnumMemberBuilder.builder()}.
* Use the static factory method to create immutable instances:
* {@code TSEnumMemberBuilder.of()}.
*/
@SuppressWarnings({"all"})
@Generated({"Immutables.generator", "TSEnumMember"})
public final class TSEnumMemberBuilder extends TSEnumMember {
private final String name;
private final TSTargetType type;
private final boolean invalid;
private final boolean readOnly;
private TSEnumMemberBuilder(String name) {
this.name = Objects.requireNonNull(name, "name");
this.type = initShim.getType();
this.invalid = initShim.getInvalid();
this.readOnly = initShim.getReadOnly();
this.initShim = null;
}
private TSEnumMemberBuilder(TSEnumMemberBuilder.Builder builder) {
this.name = builder.name;
if (builder.invalidIsSet()) {
initShim.invalid(builder.invalid);
}
if (builder.readOnlyIsSet()) {
initShim.readOnly(builder.readOnly);
}
this.invalid = initShim.getInvalid();
this.readOnly = initShim.getReadOnly();
this.type = initShim.getType();
this.initShim = null;
}
private TSEnumMemberBuilder(String name, boolean invalid, boolean readOnly) {
this.name = name;
this.invalid = invalid;
this.readOnly = readOnly;
initShim.invalid(this.invalid);
initShim.readOnly(this.readOnly);
this.type = initShim.getType();
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 TSTargetType type;
private int typeBuildStage;
TSTargetType getType() {
if (typeBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (typeBuildStage == STAGE_UNINITIALIZED) {
typeBuildStage = STAGE_INITIALIZING;
this.type = Objects.requireNonNull(TSEnumMemberBuilder.super.getType(), "type");
typeBuildStage = STAGE_INITIALIZED;
}
return this.type;
}
private boolean invalid;
private int invalidBuildStage;
boolean getInvalid() {
if (invalidBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (invalidBuildStage == STAGE_UNINITIALIZED) {
invalidBuildStage = STAGE_INITIALIZING;
this.invalid = TSEnumMemberBuilder.super.getInvalid();
invalidBuildStage = STAGE_INITIALIZED;
}
return this.invalid;
}
void invalid(boolean invalid) {
this.invalid = invalid;
invalidBuildStage = STAGE_INITIALIZED;
}
private boolean readOnly;
private int readOnlyBuildStage;
boolean getReadOnly() {
if (readOnlyBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (readOnlyBuildStage == STAGE_UNINITIALIZED) {
readOnlyBuildStage = STAGE_INITIALIZING;
this.readOnly = TSEnumMemberBuilder.super.getReadOnly();
readOnlyBuildStage = STAGE_INITIALIZED;
}
return this.readOnly;
}
void readOnly(boolean readOnly) {
this.readOnly = readOnly;
readOnlyBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
ArrayList attributes = new ArrayList();
if (typeBuildStage == STAGE_INITIALIZING) attributes.add("type");
if (invalidBuildStage == STAGE_INITIALIZING) attributes.add("invalid");
if (readOnlyBuildStage == STAGE_INITIALIZING) attributes.add("readOnly");
return "Cannot build TSEnumMember, attribute initializers form cycle" + attributes;
}
}
/**
* @return The value of the {@code name} attribute
*/
@Override
public String getName() {
return name;
}
/**
* @return The computed-at-construction value of the {@code type} attribute
*/
@Override
public TSTargetType getType() {
InitShim shim = this.initShim;
return shim != null
? shim.getType()
: this.type;
}
/**
* @return The value of the {@code invalid} attribute
*/
@Override
public boolean getInvalid() {
InitShim shim = this.initShim;
return shim != null
? shim.getInvalid()
: this.invalid;
}
/**
* @return The value of the {@code readOnly} attribute
*/
@Override
public boolean getReadOnly() {
InitShim shim = this.initShim;
return shim != null
? shim.getReadOnly()
: this.readOnly;
}
/**
* Copy the current immutable object by setting a value for the {@link TSEnumMember#getName() name} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for name
* @return A modified copy of the {@code this} object
*/
public final TSEnumMemberBuilder withName(String value) {
if (this.name.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "name");
return new TSEnumMemberBuilder(newValue, this.invalid, this.readOnly);
}
/**
* Copy the current immutable object by setting a value for the {@link TSEnumMember#getInvalid() invalid} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for invalid
* @return A modified copy of the {@code this} object
*/
public final TSEnumMemberBuilder withInvalid(boolean value) {
if (this.invalid == value) return this;
return new TSEnumMemberBuilder(this.name, value, this.readOnly);
}
/**
* Copy the current immutable object by setting a value for the {@link TSEnumMember#getReadOnly() readOnly} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for readOnly
* @return A modified copy of the {@code this} object
*/
public final TSEnumMemberBuilder withReadOnly(boolean value) {
if (this.readOnly == value) return this;
return new TSEnumMemberBuilder(this.name, this.invalid, value);
}
/**
* This instance is equal to all instances of {@code TSEnumMemberBuilder} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(Object another) {
if (this == another) return true;
return another instanceof TSEnumMemberBuilder
&& equalTo((TSEnumMemberBuilder) another);
}
private boolean equalTo(TSEnumMemberBuilder another) {
return name.equals(another.name)
&& type.equals(another.type)
&& invalid == another.invalid
&& readOnly == another.readOnly;
}
/**
* Computes a hash code from attributes: {@code name}, {@code type}, {@code invalid}, {@code readOnly}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + name.hashCode();
h += (h << 5) + type.hashCode();
h += (h << 5) + Boolean.hashCode(invalid);
h += (h << 5) + Boolean.hashCode(readOnly);
return h;
}
/**
* Prints the immutable value {@code TSEnumMember} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "TSEnumMember{"
+ "name=" + name
+ ", type=" + type
+ ", invalid=" + invalid
+ ", readOnly=" + readOnly
+ "}";
}
/**
* Construct a new immutable {@code TSEnumMember} instance.
* @param name The value for the {@code name} attribute
* @return An immutable TSEnumMember instance
*/
public static TSEnumMemberBuilder of(String name) {
return new TSEnumMemberBuilder(name);
}
/**
* Creates an immutable copy of a {@link TSEnumMember} 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 TSEnumMember instance
*/
public static TSEnumMemberBuilder copyOf(TSEnumMember instance) {
if (instance instanceof TSEnumMemberBuilder) {
return (TSEnumMemberBuilder) instance;
}
return TSEnumMemberBuilder.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link TSEnumMemberBuilder TSEnumMemberBuilder}.
* @return A new TSEnumMemberBuilder builder
*/
public static TSEnumMemberBuilder.Builder builder() {
return new TSEnumMemberBuilder.Builder();
}
/**
* Builds instances of type {@link TSEnumMemberBuilder TSEnumMemberBuilder}.
* 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.
*/
public static final class Builder {
private static final long INIT_BIT_NAME = 0x1L;
private static final long OPT_BIT_INVALID = 0x1L;
private static final long OPT_BIT_READ_ONLY = 0x2L;
private long initBits = 0x1L;
private long optBits;
private String name;
private boolean invalid;
private boolean readOnly;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code dz.jtsgen.processor.model.TSEnumMember} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(TSEnumMember instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code dz.jtsgen.processor.model.TSMember} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(TSMember instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
long bits = 0;
if (object instanceof TSEnumMember) {
TSEnumMember instance = (TSEnumMember) object;
if ((bits & 0x1L) == 0) {
name(instance.getName());
bits |= 0x1L;
}
if ((bits & 0x2L) == 0) {
invalid(instance.getInvalid());
bits |= 0x2L;
}
if ((bits & 0x4L) == 0) {
readOnly(instance.getReadOnly());
bits |= 0x4L;
}
}
if (object instanceof TSMember) {
TSMember instance = (TSMember) object;
if ((bits & 0x1L) == 0) {
name(instance.getName());
bits |= 0x1L;
}
if ((bits & 0x2L) == 0) {
invalid(instance.getInvalid());
bits |= 0x2L;
}
if ((bits & 0x4L) == 0) {
readOnly(instance.getReadOnly());
bits |= 0x4L;
}
}
}
/**
* Initializes the value for the {@link TSEnumMember#getName() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
public final Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes the value for the {@link TSEnumMember#getInvalid() invalid} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link TSEnumMember#getInvalid() invalid}.
* @param invalid The value for invalid
* @return {@code this} builder for use in a chained invocation
*/
public final Builder invalid(boolean invalid) {
this.invalid = invalid;
optBits |= OPT_BIT_INVALID;
return this;
}
/**
* Initializes the value for the {@link TSEnumMember#getReadOnly() readOnly} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link TSEnumMember#getReadOnly() readOnly}.
* @param readOnly The value for readOnly
* @return {@code this} builder for use in a chained invocation
*/
public final Builder readOnly(boolean readOnly) {
this.readOnly = readOnly;
optBits |= OPT_BIT_READ_ONLY;
return this;
}
/**
* Builds a new {@link TSEnumMemberBuilder TSEnumMemberBuilder}.
* @return An immutable instance of TSEnumMember
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public TSEnumMemberBuilder build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new TSEnumMemberBuilder(this);
}
private boolean invalidIsSet() {
return (optBits & OPT_BIT_INVALID) != 0;
}
private boolean readOnlyIsSet() {
return (optBits & OPT_BIT_READ_ONLY) != 0;
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
return "Cannot build TSEnumMember, some of required attributes are not set " + attributes;
}
}
}