![JAR search and dependency download from the Maven repository](/logo.png)
com.neotys.neoload.model.repository.ImmutableRandomNumberVariable 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 RandomNumberVariable}.
*
* Use the builder to create immutable instances:
* {@code ImmutableRandomNumberVariable.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "RandomNumberVariable"})
@Deprecated
@Immutable
@CheckReturnValue
public final class ImmutableRandomNumberVariable
implements RandomNumberVariable {
private final int minValue;
private final int maxValue;
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 ImmutableRandomNumberVariable(
int minValue,
int maxValue,
String name,
@Nullable String description,
@Nullable Variable.VariableOrder order,
Variable.VariablePolicy policy,
Variable.VariableScope scope,
@Nullable Variable.VariableNoValuesLeftBehavior noValuesLeftBehavior) {
this.minValue = minValue;
this.maxValue = maxValue;
this.name = name;
this.description = description;
this.order = order;
this.policy = policy;
this.scope = scope;
this.noValuesLeftBehavior = noValuesLeftBehavior;
}
/**
* @return The value of the {@code minValue} attribute
*/
@Override
public int getMinValue() {
return minValue;
}
/**
* @return The value of the {@code maxValue} attribute
*/
@Override
public int getMaxValue() {
return maxValue;
}
/**
* @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 RandomNumberVariable#getMinValue() minValue} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for minValue
* @return A modified copy of the {@code this} object
*/
public final ImmutableRandomNumberVariable withMinValue(int value) {
if (this.minValue == value) return this;
return new ImmutableRandomNumberVariable(
value,
this.maxValue,
this.name,
this.description,
this.order,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a value for the {@link RandomNumberVariable#getMaxValue() maxValue} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for maxValue
* @return A modified copy of the {@code this} object
*/
public final ImmutableRandomNumberVariable withMaxValue(int value) {
if (this.maxValue == value) return this;
return new ImmutableRandomNumberVariable(
this.minValue,
value,
this.name,
this.description,
this.order,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a value for the {@link RandomNumberVariable#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 ImmutableRandomNumberVariable withName(String value) {
if (this.name.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "name");
return new ImmutableRandomNumberVariable(
this.minValue,
this.maxValue,
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 RandomNumberVariable#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableRandomNumberVariable withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutableRandomNumberVariable(
this.minValue,
this.maxValue,
this.name,
newValue,
this.order,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting an optional value for the {@link RandomNumberVariable#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 ImmutableRandomNumberVariable withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutableRandomNumberVariable(
this.minValue,
this.maxValue,
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 RandomNumberVariable#getOrder() order} attribute.
* @param value The value for order
* @return A modified copy of {@code this} object
*/
public final ImmutableRandomNumberVariable withOrder(Variable.VariableOrder value) {
@Nullable Variable.VariableOrder newValue = Objects.requireNonNull(value, "order");
if (this.order == newValue) return this;
return new ImmutableRandomNumberVariable(
this.minValue,
this.maxValue,
this.name,
this.description,
newValue,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting an optional value for the {@link RandomNumberVariable#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 ImmutableRandomNumberVariable withOrder(Optional extends Variable.VariableOrder> optional) {
@Nullable Variable.VariableOrder value = optional.orElse(null);
if (Objects.equals(this.order, value)) return this;
return new ImmutableRandomNumberVariable(
this.minValue,
this.maxValue,
this.name,
this.description,
value,
this.policy,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a value for the {@link RandomNumberVariable#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 ImmutableRandomNumberVariable withPolicy(Variable.VariablePolicy value) {
if (this.policy == value) return this;
Variable.VariablePolicy newValue = Objects.requireNonNull(value, "policy");
return new ImmutableRandomNumberVariable(
this.minValue,
this.maxValue,
this.name,
this.description,
this.order,
newValue,
this.scope,
this.noValuesLeftBehavior);
}
/**
* Copy the current immutable object by setting a value for the {@link RandomNumberVariable#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 ImmutableRandomNumberVariable withScope(Variable.VariableScope value) {
if (this.scope == value) return this;
Variable.VariableScope newValue = Objects.requireNonNull(value, "scope");
return new ImmutableRandomNumberVariable(
this.minValue,
this.maxValue,
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 RandomNumberVariable#getNoValuesLeftBehavior() noValuesLeftBehavior} attribute.
* @param value The value for noValuesLeftBehavior
* @return A modified copy of {@code this} object
*/
public final ImmutableRandomNumberVariable withNoValuesLeftBehavior(Variable.VariableNoValuesLeftBehavior value) {
@Nullable Variable.VariableNoValuesLeftBehavior newValue = Objects.requireNonNull(value, "noValuesLeftBehavior");
if (this.noValuesLeftBehavior == newValue) return this;
return new ImmutableRandomNumberVariable(
this.minValue,
this.maxValue,
this.name,
this.description,
this.order,
this.policy,
this.scope,
newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link RandomNumberVariable#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 ImmutableRandomNumberVariable withNoValuesLeftBehavior(Optional extends Variable.VariableNoValuesLeftBehavior> optional) {
@Nullable Variable.VariableNoValuesLeftBehavior value = optional.orElse(null);
if (Objects.equals(this.noValuesLeftBehavior, value)) return this;
return new ImmutableRandomNumberVariable(
this.minValue,
this.maxValue,
this.name,
this.description,
this.order,
this.policy,
this.scope,
value);
}
/**
* This instance is equal to all instances of {@code ImmutableRandomNumberVariable} 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 ImmutableRandomNumberVariable
&& equalTo((ImmutableRandomNumberVariable) another);
}
private boolean equalTo(ImmutableRandomNumberVariable another) {
return minValue == another.minValue
&& maxValue == another.maxValue
&& 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 minValue}, {@code maxValue}, {@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) + minValue;
h += (h << 5) + maxValue;
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 RandomNumberVariable} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("RandomNumberVariable")
.omitNullValues()
.add("minValue", minValue)
.add("maxValue", maxValue)
.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 RandomNumberVariable} 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 RandomNumberVariable instance
*/
public static ImmutableRandomNumberVariable copyOf(RandomNumberVariable instance) {
if (instance instanceof ImmutableRandomNumberVariable) {
return (ImmutableRandomNumberVariable) instance;
}
return ImmutableRandomNumberVariable.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableRandomNumberVariable ImmutableRandomNumberVariable}.
* @return A new ImmutableRandomNumberVariable builder
*/
public static ImmutableRandomNumberVariable.Builder builder() {
return new ImmutableRandomNumberVariable.Builder();
}
/**
* Builds instances of type {@link ImmutableRandomNumberVariable ImmutableRandomNumberVariable}.
* 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_MIN_VALUE = 0x1L;
private static final long INIT_BIT_MAX_VALUE = 0x2L;
private static final long INIT_BIT_NAME = 0x4L;
private static final long INIT_BIT_POLICY = 0x8L;
private static final long INIT_BIT_SCOPE = 0x10L;
private long initBits = 0x1fL;
private int minValue;
private int maxValue;
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.RandomNumberVariable} 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(RandomNumberVariable 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 RandomNumberVariable) {
RandomNumberVariable instance = (RandomNumberVariable) object;
minValue(instance.getMinValue());
maxValue(instance.getMaxValue());
}
}
/**
* Initializes the value for the {@link RandomNumberVariable#getMinValue() minValue} attribute.
* @param minValue The value for minValue
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder minValue(int minValue) {
this.minValue = minValue;
initBits &= ~INIT_BIT_MIN_VALUE;
return this;
}
/**
* Initializes the value for the {@link RandomNumberVariable#getMaxValue() maxValue} attribute.
* @param maxValue The value for maxValue
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder maxValue(int maxValue) {
this.maxValue = maxValue;
initBits &= ~INIT_BIT_MAX_VALUE;
return this;
}
/**
* Initializes the value for the {@link RandomNumberVariable#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 RandomNumberVariable#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 RandomNumberVariable#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 RandomNumberVariable#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 RandomNumberVariable#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 RandomNumberVariable#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 RandomNumberVariable#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 RandomNumberVariable#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 RandomNumberVariable#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 ImmutableRandomNumberVariable ImmutableRandomNumberVariable}.
* @return An immutable instance of RandomNumberVariable
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableRandomNumberVariable build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableRandomNumberVariable(minValue, maxValue, name, description, order, policy, scope, noValuesLeftBehavior);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_MIN_VALUE) != 0) attributes.add("minValue");
if ((initBits & INIT_BIT_MAX_VALUE) != 0) attributes.add("maxValue");
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 RandomNumberVariable, some of required attributes are not set " + attributes;
}
}
}