dz.jtsgen.processor.model.NameSpaceMappingBuilder 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 NameSpaceMapping}.
*
* Use the builder to create immutable instances:
* {@code NameSpaceMappingBuilder.builder()}.
* Use the static factory method to create immutable instances:
* {@code NameSpaceMappingBuilder.of()}.
*/
@SuppressWarnings({"all"})
@Generated({"Immutables.generator", "NameSpaceMapping"})
public final class NameSpaceMappingBuilder extends NameSpaceMapping {
private final String originNameSpace;
private final String targetNameSpace;
private final boolean exact;
private NameSpaceMappingBuilder(String originNameSpace, String targetNameSpace) {
this.originNameSpace = Objects.requireNonNull(originNameSpace, "originNameSpace");
this.targetNameSpace = Objects.requireNonNull(targetNameSpace, "targetNameSpace");
this.exact = super.exact();
}
private NameSpaceMappingBuilder(NameSpaceMappingBuilder.Builder builder) {
this.originNameSpace = builder.originNameSpace;
this.targetNameSpace = builder.targetNameSpace;
this.exact = builder.exactIsSet()
? builder.exact
: super.exact();
}
private NameSpaceMappingBuilder(String originNameSpace, String targetNameSpace, boolean exact) {
this.originNameSpace = originNameSpace;
this.targetNameSpace = targetNameSpace;
this.exact = exact;
}
/**
* @return The value of the {@code originNameSpace} attribute
*/
@Override
public String originNameSpace() {
return originNameSpace;
}
/**
* @return The value of the {@code targetNameSpace} attribute
*/
@Override
public String targetNameSpace() {
return targetNameSpace;
}
/**
* @return The value of the {@code exact} attribute
*/
@Override
public boolean exact() {
return exact;
}
/**
* Copy the current immutable object by setting a value for the {@link NameSpaceMapping#originNameSpace() originNameSpace} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for originNameSpace
* @return A modified copy of the {@code this} object
*/
public final NameSpaceMappingBuilder withOriginNameSpace(String value) {
if (this.originNameSpace.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "originNameSpace");
return new NameSpaceMappingBuilder(newValue, this.targetNameSpace, this.exact);
}
/**
* Copy the current immutable object by setting a value for the {@link NameSpaceMapping#targetNameSpace() targetNameSpace} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for targetNameSpace
* @return A modified copy of the {@code this} object
*/
public final NameSpaceMappingBuilder withTargetNameSpace(String value) {
if (this.targetNameSpace.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "targetNameSpace");
return new NameSpaceMappingBuilder(this.originNameSpace, newValue, this.exact);
}
/**
* Copy the current immutable object by setting a value for the {@link NameSpaceMapping#exact() exact} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for exact
* @return A modified copy of the {@code this} object
*/
public final NameSpaceMappingBuilder withExact(boolean value) {
if (this.exact == value) return this;
return new NameSpaceMappingBuilder(this.originNameSpace, this.targetNameSpace, value);
}
/**
* This instance is equal to all instances of {@code NameSpaceMappingBuilder} 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 NameSpaceMappingBuilder
&& equalTo((NameSpaceMappingBuilder) another);
}
private boolean equalTo(NameSpaceMappingBuilder another) {
return originNameSpace.equals(another.originNameSpace)
&& targetNameSpace.equals(another.targetNameSpace)
&& exact == another.exact;
}
/**
* Computes a hash code from attributes: {@code originNameSpace}, {@code targetNameSpace}, {@code exact}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + originNameSpace.hashCode();
h += (h << 5) + targetNameSpace.hashCode();
h += (h << 5) + Boolean.hashCode(exact);
return h;
}
/**
* Construct a new immutable {@code NameSpaceMapping} instance.
* @param originNameSpace The value for the {@code originNameSpace} attribute
* @param targetNameSpace The value for the {@code targetNameSpace} attribute
* @return An immutable NameSpaceMapping instance
*/
public static NameSpaceMappingBuilder of(String originNameSpace, String targetNameSpace) {
return new NameSpaceMappingBuilder(originNameSpace, targetNameSpace);
}
/**
* Creates an immutable copy of a {@link NameSpaceMapping} 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 NameSpaceMapping instance
*/
public static NameSpaceMappingBuilder copyOf(NameSpaceMapping instance) {
if (instance instanceof NameSpaceMappingBuilder) {
return (NameSpaceMappingBuilder) instance;
}
return NameSpaceMappingBuilder.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link NameSpaceMappingBuilder NameSpaceMappingBuilder}.
* @return A new NameSpaceMappingBuilder builder
*/
public static NameSpaceMappingBuilder.Builder builder() {
return new NameSpaceMappingBuilder.Builder();
}
/**
* Builds instances of type {@link NameSpaceMappingBuilder NameSpaceMappingBuilder}.
* 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_ORIGIN_NAME_SPACE = 0x1L;
private static final long INIT_BIT_TARGET_NAME_SPACE = 0x2L;
private static final long OPT_BIT_EXACT = 0x1L;
private long initBits = 0x3L;
private long optBits;
private String originNameSpace;
private String targetNameSpace;
private boolean exact;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code NameSpaceMapping} 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 Builder from(NameSpaceMapping instance) {
Objects.requireNonNull(instance, "instance");
originNameSpace(instance.originNameSpace());
targetNameSpace(instance.targetNameSpace());
exact(instance.exact());
return this;
}
/**
* Initializes the value for the {@link NameSpaceMapping#originNameSpace() originNameSpace} attribute.
* @param originNameSpace The value for originNameSpace
* @return {@code this} builder for use in a chained invocation
*/
public final Builder originNameSpace(String originNameSpace) {
this.originNameSpace = Objects.requireNonNull(originNameSpace, "originNameSpace");
initBits &= ~INIT_BIT_ORIGIN_NAME_SPACE;
return this;
}
/**
* Initializes the value for the {@link NameSpaceMapping#targetNameSpace() targetNameSpace} attribute.
* @param targetNameSpace The value for targetNameSpace
* @return {@code this} builder for use in a chained invocation
*/
public final Builder targetNameSpace(String targetNameSpace) {
this.targetNameSpace = Objects.requireNonNull(targetNameSpace, "targetNameSpace");
initBits &= ~INIT_BIT_TARGET_NAME_SPACE;
return this;
}
/**
* Initializes the value for the {@link NameSpaceMapping#exact() exact} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link NameSpaceMapping#exact() exact}.
* @param exact The value for exact
* @return {@code this} builder for use in a chained invocation
*/
public final Builder exact(boolean exact) {
this.exact = exact;
optBits |= OPT_BIT_EXACT;
return this;
}
/**
* Builds a new {@link NameSpaceMappingBuilder NameSpaceMappingBuilder}.
* @return An immutable instance of NameSpaceMapping
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public NameSpaceMappingBuilder build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new NameSpaceMappingBuilder(this);
}
private boolean exactIsSet() {
return (optBits & OPT_BIT_EXACT) != 0;
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList();
if ((initBits & INIT_BIT_ORIGIN_NAME_SPACE) != 0) attributes.add("originNameSpace");
if ((initBits & INIT_BIT_TARGET_NAME_SPACE) != 0) attributes.add("targetNameSpace");
return "Cannot build NameSpaceMapping, some of required attributes are not set " + attributes;
}
}
}