com.neotys.neoload.model.v3.project.variable.ImmutableJavaScriptVariable Maven / Gradle / Ivy
package com.neotys.neoload.model.v3.project.variable;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.neotys.neoload.model.v3.project.Element;
import java.util.ArrayList;
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 JavaScriptVariable}.
*
* Use the builder to create immutable instances:
* {@code new JavaScriptVariable.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "JavaScriptVariable"})
@Immutable
@CheckReturnValue
public final class ImmutableJavaScriptVariable
implements JavaScriptVariable {
private final String script;
private final Variable.ChangePolicy changePolicy;
private final Variable.Scope scope;
private final Variable.Order order;
private final Variable.OutOfValue outOfValue;
private final String name;
private final @Nullable String description;
private ImmutableJavaScriptVariable(ImmutableJavaScriptVariable.Builder builder) {
this.script = builder.script;
this.name = builder.name;
this.description = builder.description;
if (builder.changePolicy != null) {
initShim.changePolicy(builder.changePolicy);
}
if (builder.scope != null) {
initShim.scope(builder.scope);
}
if (builder.order != null) {
initShim.order(builder.order);
}
if (builder.outOfValue != null) {
initShim.outOfValue(builder.outOfValue);
}
this.changePolicy = initShim.getChangePolicy();
this.scope = initShim.getScope();
this.order = initShim.getOrder();
this.outOfValue = initShim.getOutOfValue();
this.initShim = null;
}
private ImmutableJavaScriptVariable(
String script,
Variable.ChangePolicy changePolicy,
Variable.Scope scope,
Variable.Order order,
Variable.OutOfValue outOfValue,
String name,
@Nullable String description) {
this.script = script;
this.changePolicy = changePolicy;
this.scope = scope;
this.order = order;
this.outOfValue = outOfValue;
this.name = name;
this.description = description;
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 Variable.ChangePolicy changePolicy;
private int changePolicyBuildStage;
Variable.ChangePolicy getChangePolicy() {
if (changePolicyBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (changePolicyBuildStage == STAGE_UNINITIALIZED) {
changePolicyBuildStage = STAGE_INITIALIZING;
this.changePolicy = Objects.requireNonNull(getChangePolicyInitialize(), "changePolicy");
changePolicyBuildStage = STAGE_INITIALIZED;
}
return this.changePolicy;
}
void changePolicy(Variable.ChangePolicy changePolicy) {
this.changePolicy = changePolicy;
changePolicyBuildStage = STAGE_INITIALIZED;
}
private Variable.Scope scope;
private int scopeBuildStage;
Variable.Scope getScope() {
if (scopeBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (scopeBuildStage == STAGE_UNINITIALIZED) {
scopeBuildStage = STAGE_INITIALIZING;
this.scope = Objects.requireNonNull(getScopeInitialize(), "scope");
scopeBuildStage = STAGE_INITIALIZED;
}
return this.scope;
}
void scope(Variable.Scope scope) {
this.scope = scope;
scopeBuildStage = STAGE_INITIALIZED;
}
private Variable.Order order;
private int orderBuildStage;
Variable.Order getOrder() {
if (orderBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (orderBuildStage == STAGE_UNINITIALIZED) {
orderBuildStage = STAGE_INITIALIZING;
this.order = Objects.requireNonNull(getOrderInitialize(), "order");
orderBuildStage = STAGE_INITIALIZED;
}
return this.order;
}
void order(Variable.Order order) {
this.order = order;
orderBuildStage = STAGE_INITIALIZED;
}
private Variable.OutOfValue outOfValue;
private int outOfValueBuildStage;
Variable.OutOfValue getOutOfValue() {
if (outOfValueBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (outOfValueBuildStage == STAGE_UNINITIALIZED) {
outOfValueBuildStage = STAGE_INITIALIZING;
this.outOfValue = Objects.requireNonNull(getOutOfValueInitialize(), "outOfValue");
outOfValueBuildStage = STAGE_INITIALIZED;
}
return this.outOfValue;
}
void outOfValue(Variable.OutOfValue outOfValue) {
this.outOfValue = outOfValue;
outOfValueBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
ArrayList attributes = Lists.newArrayList();
if (changePolicyBuildStage == STAGE_INITIALIZING) attributes.add("changePolicy");
if (scopeBuildStage == STAGE_INITIALIZING) attributes.add("scope");
if (orderBuildStage == STAGE_INITIALIZING) attributes.add("order");
if (outOfValueBuildStage == STAGE_INITIALIZING) attributes.add("outOfValue");
return "Cannot build JavaScriptVariable, attribute initializers form cycle" + attributes;
}
}
private Variable.ChangePolicy getChangePolicyInitialize() {
return JavaScriptVariable.super.getChangePolicy();
}
private Variable.Scope getScopeInitialize() {
return JavaScriptVariable.super.getScope();
}
private Variable.Order getOrderInitialize() {
return JavaScriptVariable.super.getOrder();
}
private Variable.OutOfValue getOutOfValueInitialize() {
return JavaScriptVariable.super.getOutOfValue();
}
/**
* @return The value of the {@code script} attribute
*/
@JsonProperty("script")
@Override
public String getScript() {
return script;
}
/**
* @return The value of the {@code changePolicy} attribute
*/
@JsonProperty("change_policy")
@Override
public Variable.ChangePolicy getChangePolicy() {
InitShim shim = this.initShim;
return shim != null
? shim.getChangePolicy()
: this.changePolicy;
}
/**
* @return The value of the {@code scope} attribute
*/
@JsonProperty("scope")
@Override
public Variable.Scope getScope() {
InitShim shim = this.initShim;
return shim != null
? shim.getScope()
: this.scope;
}
/**
* @return The value of the {@code order} attribute
*/
@JsonProperty("order")
@Override
public Variable.Order getOrder() {
InitShim shim = this.initShim;
return shim != null
? shim.getOrder()
: this.order;
}
/**
* @return The value of the {@code outOfValue} attribute
*/
@JsonProperty("out_of_value")
@Override
public Variable.OutOfValue getOutOfValue() {
InitShim shim = this.initShim;
return shim != null
? shim.getOutOfValue()
: this.outOfValue;
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code description} attribute
*/
@JsonProperty("description")
@Override
public Optional getDescription() {
return Optional.ofNullable(description);
}
/**
* Copy the current immutable object by setting a value for the {@link JavaScriptVariable#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 ImmutableJavaScriptVariable withScript(String value) {
if (Objects.equals(this.script, value)) return this;
return new ImmutableJavaScriptVariable(value, this.changePolicy, this.scope, this.order, this.outOfValue, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link JavaScriptVariable#getChangePolicy() changePolicy} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for changePolicy
* @return A modified copy of the {@code this} object
*/
public final ImmutableJavaScriptVariable withChangePolicy(Variable.ChangePolicy value) {
if (this.changePolicy == value) return this;
Variable.ChangePolicy newValue = Objects.requireNonNull(value, "changePolicy");
return new ImmutableJavaScriptVariable(this.script, newValue, this.scope, this.order, this.outOfValue, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link JavaScriptVariable#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 ImmutableJavaScriptVariable withScope(Variable.Scope value) {
if (this.scope == value) return this;
Variable.Scope newValue = Objects.requireNonNull(value, "scope");
return new ImmutableJavaScriptVariable(
this.script,
this.changePolicy,
newValue,
this.order,
this.outOfValue,
this.name,
this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link JavaScriptVariable#getOrder() order} attribute.
* A value equality check is 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 ImmutableJavaScriptVariable withOrder(Variable.Order value) {
if (this.order == value) return this;
Variable.Order newValue = Objects.requireNonNull(value, "order");
return new ImmutableJavaScriptVariable(
this.script,
this.changePolicy,
this.scope,
newValue,
this.outOfValue,
this.name,
this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link JavaScriptVariable#getOutOfValue() outOfValue} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for outOfValue
* @return A modified copy of the {@code this} object
*/
public final ImmutableJavaScriptVariable withOutOfValue(Variable.OutOfValue value) {
if (this.outOfValue == value) return this;
Variable.OutOfValue newValue = Objects.requireNonNull(value, "outOfValue");
return new ImmutableJavaScriptVariable(this.script, this.changePolicy, this.scope, this.order, newValue, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link JavaScriptVariable#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 (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableJavaScriptVariable withName(String value) {
if (Objects.equals(this.name, value)) return this;
return new ImmutableJavaScriptVariable(
this.script,
this.changePolicy,
this.scope,
this.order,
this.outOfValue,
value,
this.description);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link JavaScriptVariable#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableJavaScriptVariable withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutableJavaScriptVariable(this.script, this.changePolicy, this.scope, this.order, this.outOfValue, this.name, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link JavaScriptVariable#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 ImmutableJavaScriptVariable withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutableJavaScriptVariable(this.script, this.changePolicy, this.scope, this.order, this.outOfValue, this.name, value);
}
/**
* This instance is equal to all instances of {@code ImmutableJavaScriptVariable} 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 ImmutableJavaScriptVariable
&& equalTo((ImmutableJavaScriptVariable) another);
}
private boolean equalTo(ImmutableJavaScriptVariable another) {
return Objects.equals(script, another.script)
&& changePolicy.equals(another.changePolicy)
&& scope.equals(another.scope)
&& order.equals(another.order)
&& outOfValue.equals(another.outOfValue)
&& Objects.equals(name, another.name)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code script}, {@code changePolicy}, {@code scope}, {@code order}, {@code outOfValue}, {@code name}, {@code description}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(script);
h += (h << 5) + changePolicy.hashCode();
h += (h << 5) + scope.hashCode();
h += (h << 5) + order.hashCode();
h += (h << 5) + outOfValue.hashCode();
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + Objects.hashCode(description);
return h;
}
/**
* Prints the immutable value {@code JavaScriptVariable} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("JavaScriptVariable")
.omitNullValues()
.add("script", script)
.add("changePolicy", changePolicy)
.add("scope", scope)
.add("order", order)
.add("outOfValue", outOfValue)
.add("name", name)
.add("description", description)
.toString();
}
/**
* Utility type used to correctly read immutable object from JSON representation.
* @deprecated Do not use this type directly, it exists only for the Jackson-binding infrastructure
*/
@Deprecated
@JsonDeserialize
@JsonTypeInfo(use=JsonTypeInfo.Id.NONE)
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements JavaScriptVariable {
@Nullable String script;
@Nullable Variable.ChangePolicy changePolicy;
@Nullable Variable.Scope scope;
@Nullable Variable.Order order;
@Nullable Variable.OutOfValue outOfValue;
@Nullable String name;
Optional description = Optional.empty();
@JsonProperty("script")
public void setScript(String script) {
this.script = script;
}
@JsonProperty("change_policy")
public void setChangePolicy(Variable.ChangePolicy changePolicy) {
this.changePolicy = changePolicy;
}
@JsonProperty("scope")
public void setScope(Variable.Scope scope) {
this.scope = scope;
}
@JsonProperty("order")
public void setOrder(Variable.Order order) {
this.order = order;
}
@JsonProperty("out_of_value")
public void setOutOfValue(Variable.OutOfValue outOfValue) {
this.outOfValue = outOfValue;
}
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("description")
public void setDescription(Optional description) {
this.description = description;
}
@Override
public Element withName(String of) { throw new UnsupportedOperationException(); }
@Override
public String getScript() { throw new UnsupportedOperationException(); }
@Override
public Variable.ChangePolicy getChangePolicy() { throw new UnsupportedOperationException(); }
@Override
public Variable.Scope getScope() { throw new UnsupportedOperationException(); }
@Override
public Variable.Order getOrder() { throw new UnsupportedOperationException(); }
@Override
public Variable.OutOfValue getOutOfValue() { throw new UnsupportedOperationException(); }
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public Optional getDescription() { throw new UnsupportedOperationException(); }
}
/**
* @param json A JSON-bindable data structure
* @return An immutable value type
* @deprecated Do not use this method directly, it exists only for the Jackson-binding infrastructure
*/
@Deprecated
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
static ImmutableJavaScriptVariable fromJson(Json json) {
JavaScriptVariable.Builder builder = new JavaScriptVariable.Builder();
if (json.script != null) {
builder.script(json.script);
}
if (json.changePolicy != null) {
builder.changePolicy(json.changePolicy);
}
if (json.scope != null) {
builder.scope(json.scope);
}
if (json.order != null) {
builder.order(json.order);
}
if (json.outOfValue != null) {
builder.outOfValue(json.outOfValue);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.description != null) {
builder.description(json.description);
}
return (ImmutableJavaScriptVariable) builder.build();
}
/**
* Creates an immutable copy of a {@link JavaScriptVariable} 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 JavaScriptVariable instance
*/
public static ImmutableJavaScriptVariable copyOf(JavaScriptVariable instance) {
if (instance instanceof ImmutableJavaScriptVariable) {
return (ImmutableJavaScriptVariable) instance;
}
return new JavaScriptVariable.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableJavaScriptVariable ImmutableJavaScriptVariable}.
* 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 class Builder {
private @Nullable String script;
private @Nullable Variable.ChangePolicy changePolicy;
private @Nullable Variable.Scope scope;
private @Nullable Variable.Order order;
private @Nullable Variable.OutOfValue outOfValue;
private @Nullable String name;
private @Nullable String description;
/**
* Creates a builder for {@link ImmutableJavaScriptVariable ImmutableJavaScriptVariable} instances.
*/
public Builder() {
if (!(this instanceof JavaScriptVariable.Builder)) {
throw new UnsupportedOperationException("Use: new JavaScriptVariable.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.variable.JavaScriptVariable} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final JavaScriptVariable.Builder from(JavaScriptVariable instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (JavaScriptVariable.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.Element} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final JavaScriptVariable.Builder from(Element instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (JavaScriptVariable.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.variable.Variable} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final JavaScriptVariable.Builder from(Variable instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (JavaScriptVariable.Builder) this;
}
private void from(Object object) {
if (object instanceof JavaScriptVariable) {
JavaScriptVariable instance = (JavaScriptVariable) object;
String scriptValue = instance.getScript();
if (scriptValue != null) {
script(scriptValue);
}
}
if (object instanceof Element) {
Element instance = (Element) object;
String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
description(descriptionOptional);
}
}
if (object instanceof Variable) {
Variable instance = (Variable) object;
changePolicy(instance.getChangePolicy());
scope(instance.getScope());
outOfValue(instance.getOutOfValue());
order(instance.getOrder());
}
}
/**
* Initializes the value for the {@link JavaScriptVariable#getScript() script} attribute.
* @param script The value for script (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("script")
public final JavaScriptVariable.Builder script(String script) {
this.script = script;
return (JavaScriptVariable.Builder) this;
}
/**
* Initializes the value for the {@link JavaScriptVariable#getChangePolicy() changePolicy} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link JavaScriptVariable#getChangePolicy() changePolicy}.
* @param changePolicy The value for changePolicy
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("change_policy")
public final JavaScriptVariable.Builder changePolicy(Variable.ChangePolicy changePolicy) {
this.changePolicy = Objects.requireNonNull(changePolicy, "changePolicy");
return (JavaScriptVariable.Builder) this;
}
/**
* Initializes the value for the {@link JavaScriptVariable#getScope() scope} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link JavaScriptVariable#getScope() scope}.
* @param scope The value for scope
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("scope")
public final JavaScriptVariable.Builder scope(Variable.Scope scope) {
this.scope = Objects.requireNonNull(scope, "scope");
return (JavaScriptVariable.Builder) this;
}
/**
* Initializes the value for the {@link JavaScriptVariable#getOrder() order} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link JavaScriptVariable#getOrder() order}.
* @param order The value for order
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("order")
public final JavaScriptVariable.Builder order(Variable.Order order) {
this.order = Objects.requireNonNull(order, "order");
return (JavaScriptVariable.Builder) this;
}
/**
* Initializes the value for the {@link JavaScriptVariable#getOutOfValue() outOfValue} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link JavaScriptVariable#getOutOfValue() outOfValue}.
* @param outOfValue The value for outOfValue
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("out_of_value")
public final JavaScriptVariable.Builder outOfValue(Variable.OutOfValue outOfValue) {
this.outOfValue = Objects.requireNonNull(outOfValue, "outOfValue");
return (JavaScriptVariable.Builder) this;
}
/**
* Initializes the value for the {@link JavaScriptVariable#getName() name} attribute.
* @param name The value for name (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("name")
public final JavaScriptVariable.Builder name(String name) {
this.name = name;
return (JavaScriptVariable.Builder) this;
}
/**
* Initializes the optional value {@link JavaScriptVariable#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final JavaScriptVariable.Builder description(String description) {
this.description = Objects.requireNonNull(description, "description");
return (JavaScriptVariable.Builder) this;
}
/**
* Initializes the optional value {@link JavaScriptVariable#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("description")
public final JavaScriptVariable.Builder description(Optional description) {
this.description = description.orElse(null);
return (JavaScriptVariable.Builder) this;
}
/**
* Builds a new {@link ImmutableJavaScriptVariable ImmutableJavaScriptVariable}.
* @return An immutable instance of JavaScriptVariable
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableJavaScriptVariable build() {
return new ImmutableJavaScriptVariable(this);
}
}
}