All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.neotys.neoload.model.v3.project.userpath.ImmutableIf 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.project.Element;
import java.util.ArrayList;
import java.util.Objects;
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 If}.
 * 

* Use the builder to create immutable instances: * {@code new If.Builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "If"}) @Immutable @CheckReturnValue public final class ImmutableIf implements If { private final String name; private final ImmutableList conditions; private final Match match; private final com.neotys.neoload.model.v3.project.userpath.@Valid Container then; private final @Nullable Container getElse; private final @Nullable String description; private ImmutableIf(ImmutableIf.Builder builder) { this.conditions = builder.conditions.build(); this.then = builder.then; this.getElse = builder.getElse; 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 ImmutableIf( String name, ImmutableList conditions, Match match, com.neotys.neoload.model.v3.project.userpath.@Valid Container then, @Nullable Container getElse, @Nullable String description) { this.name = name; this.conditions = conditions; this.match = match; this.then = then; this.getElse = getElse; 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 If, attribute initializers form cycle" + attributes; } } private String getNameInitialize() { return If.super.getName(); } private Match getMatchInitialize() { return If.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 then} attribute */ @JsonProperty("then") @Override public com.neotys.neoload.model.v3.project.userpath.@Valid Container getThen() { return then; } /** * @return The value of the {@code getElse} attribute */ @JsonProperty("else") @Override public java.util.@Valid Optional getElse() { return java.util.Optional.ofNullable(getElse); } /** * @return The value of the {@code description} attribute */ @JsonProperty("description") @Override public java.util.Optional getDescription() { return java.util.Optional.ofNullable(description); } /** * Copy the current immutable object by setting a value for the {@link If#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 ImmutableIf withName(String value) { if (this.name.equals(value)) return this; String newValue = Objects.requireNonNull(value, "name"); return new ImmutableIf(newValue, this.conditions, this.match, this.then, this.getElse, this.description); } /** * Copy the current immutable object with elements that replace the content of {@link If#getConditions() conditions}. * @param elements The elements to set * @return A modified copy of {@code this} object */ public final ImmutableIf withConditions(Condition... elements) { ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableIf(this.name, newValue, this.match, this.then, this.getElse, this.description); } /** * Copy the current immutable object with elements that replace the content of {@link If#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 ImmutableIf withConditions(Iterable elements) { if (this.conditions == elements) return this; ImmutableList newValue = ImmutableList.copyOf(elements); return new ImmutableIf(this.name, newValue, this.match, this.then, this.getElse, this.description); } /** * Copy the current immutable object by setting a value for the {@link If#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 ImmutableIf withMatch(Match value) { if (this.match == value) return this; Match newValue = Objects.requireNonNull(value, "match"); return new ImmutableIf(this.name, this.conditions, newValue, this.then, this.getElse, this.description); } /** * Copy the current immutable object by setting a value for the {@link If#getThen() then} attribute. * A shallow reference equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for then (can be {@code null}) * @return A modified copy of the {@code this} object */ public final ImmutableIf withThen(com.neotys.neoload.model.v3.project.userpath.@Valid Container value) { if (this.then == value) return this; return new ImmutableIf(this.name, this.conditions, this.match, value, this.getElse, this.description); } /** * Copy the current immutable object by setting a present value for the optional {@link If#getElse() else} attribute. * @param value The value for getElse * @return A modified copy of {@code this} object */ public final ImmutableIf withElse(Container value) { @Nullable Container newValue = Objects.requireNonNull(value, "getElse"); if (this.getElse == newValue) return this; return new ImmutableIf(this.name, this.conditions, this.match, this.then, newValue, this.description); } /** * Copy the current immutable object by setting an optional value for the {@link If#getElse() else} attribute. * A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}. * @param optional A value for getElse * @return A modified copy of {@code this} object */ public final ImmutableIf withElse(java.util.Optional optional) { @Nullable Container value = optional.orElse(null); if (this.getElse == value) return this; return new ImmutableIf(this.name, this.conditions, this.match, this.then, value, this.description); } /** * Copy the current immutable object by setting a present value for the optional {@link If#getDescription() description} attribute. * @param value The value for description * @return A modified copy of {@code this} object */ public final ImmutableIf withDescription(String value) { @Nullable String newValue = Objects.requireNonNull(value, "description"); if (Objects.equals(this.description, newValue)) return this; return new ImmutableIf(this.name, this.conditions, this.match, this.then, this.getElse, newValue); } /** * Copy the current immutable object by setting an optional value for the {@link If#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 ImmutableIf withDescription(java.util.Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.description, value)) return this; return new ImmutableIf(this.name, this.conditions, this.match, this.then, this.getElse, value); } /** * This instance is equal to all instances of {@code ImmutableIf} 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 ImmutableIf && equalTo((ImmutableIf) another); } private boolean equalTo(ImmutableIf another) { return name.equals(another.name) && conditions.equals(another.conditions) && match.equals(another.match) && Objects.equals(then, another.then) && Objects.equals(getElse, another.getElse) && Objects.equals(description, another.description); } /** * Computes a hash code from attributes: {@code name}, {@code conditions}, {@code match}, {@code then}, {@code getElse}, {@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) + Objects.hashCode(then); h += (h << 5) + Objects.hashCode(getElse); h += (h << 5) + Objects.hashCode(description); return h; } /** * Prints the immutable value {@code If} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("If") .omitNullValues() .add("name", name) .add("conditions", conditions) .add("match", match) .add("then", then) .add("else", getElse) .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 If { @Nullable String name; java.util.@Valid List conditions = ImmutableList.of(); @Nullable Match match; @Nullable com.neotys.neoload.model.v3.project.userpath.@Valid Container then; java.util.@Valid Optional getElse = java.util.Optional.empty(); java.util.Optional description = java.util.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("then") public void setThen(com.neotys.neoload.model.v3.project.userpath.@Valid Container then) { this.then = then; } @JsonProperty("else") public void setElse(java.util.@Valid Optional getElse) { this.getElse = getElse; } @JsonProperty("description") public void setDescription(java.util.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 com.neotys.neoload.model.v3.project.userpath.@Valid Container getThen() { throw new UnsupportedOperationException(); } @Override public java.util.@Valid Optional getElse() { throw new UnsupportedOperationException(); } @Override public java.util.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 ImmutableIf fromJson(Json json) { If.Builder builder = new If.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.then != null) { builder.then(json.then); } if (json.getElse != null) { builder.getElse(json.getElse); } if (json.description != null) { builder.description(json.description); } return (ImmutableIf) builder.build(); } /** * Creates an immutable copy of a {@link If} 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 If instance */ public static ImmutableIf copyOf(If instance) { if (instance instanceof ImmutableIf) { return (ImmutableIf) instance; } return new If.Builder() .from(instance) .build(); } /** * Builds instances of type {@link ImmutableIf ImmutableIf}. * 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 @Nullable com.neotys.neoload.model.v3.project.userpath.@Valid Container then; private @Nullable Container getElse; private @Nullable String description; /** * Creates a builder for {@link ImmutableIf ImmutableIf} instances. */ public Builder() { if (!(this instanceof If.Builder)) { throw new UnsupportedOperationException("Use: new If.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.userpath.If} instance. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final If.Builder from(If instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (If.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 If.Builder from(Element instance) { Objects.requireNonNull(instance, "instance"); from((Object) instance); return (If.Builder) this; } private void from(Object object) { long bits = 0; if (object instanceof If) { If instance = (If) object; if ((bits & 0x1L) == 0) { name(instance.getName()); bits |= 0x1L; } match(instance.getMatch()); java.util.@Valid Optional getElseOptional = instance.getElse(); if (getElseOptional.isPresent()) { getElse(getElseOptional); } com.neotys.neoload.model.v3.project.userpath.@Valid Container thenValue = instance.getThen(); if (thenValue != null) { then(thenValue); } addAllConditions(instance.getConditions()); } if (object instanceof Element) { Element instance = (Element) object; if ((bits & 0x1L) == 0) { name(instance.getName()); bits |= 0x1L; } java.util.Optional descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { description(descriptionOptional); } } } /** * Initializes the value for the {@link If#getName() name} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link If#getName() name}. * @param name The value for name * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("name") public final If.Builder name(String name) { this.name = Objects.requireNonNull(name, "name"); return (If.Builder) this; } /** * Adds one element to {@link If#getConditions() conditions} list. * @param element A conditions element * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final If.Builder addConditions(Condition element) { this.conditions.add(element); return (If.Builder) this; } /** * Adds elements to {@link If#getConditions() conditions} list. * @param elements An array of conditions elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final If.Builder addConditions(Condition... elements) { this.conditions.add(elements); return (If.Builder) this; } /** * Sets or replaces all elements for {@link If#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 If.Builder conditions(Iterable elements) { this.conditions = ImmutableList.builder(); return addAllConditions(elements); } /** * Adds elements to {@link If#getConditions() conditions} list. * @param elements An iterable of conditions elements * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final If.Builder addAllConditions(Iterable elements) { this.conditions.addAll(elements); return (If.Builder) this; } /** * Initializes the value for the {@link If#getMatch() match} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link If#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 If.Builder match(Match match) { this.match = Objects.requireNonNull(match, "match"); return (If.Builder) this; } /** * Initializes the value for the {@link If#getThen() then} attribute. * @param then The value for then (can be {@code null}) * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("then") public final If.Builder then(com.neotys.neoload.model.v3.project.userpath.@Valid Container then) { this.then = then; return (If.Builder) this; } /** * Initializes the optional value {@link If#getElse() else} to getElse. * @param getElse The value for getElse * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final If.Builder getElse(Container getElse) { this.getElse = Objects.requireNonNull(getElse, "getElse"); return (If.Builder) this; } /** * Initializes the optional value {@link If#getElse() else} to getElse. * @param getElse The value for getElse * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("else") public final If.Builder getElse(java.util.Optional getElse) { this.getElse = getElse.orElse(null); return (If.Builder) this; } /** * Initializes the optional value {@link If#getDescription() description} to description. * @param description The value for description * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final If.Builder description(String description) { this.description = Objects.requireNonNull(description, "description"); return (If.Builder) this; } /** * Initializes the optional value {@link If#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 If.Builder description(java.util.Optional description) { this.description = description.orElse(null); return (If.Builder) this; } /** * Builds a new {@link ImmutableIf ImmutableIf}. * @return An immutable instance of If * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableIf build() { return new ImmutableIf(this); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy