io.resys.wrench.assets.dt.api.model.ImmutableHeader Maven / Gradle / Ivy
package io.resys.wrench.assets.dt.api.model;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import io.resys.wrench.assets.datatype.api.DataTypeRepository;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
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 DecisionTableAst.Header}.
*
* Use the builder to create immutable instances:
* {@code ImmutableHeader.builder()}.
*/
@Generated(from = "DecisionTableAst.Header", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableHeader implements DecisionTableAst.Header {
private final String id;
private final Integer order;
private final String name;
private final DataTypeRepository.ValueType value;
private final DataTypeRepository.Direction direction;
private final @Nullable String script;
private ImmutableHeader(
String id,
Integer order,
String name,
DataTypeRepository.ValueType value,
DataTypeRepository.Direction direction,
@Nullable String script) {
this.id = id;
this.order = order;
this.name = name;
this.value = value;
this.direction = direction;
this.script = script;
}
/**
* @return The value of the {@code id} attribute
*/
@Override
public String getId() {
return id;
}
/**
* @return The value of the {@code order} attribute
*/
@Override
public Integer getOrder() {
return order;
}
/**
* @return The value of the {@code name} attribute
*/
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code value} attribute
*/
@Override
public DataTypeRepository.ValueType getValue() {
return value;
}
/**
* @return The value of the {@code direction} attribute
*/
@Override
public DataTypeRepository.Direction getDirection() {
return direction;
}
/**
* @return The value of the {@code script} attribute
*/
@Override
public @Nullable String getScript() {
return script;
}
/**
* Copy the current immutable object by setting a value for the {@link DecisionTableAst.Header#getId() id} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for id
* @return A modified copy of the {@code this} object
*/
public final ImmutableHeader withId(String value) {
String newValue = Objects.requireNonNull(value, "id");
if (this.id.equals(newValue)) return this;
return new ImmutableHeader(newValue, this.order, this.name, this.value, this.direction, this.script);
}
/**
* Copy the current immutable object by setting a value for the {@link DecisionTableAst.Header#getOrder() order} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for order
* @return A modified copy of the {@code this} object
*/
public final ImmutableHeader withOrder(Integer value) {
Integer newValue = Objects.requireNonNull(value, "order");
if (this.order.equals(newValue)) return this;
return new ImmutableHeader(this.id, newValue, this.name, this.value, this.direction, this.script);
}
/**
* Copy the current immutable object by setting a value for the {@link DecisionTableAst.Header#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 ImmutableHeader withName(String value) {
String newValue = Objects.requireNonNull(value, "name");
if (this.name.equals(newValue)) return this;
return new ImmutableHeader(this.id, this.order, newValue, this.value, this.direction, this.script);
}
/**
* Copy the current immutable object by setting a value for the {@link DecisionTableAst.Header#getValue() value} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for value
* @return A modified copy of the {@code this} object
*/
public final ImmutableHeader withValue(DataTypeRepository.ValueType value) {
if (this.value == value) return this;
DataTypeRepository.ValueType newValue = Objects.requireNonNull(value, "value");
if (this.value.equals(newValue)) return this;
return new ImmutableHeader(this.id, this.order, this.name, newValue, this.direction, this.script);
}
/**
* Copy the current immutable object by setting a value for the {@link DecisionTableAst.Header#getDirection() direction} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for direction
* @return A modified copy of the {@code this} object
*/
public final ImmutableHeader withDirection(DataTypeRepository.Direction value) {
if (this.direction == value) return this;
DataTypeRepository.Direction newValue = Objects.requireNonNull(value, "direction");
if (this.direction.equals(newValue)) return this;
return new ImmutableHeader(this.id, this.order, this.name, this.value, newValue, this.script);
}
/**
* Copy the current immutable object by setting a value for the {@link DecisionTableAst.Header#getScript() script} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for script (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableHeader withScript(@Nullable String value) {
if (Objects.equals(this.script, value)) return this;
return new ImmutableHeader(this.id, this.order, this.name, this.value, this.direction, value);
}
/**
* This instance is equal to all instances of {@code ImmutableHeader} 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 ImmutableHeader
&& equalTo((ImmutableHeader) another);
}
private boolean equalTo(ImmutableHeader another) {
return id.equals(another.id)
&& order.equals(another.order)
&& name.equals(another.name)
&& value.equals(another.value)
&& direction.equals(another.direction)
&& Objects.equals(script, another.script);
}
/**
* Computes a hash code from attributes: {@code id}, {@code order}, {@code name}, {@code value}, {@code direction}, {@code script}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + id.hashCode();
h += (h << 5) + order.hashCode();
h += (h << 5) + name.hashCode();
h += (h << 5) + value.hashCode();
h += (h << 5) + direction.hashCode();
h += (h << 5) + Objects.hashCode(script);
return h;
}
/**
* Prints the immutable value {@code Header} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Header")
.omitNullValues()
.add("id", id)
.add("order", order)
.add("name", name)
.add("value", value)
.add("direction", direction)
.add("script", script)
.toString();
}
/**
* Creates an immutable copy of a {@link DecisionTableAst.Header} 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 Header instance
*/
public static ImmutableHeader copyOf(DecisionTableAst.Header instance) {
if (instance instanceof ImmutableHeader) {
return (ImmutableHeader) instance;
}
return ImmutableHeader.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableHeader ImmutableHeader}.
*
* ImmutableHeader.builder()
* .id(String) // required {@link DecisionTableAst.Header#getId() id}
* .order(Integer) // required {@link DecisionTableAst.Header#getOrder() order}
* .name(String) // required {@link DecisionTableAst.Header#getName() name}
* .value(io.resys.wrench.assets.datatype.api.DataTypeRepository.ValueType) // required {@link DecisionTableAst.Header#getValue() value}
* .direction(io.resys.wrench.assets.datatype.api.DataTypeRepository.Direction) // required {@link DecisionTableAst.Header#getDirection() direction}
* .script(String | null) // nullable {@link DecisionTableAst.Header#getScript() script}
* .build();
*
* @return A new ImmutableHeader builder
*/
public static ImmutableHeader.Builder builder() {
return new ImmutableHeader.Builder();
}
/**
* Builds instances of type {@link ImmutableHeader ImmutableHeader}.
* 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 = "DecisionTableAst.Header", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private static final long INIT_BIT_ID = 0x1L;
private static final long INIT_BIT_ORDER = 0x2L;
private static final long INIT_BIT_NAME = 0x4L;
private static final long INIT_BIT_VALUE = 0x8L;
private static final long INIT_BIT_DIRECTION = 0x10L;
private long initBits = 0x1fL;
private @Nullable String id;
private @Nullable Integer order;
private @Nullable String name;
private @Nullable DataTypeRepository.ValueType value;
private @Nullable DataTypeRepository.Direction direction;
private @Nullable String script;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code Header} 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
*/
@CanIgnoreReturnValue
public final Builder from(DecisionTableAst.Header instance) {
Objects.requireNonNull(instance, "instance");
id(instance.getId());
order(instance.getOrder());
name(instance.getName());
value(instance.getValue());
direction(instance.getDirection());
@Nullable String scriptValue = instance.getScript();
if (scriptValue != null) {
script(scriptValue);
}
return this;
}
/**
* Initializes the value for the {@link DecisionTableAst.Header#getId() id} attribute.
* @param id The value for id
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder id(String id) {
this.id = Objects.requireNonNull(id, "id");
initBits &= ~INIT_BIT_ID;
return this;
}
/**
* Initializes the value for the {@link DecisionTableAst.Header#getOrder() order} attribute.
* @param order The value for order
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder order(Integer order) {
this.order = Objects.requireNonNull(order, "order");
initBits &= ~INIT_BIT_ORDER;
return this;
}
/**
* Initializes the value for the {@link DecisionTableAst.Header#getName() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes the value for the {@link DecisionTableAst.Header#getValue() value} attribute.
* @param value The value for value
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder value(DataTypeRepository.ValueType value) {
this.value = Objects.requireNonNull(value, "value");
initBits &= ~INIT_BIT_VALUE;
return this;
}
/**
* Initializes the value for the {@link DecisionTableAst.Header#getDirection() direction} attribute.
* @param direction The value for direction
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder direction(DataTypeRepository.Direction direction) {
this.direction = Objects.requireNonNull(direction, "direction");
initBits &= ~INIT_BIT_DIRECTION;
return this;
}
/**
* Initializes the value for the {@link DecisionTableAst.Header#getScript() script} attribute.
* @param script The value for script (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder script(@Nullable String script) {
this.script = script;
return this;
}
/**
* Builds a new {@link ImmutableHeader ImmutableHeader}.
* @return An immutable instance of Header
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableHeader build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableHeader(id, order, name, value, direction, script);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_ID) != 0) attributes.add("id");
if ((initBits & INIT_BIT_ORDER) != 0) attributes.add("order");
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
if ((initBits & INIT_BIT_VALUE) != 0) attributes.add("value");
if ((initBits & INIT_BIT_DIRECTION) != 0) attributes.add("direction");
return "Cannot build Header, some of required attributes are not set " + attributes;
}
}
}