com.neotys.neoload.model.repository.ImmutableConstantVariable Maven / Gradle / Ivy
package com.neotys.neoload.model.repository;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.CheckReturnValue;
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 ConstantVariable}.
*
* Use the builder to create immutable instances:
* {@code ImmutableConstantVariable.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ConstantVariable"})
@Deprecated
@Immutable
@CheckReturnValue
public final class ImmutableConstantVariable implements ConstantVariable {
private final String constantValue;
private final String name;
private final @Nullable String description;
private final @Nullable Variable.VariableOrder order;
private final Variable.VariablePolicy policy;
private final Variable.VariableScope scope;
private final @Nullable Variable.VariableNoValuesLeftBehavior noValuesLeftBehavior;
private ImmutableConstantVariable(
String constantValue,
String name,
@Nullable String description,
@Nullable Variable.VariableOrder order,
Variable.VariablePolicy policy,
Variable.VariableScope scope,
@Nullable Variable.VariableNoValuesLeftBehavior noValuesLeftBehavior) {
this.constantValue = constantValue;
this.name = name;
this.description = description;
this.order = order;
this.policy = policy;
this.scope = scope;
this.noValuesLeftBehavior = noValuesLeftBehavior;
}
/**
* @return The value of the {@code constantValue} attribute
*/
@Override
public String getConstantValue() {
return constantValue;
}
/**
* @return The value of the {@code name} attribute
*/
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code description} attribute
*/
@Override
public Optional getDescription() {
return Optional.ofNullable(description);
}
/**
* @return The value of the {@code order} attribute
*/
@Override
public Optional getOrder() {
return Optional.ofNullable(order);
}
/**
* @return The value of the {@code policy} attribute
*/
@Override
public Variable.VariablePolicy getPolicy() {
return policy;
}
/**
* @return The value of the {@code scope} attribute
*/
@Override
public Variable.VariableScope getScope() {
return scope;
}
/**
* @return The value of the {@code noValuesLeftBehavior} attribute
*/
@Override
public Optional getNoValuesLeftBehavior() {
return Optional.ofNullable(noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a value for the {@link ConstantVariable#getConstantValue() constantValue} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for constantValue
* @return A modified copy of the {@code this} object
*/
public final ImmutableConstantVariable withConstantValue(String value) {
if (this.constantValue.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "constantValue");
return new ImmutableConstantVariable(
newValue,
this.name,
this.description,
this.order,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a value for the {@link ConstantVariable#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 ImmutableConstantVariable withName(String value) {
if (this.name.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "name");
return new ImmutableConstantVariable(
this.constantValue,
newValue,
this.description,
this.order,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ConstantVariable#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableConstantVariable withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutableConstantVariable(
this.constantValue,
this.name,
newValue,
this.order,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ConstantVariable#getDescription() description} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableConstantVariable withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutableConstantVariable(
this.constantValue,
this.name,
value,
this.order,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ConstantVariable#getOrder() order} attribute.
* @param value The value for order
* @return A modified copy of {@code this} object
*/
public final ImmutableConstantVariable withOrder(Variable.VariableOrder value) {
@Nullable Variable.VariableOrder newValue = Objects.requireNonNull(value, "order");
if (this.order == newValue) return this;
return new ImmutableConstantVariable(
this.constantValue,
this.name,
this.description,
newValue,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ConstantVariable#getOrder() order} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for order
* @return A modified copy of {@code this} object
*/
public final ImmutableConstantVariable withOrder(Optional extends Variable.VariableOrder> optional) {
@Nullable Variable.VariableOrder value = optional.orElse(null);
if (Objects.equals(this.order, value)) return this;
return new ImmutableConstantVariable(
this.constantValue,
this.name,
this.description,
value,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a value for the {@link ConstantVariable#getPolicy() policy} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for policy
* @return A modified copy of the {@code this} object
*/
public final ImmutableConstantVariable withPolicy(Variable.VariablePolicy value) {
if (this.policy == value) return this;
Variable.VariablePolicy newValue = Objects.requireNonNull(value, "policy");
return new ImmutableConstantVariable(
this.constantValue,
this.name,
this.description,
this.order,
newValue,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a value for the {@link ConstantVariable#getScope() scope} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for scope
* @return A modified copy of the {@code this} object
*/
public final ImmutableConstantVariable withScope(Variable.VariableScope value) {
if (this.scope == value) return this;
Variable.VariableScope newValue = Objects.requireNonNull(value, "scope");
return new ImmutableConstantVariable(
this.constantValue,
this.name,
this.description,
this.order,
this.policy,
newValue,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ConstantVariable#getNoValuesLeftBehavior() noValuesLeftBehavior} attribute.
* @param value The value for noValuesLeftBehavior
* @return A modified copy of {@code this} object
*/
public final ImmutableConstantVariable withNoValuesLeftBehavior(Variable.VariableNoValuesLeftBehavior value) {
@Nullable Variable.VariableNoValuesLeftBehavior newValue = Objects.requireNonNull(value, "noValuesLeftBehavior");
if (this.noValuesLeftBehavior == newValue) return this;
return new ImmutableConstantVariable(this.constantValue, this.name, this.description, this.order, this.policy, this.scope, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ConstantVariable#getNoValuesLeftBehavior() noValuesLeftBehavior} attribute.
* An equality check is used on inner nullable value to prevent copying of the same value by returning {@code this}.
* @param optional A value for noValuesLeftBehavior
* @return A modified copy of {@code this} object
*/
public final ImmutableConstantVariable withNoValuesLeftBehavior(Optional extends Variable.VariableNoValuesLeftBehavior> optional) {
@Nullable Variable.VariableNoValuesLeftBehavior value = optional.orElse(null);
if (Objects.equals(this.noValuesLeftBehavior, value)) return this;
return new ImmutableConstantVariable(this.constantValue, this.name, this.description, this.order, this.policy, this.scope, value);
}
/**
* This instance is equal to all instances of {@code ImmutableConstantVariable} 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 ImmutableConstantVariable
&& equalTo((ImmutableConstantVariable) another);
}
private boolean equalTo(ImmutableConstantVariable another) {
return constantValue.equals(another.constantValue)
&& name.equals(another.name)
&& Objects.equals(description, another.description)
&& Objects.equals(order, another.order)
&& policy.equals(another.policy)
&& scope.equals(another.scope)
&& Objects.equals(noValuesLeftBehavior, another.noValuesLeftBehavior);
}
/**
* Computes a hash code from attributes: {@code constantValue}, {@code name}, {@code description}, {@code order}, {@code policy}, {@code scope}, {@code noValuesLeftBehavior}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + constantValue.hashCode();
h += (h << 5) + name.hashCode();
h += (h << 5) + Objects.hashCode(description);
h += (h << 5) + Objects.hashCode(order);
h += (h << 5) + policy.hashCode();
h += (h << 5) + scope.hashCode();
h += (h << 5) + Objects.hashCode(noValuesLeftBehavior);
return h;
}
/**
* Prints the immutable value {@code ConstantVariable} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ConstantVariable")
.omitNullValues()
.add("constantValue", constantValue)
.add("name", name)
.add("description", description)
.add("order", order)
.add("policy", policy)
.add("scope", scope)
.add("noValuesLeftBehavior", noValuesLeftBehavior)
.toString();
}
/**
* Creates an immutable copy of a {@link ConstantVariable} 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 ConstantVariable instance
*/
public static ImmutableConstantVariable copyOf(ConstantVariable instance) {
if (instance instanceof ImmutableConstantVariable) {
return (ImmutableConstantVariable) instance;
}
return ImmutableConstantVariable.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableConstantVariable ImmutableConstantVariable}.
* @return A new ImmutableConstantVariable builder
*/
public static ImmutableConstantVariable.Builder builder() {
return new ImmutableConstantVariable.Builder();
}
/**
* Builds instances of type {@link ImmutableConstantVariable ImmutableConstantVariable}.
* 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
public static final class Builder {
private static final long INIT_BIT_CONSTANT_VALUE = 0x1L;
private static final long INIT_BIT_NAME = 0x2L;
private static final long INIT_BIT_POLICY = 0x4L;
private static final long INIT_BIT_SCOPE = 0x8L;
private long initBits = 0xfL;
private @Nullable String constantValue;
private @Nullable String name;
private @Nullable String description;
private @Nullable Variable.VariableOrder order;
private @Nullable Variable.VariablePolicy policy;
private @Nullable Variable.VariableScope scope;
private @Nullable Variable.VariableNoValuesLeftBehavior noValuesLeftBehavior;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.repository.Variable} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(Variable instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.repository.ConstantVariable} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(ConstantVariable instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof Variable) {
Variable instance = (Variable) object;
name(instance.getName());
Optional noValuesLeftBehaviorOptional = instance.getNoValuesLeftBehavior();
if (noValuesLeftBehaviorOptional.isPresent()) {
noValuesLeftBehavior(noValuesLeftBehaviorOptional);
}
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
description(descriptionOptional);
}
scope(instance.getScope());
Optional orderOptional = instance.getOrder();
if (orderOptional.isPresent()) {
order(orderOptional);
}
policy(instance.getPolicy());
}
if (object instanceof ConstantVariable) {
ConstantVariable instance = (ConstantVariable) object;
constantValue(instance.getConstantValue());
}
}
/**
* Initializes the value for the {@link ConstantVariable#getConstantValue() constantValue} attribute.
* @param constantValue The value for constantValue
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder constantValue(String constantValue) {
this.constantValue = Objects.requireNonNull(constantValue, "constantValue");
initBits &= ~INIT_BIT_CONSTANT_VALUE;
return this;
}
/**
* Initializes the value for the {@link ConstantVariable#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 optional value {@link ConstantVariable#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder description(String description) {
this.description = Objects.requireNonNull(description, "description");
return this;
}
/**
* Initializes the optional value {@link ConstantVariable#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder description(Optional description) {
this.description = description.orElse(null);
return this;
}
/**
* Initializes the optional value {@link ConstantVariable#getOrder() order} to order.
* @param order The value for order
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder order(Variable.VariableOrder order) {
this.order = Objects.requireNonNull(order, "order");
return this;
}
/**
* Initializes the optional value {@link ConstantVariable#getOrder() order} to order.
* @param order The value for order
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder order(Optional extends Variable.VariableOrder> order) {
this.order = order.orElse(null);
return this;
}
/**
* Initializes the value for the {@link ConstantVariable#getPolicy() policy} attribute.
* @param policy The value for policy
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder policy(Variable.VariablePolicy policy) {
this.policy = Objects.requireNonNull(policy, "policy");
initBits &= ~INIT_BIT_POLICY;
return this;
}
/**
* Initializes the value for the {@link ConstantVariable#getScope() scope} attribute.
* @param scope The value for scope
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder scope(Variable.VariableScope scope) {
this.scope = Objects.requireNonNull(scope, "scope");
initBits &= ~INIT_BIT_SCOPE;
return this;
}
/**
* Initializes the optional value {@link ConstantVariable#getNoValuesLeftBehavior() noValuesLeftBehavior} to noValuesLeftBehavior.
* @param noValuesLeftBehavior The value for noValuesLeftBehavior
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder noValuesLeftBehavior(Variable.VariableNoValuesLeftBehavior noValuesLeftBehavior) {
this.noValuesLeftBehavior = Objects.requireNonNull(noValuesLeftBehavior, "noValuesLeftBehavior");
return this;
}
/**
* Initializes the optional value {@link ConstantVariable#getNoValuesLeftBehavior() noValuesLeftBehavior} to noValuesLeftBehavior.
* @param noValuesLeftBehavior The value for noValuesLeftBehavior
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder noValuesLeftBehavior(Optional extends Variable.VariableNoValuesLeftBehavior> noValuesLeftBehavior) {
this.noValuesLeftBehavior = noValuesLeftBehavior.orElse(null);
return this;
}
/**
* Builds a new {@link ImmutableConstantVariable ImmutableConstantVariable}.
* @return An immutable instance of ConstantVariable
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableConstantVariable build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableConstantVariable(constantValue, name, description, order, policy, scope, noValuesLeftBehavior);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_CONSTANT_VALUE) != 0) attributes.add("constantValue");
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
if ((initBits & INIT_BIT_POLICY) != 0) attributes.add("policy");
if ((initBits & INIT_BIT_SCOPE) != 0) attributes.add("scope");
return "Cannot build ConstantVariable, some of required attributes are not set " + attributes;
}
}
}