com.neotys.neoload.model.v3.project.userpath.assertion.ImmutableContentAssertion Maven / Gradle / Ivy
package com.neotys.neoload.model.v3.project.userpath.assertion;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import com.google.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
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 ContentAssertion}.
*
* Use the builder to create immutable instances:
* {@code new ContentAssertion.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ContentAssertion"})
@Immutable
@CheckReturnValue
public final class ImmutableContentAssertion
implements ContentAssertion {
private final @Nullable String name;
private final @Nullable String xPath;
private final @Nullable String jsonPath;
private final boolean not;
private final @Nullable String contains;
private final boolean regexp;
private ImmutableContentAssertion(ImmutableContentAssertion.Builder builder) {
this.name = builder.name;
this.xPath = builder.xPath;
this.jsonPath = builder.jsonPath;
this.contains = builder.contains;
if (builder.notIsSet()) {
initShim.not(builder.not);
}
if (builder.regexpIsSet()) {
initShim.regexp(builder.regexp);
}
this.not = initShim.getNot();
this.regexp = initShim.getRegexp();
this.initShim = null;
}
private ImmutableContentAssertion(
@Nullable String name,
@Nullable String xPath,
@Nullable String jsonPath,
boolean not,
@Nullable String contains,
boolean regexp) {
this.name = name;
this.xPath = xPath;
this.jsonPath = jsonPath;
this.not = not;
this.contains = contains;
this.regexp = regexp;
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 boolean not;
private int notBuildStage;
boolean getNot() {
if (notBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (notBuildStage == STAGE_UNINITIALIZED) {
notBuildStage = STAGE_INITIALIZING;
this.not = getNotInitialize();
notBuildStage = STAGE_INITIALIZED;
}
return this.not;
}
void not(boolean not) {
this.not = not;
notBuildStage = STAGE_INITIALIZED;
}
private boolean regexp;
private int regexpBuildStage;
boolean getRegexp() {
if (regexpBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage());
if (regexpBuildStage == STAGE_UNINITIALIZED) {
regexpBuildStage = STAGE_INITIALIZING;
this.regexp = getRegexpInitialize();
regexpBuildStage = STAGE_INITIALIZED;
}
return this.regexp;
}
void regexp(boolean regexp) {
this.regexp = regexp;
regexpBuildStage = STAGE_INITIALIZED;
}
private String formatInitCycleMessage() {
ArrayList attributes = Lists.newArrayList();
if (notBuildStage == STAGE_INITIALIZING) attributes.add("not");
if (regexpBuildStage == STAGE_INITIALIZING) attributes.add("regexp");
return "Cannot build ContentAssertion, attribute initializers form cycle" + attributes;
}
}
private boolean getNotInitialize() {
return ContentAssertion.super.getNot();
}
private boolean getRegexpInitialize() {
return ContentAssertion.super.getRegexp();
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public Optional getName() {
return Optional.ofNullable(name);
}
/**
* @return The value of the {@code xPath} attribute
*/
@JsonProperty("xpath")
@Override
public Optional getXPath() {
return Optional.ofNullable(xPath);
}
/**
* @return The value of the {@code jsonPath} attribute
*/
@JsonProperty("jsonpath")
@Override
public Optional getJsonPath() {
return Optional.ofNullable(jsonPath);
}
/**
* @return The value of the {@code not} attribute
*/
@JsonProperty("not")
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@Override
public boolean getNot() {
InitShim shim = this.initShim;
return shim != null
? shim.getNot()
: this.not;
}
/**
* @return The value of the {@code contains} attribute
*/
@JsonProperty("contains")
@Override
public Optional getContains() {
return Optional.ofNullable(contains);
}
/**
* @return The value of the {@code regexp} attribute
*/
@JsonProperty("regexp")
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
@Override
public boolean getRegexp() {
InitShim shim = this.initShim;
return shim != null
? shim.getRegexp()
: this.regexp;
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ContentAssertion#getName() name} attribute.
* @param value The value for name
* @return A modified copy of {@code this} object
*/
public final ImmutableContentAssertion withName(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "name");
if (Objects.equals(this.name, newValue)) return this;
return new ImmutableContentAssertion(newValue, this.xPath, this.jsonPath, this.not, this.contains, this.regexp);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ContentAssertion#getName() name} 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 name
* @return A modified copy of {@code this} object
*/
public final ImmutableContentAssertion withName(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.name, value)) return this;
return new ImmutableContentAssertion(value, this.xPath, this.jsonPath, this.not, this.contains, this.regexp);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ContentAssertion#getXPath() xPath} attribute.
* @param value The value for xPath
* @return A modified copy of {@code this} object
*/
public final ImmutableContentAssertion withXPath(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "xPath");
if (Objects.equals(this.xPath, newValue)) return this;
return new ImmutableContentAssertion(this.name, newValue, this.jsonPath, this.not, this.contains, this.regexp);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ContentAssertion#getXPath() xPath} 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 xPath
* @return A modified copy of {@code this} object
*/
public final ImmutableContentAssertion withXPath(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.xPath, value)) return this;
return new ImmutableContentAssertion(this.name, value, this.jsonPath, this.not, this.contains, this.regexp);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ContentAssertion#getJsonPath() jsonPath} attribute.
* @param value The value for jsonPath
* @return A modified copy of {@code this} object
*/
public final ImmutableContentAssertion withJsonPath(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "jsonPath");
if (Objects.equals(this.jsonPath, newValue)) return this;
return new ImmutableContentAssertion(this.name, this.xPath, newValue, this.not, this.contains, this.regexp);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ContentAssertion#getJsonPath() jsonPath} 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 jsonPath
* @return A modified copy of {@code this} object
*/
public final ImmutableContentAssertion withJsonPath(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.jsonPath, value)) return this;
return new ImmutableContentAssertion(this.name, this.xPath, value, this.not, this.contains, this.regexp);
}
/**
* Copy the current immutable object by setting a value for the {@link ContentAssertion#getNot() not} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for not
* @return A modified copy of the {@code this} object
*/
public final ImmutableContentAssertion withNot(boolean value) {
if (this.not == value) return this;
return new ImmutableContentAssertion(this.name, this.xPath, this.jsonPath, value, this.contains, this.regexp);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ContentAssertion#getContains() contains} attribute.
* @param value The value for contains
* @return A modified copy of {@code this} object
*/
public final ImmutableContentAssertion withContains(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "contains");
if (Objects.equals(this.contains, newValue)) return this;
return new ImmutableContentAssertion(this.name, this.xPath, this.jsonPath, this.not, newValue, this.regexp);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ContentAssertion#getContains() contains} 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 contains
* @return A modified copy of {@code this} object
*/
public final ImmutableContentAssertion withContains(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.contains, value)) return this;
return new ImmutableContentAssertion(this.name, this.xPath, this.jsonPath, this.not, value, this.regexp);
}
/**
* Copy the current immutable object by setting a value for the {@link ContentAssertion#getRegexp() regexp} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for regexp
* @return A modified copy of the {@code this} object
*/
public final ImmutableContentAssertion withRegexp(boolean value) {
if (this.regexp == value) return this;
return new ImmutableContentAssertion(this.name, this.xPath, this.jsonPath, this.not, this.contains, value);
}
/**
* This instance is equal to all instances of {@code ImmutableContentAssertion} 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 ImmutableContentAssertion
&& equalTo((ImmutableContentAssertion) another);
}
private boolean equalTo(ImmutableContentAssertion another) {
return Objects.equals(name, another.name)
&& Objects.equals(xPath, another.xPath)
&& Objects.equals(jsonPath, another.jsonPath)
&& not == another.not
&& Objects.equals(contains, another.contains)
&& regexp == another.regexp;
}
/**
* Computes a hash code from attributes: {@code name}, {@code xPath}, {@code jsonPath}, {@code not}, {@code contains}, {@code regexp}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + Objects.hashCode(xPath);
h += (h << 5) + Objects.hashCode(jsonPath);
h += (h << 5) + Booleans.hashCode(not);
h += (h << 5) + Objects.hashCode(contains);
h += (h << 5) + Booleans.hashCode(regexp);
return h;
}
/**
* Prints the immutable value {@code ContentAssertion} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ContentAssertion")
.omitNullValues()
.add("name", name)
.add("xPath", xPath)
.add("jsonPath", jsonPath)
.add("not", not)
.add("contains", contains)
.add("regexp", regexp)
.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 ContentAssertion {
Optional name = Optional.empty();
Optional xPath = Optional.empty();
Optional jsonPath = Optional.empty();
boolean not;
boolean notIsSet;
Optional contains = Optional.empty();
boolean regexp;
boolean regexpIsSet;
@JsonProperty("name")
public void setName(Optional name) {
this.name = name;
}
@JsonProperty("xpath")
public void setXPath(Optional xPath) {
this.xPath = xPath;
}
@JsonProperty("jsonpath")
public void setJsonPath(Optional jsonPath) {
this.jsonPath = jsonPath;
}
@JsonProperty("not")
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public void setNot(boolean not) {
this.not = not;
this.notIsSet = true;
}
@JsonProperty("contains")
public void setContains(Optional contains) {
this.contains = contains;
}
@JsonProperty("regexp")
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public void setRegexp(boolean regexp) {
this.regexp = regexp;
this.regexpIsSet = true;
}
@Override
public Optional getName() { throw new UnsupportedOperationException(); }
@Override
public Optional getXPath() { throw new UnsupportedOperationException(); }
@Override
public Optional getJsonPath() { throw new UnsupportedOperationException(); }
@Override
public boolean getNot() { throw new UnsupportedOperationException(); }
@Override
public Optional getContains() { throw new UnsupportedOperationException(); }
@Override
public boolean getRegexp() { 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 ImmutableContentAssertion fromJson(Json json) {
ContentAssertion.Builder builder = new ContentAssertion.Builder();
if (json.name != null) {
builder.name(json.name);
}
if (json.xPath != null) {
builder.xPath(json.xPath);
}
if (json.jsonPath != null) {
builder.jsonPath(json.jsonPath);
}
if (json.notIsSet) {
builder.not(json.not);
}
if (json.contains != null) {
builder.contains(json.contains);
}
if (json.regexpIsSet) {
builder.regexp(json.regexp);
}
return (ImmutableContentAssertion) builder.build();
}
/**
* Creates an immutable copy of a {@link ContentAssertion} 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 ContentAssertion instance
*/
public static ImmutableContentAssertion copyOf(ContentAssertion instance) {
if (instance instanceof ImmutableContentAssertion) {
return (ImmutableContentAssertion) instance;
}
return new ContentAssertion.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableContentAssertion ImmutableContentAssertion}.
* 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 static final long OPT_BIT_NOT = 0x1L;
private static final long OPT_BIT_REGEXP = 0x2L;
private long optBits;
private @Nullable String name;
private @Nullable String xPath;
private @Nullable String jsonPath;
private boolean not;
private @Nullable String contains;
private boolean regexp;
/**
* Creates a builder for {@link ImmutableContentAssertion ImmutableContentAssertion} instances.
*/
public Builder() {
if (!(this instanceof ContentAssertion.Builder)) {
throw new UnsupportedOperationException("Use: new ContentAssertion.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code ContentAssertion} 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 ContentAssertion.Builder from(ContentAssertion instance) {
Objects.requireNonNull(instance, "instance");
Optional nameOptional = instance.getName();
if (nameOptional.isPresent()) {
name(nameOptional);
}
Optional xPathOptional = instance.getXPath();
if (xPathOptional.isPresent()) {
xPath(xPathOptional);
}
Optional jsonPathOptional = instance.getJsonPath();
if (jsonPathOptional.isPresent()) {
jsonPath(jsonPathOptional);
}
not(instance.getNot());
Optional containsOptional = instance.getContains();
if (containsOptional.isPresent()) {
contains(containsOptional);
}
regexp(instance.getRegexp());
return (ContentAssertion.Builder) this;
}
/**
* Initializes the optional value {@link ContentAssertion#getName() name} to name.
* @param name The value for name
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final ContentAssertion.Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
return (ContentAssertion.Builder) this;
}
/**
* Initializes the optional value {@link ContentAssertion#getName() name} to name.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("name")
public final ContentAssertion.Builder name(Optional name) {
this.name = name.orElse(null);
return (ContentAssertion.Builder) this;
}
/**
* Initializes the optional value {@link ContentAssertion#getXPath() xPath} to xPath.
* @param xPath The value for xPath
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final ContentAssertion.Builder xPath(String xPath) {
this.xPath = Objects.requireNonNull(xPath, "xPath");
return (ContentAssertion.Builder) this;
}
/**
* Initializes the optional value {@link ContentAssertion#getXPath() xPath} to xPath.
* @param xPath The value for xPath
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("xpath")
public final ContentAssertion.Builder xPath(Optional xPath) {
this.xPath = xPath.orElse(null);
return (ContentAssertion.Builder) this;
}
/**
* Initializes the optional value {@link ContentAssertion#getJsonPath() jsonPath} to jsonPath.
* @param jsonPath The value for jsonPath
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final ContentAssertion.Builder jsonPath(String jsonPath) {
this.jsonPath = Objects.requireNonNull(jsonPath, "jsonPath");
return (ContentAssertion.Builder) this;
}
/**
* Initializes the optional value {@link ContentAssertion#getJsonPath() jsonPath} to jsonPath.
* @param jsonPath The value for jsonPath
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("jsonpath")
public final ContentAssertion.Builder jsonPath(Optional jsonPath) {
this.jsonPath = jsonPath.orElse(null);
return (ContentAssertion.Builder) this;
}
/**
* Initializes the value for the {@link ContentAssertion#getNot() not} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link ContentAssertion#getNot() not}.
* @param not The value for not
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("not")
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public final ContentAssertion.Builder not(boolean not) {
this.not = not;
optBits |= OPT_BIT_NOT;
return (ContentAssertion.Builder) this;
}
/**
* Initializes the optional value {@link ContentAssertion#getContains() contains} to contains.
* @param contains The value for contains
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final ContentAssertion.Builder contains(String contains) {
this.contains = Objects.requireNonNull(contains, "contains");
return (ContentAssertion.Builder) this;
}
/**
* Initializes the optional value {@link ContentAssertion#getContains() contains} to contains.
* @param contains The value for contains
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("contains")
public final ContentAssertion.Builder contains(Optional contains) {
this.contains = contains.orElse(null);
return (ContentAssertion.Builder) this;
}
/**
* Initializes the value for the {@link ContentAssertion#getRegexp() regexp} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link ContentAssertion#getRegexp() regexp}.
* @param regexp The value for regexp
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("regexp")
@JsonInclude(JsonInclude.Include.NON_DEFAULT)
public final ContentAssertion.Builder regexp(boolean regexp) {
this.regexp = regexp;
optBits |= OPT_BIT_REGEXP;
return (ContentAssertion.Builder) this;
}
/**
* Builds a new {@link ImmutableContentAssertion ImmutableContentAssertion}.
* @return An immutable instance of ContentAssertion
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableContentAssertion build() {
return new ImmutableContentAssertion(this);
}
private boolean notIsSet() {
return (optBits & OPT_BIT_NOT) != 0;
}
private boolean regexpIsSet() {
return (optBits & OPT_BIT_REGEXP) != 0;
}
}
}