com.neotys.neoload.model.v3.project.userpath.ImmutableWhile Maven / Gradle / Ivy
package com.neotys.neoload.model.v3.project.userpath;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.neotys.neoload.model.v3.binding.serializer.MatchDeserializer;
import com.neotys.neoload.model.v3.binding.serializer.StepsDeserializer;
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;
import javax.validation.Valid;
/**
* Immutable implementation of {@link While}.
*
* Use the builder to create immutable instances:
* {@code new While.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "While"})
@Immutable
@CheckReturnValue
public final class ImmutableWhile implements While {
private final String name;
private final ImmutableList conditions;
private final Match match;
private final ImmutableList steps;
private final @Nullable String description;
private ImmutableWhile(ImmutableWhile.Builder builder) {
this.conditions = builder.conditions.build();
this.steps = builder.steps.build();
this.description = builder.description;
if (builder.name != null) {
initShim.name(builder.name);
}
if (builder.match != null) {
initShim.match(builder.match);
}
this.name = initShim.getName();
this.match = initShim.getMatch();
this.initShim = null;
}
private ImmutableWhile(
String name,
ImmutableList conditions,
Match match,
ImmutableList steps,
@Nullable String description) {
this.name = name;
this.conditions = conditions;
this.match = match;
this.steps = steps;
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 String name;
private int nameBuildStage;
String getName() {
if (nameBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (nameBuildStage == STAGE_UNINITIALIZED) {
nameBuildStage = STAGE_INITIALIZING;
this.name = Objects.requireNonNull(getNameInitialize(), "name");
nameBuildStage = STAGE_INITIALIZED;
}
return this.name;
}
void name(String name) {
this.name = name;
nameBuildStage = STAGE_INITIALIZED;
}
private Match match;
private int matchBuildStage;
Match getMatch() {
if (matchBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (matchBuildStage == STAGE_UNINITIALIZED) {
matchBuildStage = STAGE_INITIALIZING;
this.match = Objects.requireNonNull(getMatchInitialize(), "match");
matchBuildStage = STAGE_INITIALIZED;
}
return this.match;
}
void match(Match match) {
this.match = match;
matchBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
ArrayList attributes = Lists.newArrayList();
if (nameBuildStage == STAGE_INITIALIZING) attributes.add("name");
if (matchBuildStage == STAGE_INITIALIZING) attributes.add("match");
return "Cannot build While, attribute initializers form cycle" + attributes;
}
}
private String getNameInitialize() {
return While.super.getName();
}
private Match getMatchInitialize() {
return While.super.getMatch();
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public String getName() {
InitShim shim = this.initShim;
return shim != null
? shim.getName()
: this.name;
}
/**
* @return The value of the {@code conditions} attribute
*/
@JsonProperty("conditions")
@Override
public ImmutableList getConditions() {
return conditions;
}
/**
* @return The value of the {@code match} attribute
*/
@JsonProperty("match")
@JsonDeserialize(using = MatchDeserializer.class)
@Override
public Match getMatch() {
InitShim shim = this.initShim;
return shim != null
? shim.getMatch()
: this.match;
}
/**
* @return The value of the {@code steps} attribute
*/
@JsonProperty("steps")
@JsonDeserialize(using = StepsDeserializer.class)
@Override
public ImmutableList getSteps() {
return steps;
}
/**
* @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 While#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 ImmutableWhile withName(String value) {
if (this.name.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "name");
return new ImmutableWhile(newValue, this.conditions, this.match, this.steps, this.description);
}
/**
* Copy the current immutable object with elements that replace the content of {@link While#getConditions() conditions}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableWhile withConditions(Condition... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableWhile(this.name, newValue, this.match, this.steps, this.description);
}
/**
* Copy the current immutable object with elements that replace the content of {@link While#getConditions() conditions}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of conditions elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableWhile withConditions(Iterable extends Condition> elements) {
if (this.conditions == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableWhile(this.name, newValue, this.match, this.steps, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link While#getMatch() match} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for match
* @return A modified copy of the {@code this} object
*/
public final ImmutableWhile withMatch(Match value) {
if (this.match == value) return this;
Match newValue = Objects.requireNonNull(value, "match");
return new ImmutableWhile(this.name, this.conditions, newValue, this.steps, this.description);
}
/**
* Copy the current immutable object with elements that replace the content of {@link While#getSteps() steps}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableWhile withSteps(Step... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableWhile(this.name, this.conditions, this.match, newValue, this.description);
}
/**
* Copy the current immutable object with elements that replace the content of {@link While#getSteps() steps}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of steps elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableWhile withSteps(Iterable extends Step> elements) {
if (this.steps == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableWhile(this.name, this.conditions, this.match, newValue, this.description);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link While#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableWhile withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutableWhile(this.name, this.conditions, this.match, this.steps, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link While#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 ImmutableWhile withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutableWhile(this.name, this.conditions, this.match, this.steps, value);
}
/**
* This instance is equal to all instances of {@code ImmutableWhile} 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 ImmutableWhile
&& equalTo((ImmutableWhile) another);
}
private boolean equalTo(ImmutableWhile another) {
return name.equals(another.name)
&& conditions.equals(another.conditions)
&& match.equals(another.match)
&& steps.equals(another.steps)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code name}, {@code conditions}, {@code match}, {@code steps}, {@code description}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + name.hashCode();
h += (h << 5) + conditions.hashCode();
h += (h << 5) + match.hashCode();
h += (h << 5) + steps.hashCode();
h += (h << 5) + Objects.hashCode(description);
return h;
}
/**
* Prints the immutable value {@code While} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("While")
.omitNullValues()
.add("name", name)
.add("conditions", conditions)
.add("match", match)
.add("steps", steps)
.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
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements While {
@Nullable String name;
java.util.@Valid List conditions = ImmutableList.of();
@Nullable Match match;
java.util.@Valid List steps = ImmutableList.of();
Optional description = Optional.empty();
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("conditions")
public void setConditions(java.util.@Valid List conditions) {
this.conditions = conditions;
}
@JsonProperty("match")
@JsonDeserialize(using = MatchDeserializer.class)
public void setMatch(Match match) {
this.match = match;
}
@JsonProperty("steps")
@JsonDeserialize(using = StepsDeserializer.class)
public void setSteps(java.util.@Valid List steps) {
this.steps = steps;
}
@JsonProperty("description")
public void setDescription(Optional description) {
this.description = description;
}
@Override
public Element withName(String of) { throw new UnsupportedOperationException(); }
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public java.util.@Valid List getConditions() { throw new UnsupportedOperationException(); }
@Override
public Match getMatch() { throw new UnsupportedOperationException(); }
@Override
public java.util.@Valid List getSteps() { 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 ImmutableWhile fromJson(Json json) {
While.Builder builder = new While.Builder();
if (json.name != null) {
builder.name(json.name);
}
if (json.conditions != null) {
builder.addAllConditions(json.conditions);
}
if (json.match != null) {
builder.match(json.match);
}
if (json.steps != null) {
builder.addAllSteps(json.steps);
}
if (json.description != null) {
builder.description(json.description);
}
return (ImmutableWhile) builder.build();
}
/**
* Creates an immutable copy of a {@link While} 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 While instance
*/
public static ImmutableWhile copyOf(While instance) {
if (instance instanceof ImmutableWhile) {
return (ImmutableWhile) instance;
}
return new While.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableWhile ImmutableWhile}.
* 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 name;
private ImmutableList.Builder conditions = ImmutableList.builder();
private @Nullable Match match;
private ImmutableList.Builder steps = ImmutableList.builder();
private @Nullable String description;
/**
* Creates a builder for {@link ImmutableWhile ImmutableWhile} instances.
*/
public Builder() {
if (!(this instanceof While.Builder)) {
throw new UnsupportedOperationException("Use: new While.Builder()");
}
}
/**
* 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 While.Builder from(Element instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (While.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.userpath.While} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final While.Builder from(While instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (While.Builder) this;
}
private void from(Object object) {
long bits = 0;
if (object instanceof Element) {
Element instance = (Element) object;
if ((bits & 0x1L) == 0) {
name(instance.getName());
bits |= 0x1L;
}
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
description(descriptionOptional);
}
}
if (object instanceof While) {
While instance = (While) object;
if ((bits & 0x1L) == 0) {
name(instance.getName());
bits |= 0x1L;
}
match(instance.getMatch());
addAllConditions(instance.getConditions());
addAllSteps(instance.getSteps());
}
}
/**
* Initializes the value for the {@link While#getName() name} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link While#getName() name}.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("name")
public final While.Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
return (While.Builder) this;
}
/**
* Adds one element to {@link While#getConditions() conditions} list.
* @param element A conditions element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final While.Builder addConditions(Condition element) {
this.conditions.add(element);
return (While.Builder) this;
}
/**
* Adds elements to {@link While#getConditions() conditions} list.
* @param elements An array of conditions elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final While.Builder addConditions(Condition... elements) {
this.conditions.add(elements);
return (While.Builder) this;
}
/**
* Sets or replaces all elements for {@link While#getConditions() conditions} list.
* @param elements An iterable of conditions elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("conditions")
public final While.Builder conditions(Iterable extends Condition> elements) {
this.conditions = ImmutableList.builder();
return addAllConditions(elements);
}
/**
* Adds elements to {@link While#getConditions() conditions} list.
* @param elements An iterable of conditions elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final While.Builder addAllConditions(Iterable extends Condition> elements) {
this.conditions.addAll(elements);
return (While.Builder) this;
}
/**
* Initializes the value for the {@link While#getMatch() match} attribute.
*
If not set, this attribute will have a default value as returned by the initializer of {@link While#getMatch() match}.
* @param match The value for match
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("match")
@JsonDeserialize(using = MatchDeserializer.class)
public final While.Builder match(Match match) {
this.match = Objects.requireNonNull(match, "match");
return (While.Builder) this;
}
/**
* Adds one element to {@link While#getSteps() steps} list.
* @param element A steps element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final While.Builder addSteps(Step element) {
this.steps.add(element);
return (While.Builder) this;
}
/**
* Adds elements to {@link While#getSteps() steps} list.
* @param elements An array of steps elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final While.Builder addSteps(Step... elements) {
this.steps.add(elements);
return (While.Builder) this;
}
/**
* Sets or replaces all elements for {@link While#getSteps() steps} list.
* @param elements An iterable of steps elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("steps")
@JsonDeserialize(using = StepsDeserializer.class)
public final While.Builder steps(Iterable extends Step> elements) {
this.steps = ImmutableList.builder();
return addAllSteps(elements);
}
/**
* Adds elements to {@link While#getSteps() steps} list.
* @param elements An iterable of steps elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final While.Builder addAllSteps(Iterable extends Step> elements) {
this.steps.addAll(elements);
return (While.Builder) this;
}
/**
* Initializes the optional value {@link While#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final While.Builder description(String description) {
this.description = Objects.requireNonNull(description, "description");
return (While.Builder) this;
}
/**
* Initializes the optional value {@link While#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 While.Builder description(Optional description) {
this.description = description.orElse(null);
return (While.Builder) this;
}
/**
* Builds a new {@link ImmutableWhile ImmutableWhile}.
* @return An immutable instance of While
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableWhile build() {
return new ImmutableWhile(this);
}
}
}