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

There is a newer version: 3.3.3
Show newest version
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.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import com.neotys.neoload.model.v3.binding.serializer.MatchDeserializer;
import com.neotys.neoload.model.v3.project.Element;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link If}.
 * 

* Use the builder to create immutable instances: * {@code new If.Builder()}. */ @Generated(from = "If", generator = "Immutables") @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor") @Immutable @CheckReturnValue public final class ImmutableIf implements If { private final @Nullable String description; private final String name; private final ImmutableList conditions; private final Match match; private final Container then; private final @Nullable Container getElse; private ImmutableIf(ImmutableIf.Builder builder) { this.description = builder.description; this.conditions = builder.conditions.build(); this.then = builder.then; this.getElse = builder.getElse; if (builder.nameIsSet()) { initShim.name(builder.name); } if (builder.matchIsSet()) { initShim.match(builder.match); } this.name = initShim.getName(); this.match = initShim.getMatch(); this.initShim = null; } private ImmutableIf( @Nullable String description, String name, ImmutableList conditions, Match match, Container then, @Nullable Container getElse) { this.description = description; this.name = name; this.conditions = conditions; this.match = match; this.then = then; this.getElse = getElse; this.initShim = null; } private static final byte STAGE_INITIALIZING = -1; private static final byte STAGE_UNINITIALIZED = 0; private static final byte STAGE_INITIALIZED = 1; @SuppressWarnings("Immutable") private transient volatile InitShim initShim = new InitShim(); @Generated(from = "If", generator = "Immutables") private final class InitShim { private byte nameBuildStage = STAGE_UNINITIALIZED; private String name; String getName() { if (nameBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (nameBuildStage == STAGE_UNINITIALIZED) { nameBuildStage = STAGE_INITIALIZING; this.name = getNameInitialize(); nameBuildStage = STAGE_INITIALIZED; } return this.name; } void name(String name) { this.name = name; nameBuildStage = STAGE_INITIALIZED; } private byte matchBuildStage = STAGE_UNINITIALIZED; private Match match; Match getMatch() { if (matchBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (matchBuildStage == STAGE_UNINITIALIZED) { matchBuildStage = STAGE_INITIALIZING; this.match = getMatchInitialize(); matchBuildStage = STAGE_INITIALIZED; } return this.match; } void match(Match match) { this.match = match; matchBuildStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); 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 description} attribute */ @JsonProperty("description") @Override public Optional getDescription() { return Optional.ofNullable(description); } /** * @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 Container getThen() { return then; } /** * @return The value of the {@code getElse} attribute */ @JsonProperty("else") @Override public Optional getElse() { return Optional.ofNullable(getElse); } /** * 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) { String newValue = Objects.requireNonNull(value, "description"); if (Objects.equals(this.description, newValue)) return this; return new ImmutableIf(newValue, this.name, this.conditions, this.match, this.then, this.getElse); } /** * 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(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.description, value)) return this; return new ImmutableIf(value, this.name, this.conditions, this.match, this.then, this.getElse); } /** * 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) { String newValue = value; if (this.name.equals(newValue)) return this; return new ImmutableIf(this.description, newValue, this.conditions, this.match, this.then, this.getElse); } /** * 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.description, this.name, newValue, this.match, this.then, this.getElse); } /** * 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.description, this.name, newValue, this.match, this.then, this.getElse); } /** * 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) { Match newValue = value; if (this.match == newValue) return this; return new ImmutableIf(this.description, this.name, this.conditions, newValue, this.then, this.getElse); } /** * 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(Container value) { if (this.then == value) return this; return new ImmutableIf(this.description, this.name, this.conditions, this.match, value, this.getElse); } /** * 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) { Container newValue = Objects.requireNonNull(value, "getElse"); if (this.getElse == newValue) return this; return new ImmutableIf(this.description, this.name, this.conditions, this.match, this.then, newValue); } /** * 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 */ @SuppressWarnings("unchecked") // safe covariant cast public final ImmutableIf withElse(Optional optional) { @Nullable Container value = optional.orElse(null); if (this.getElse == value) return this; return new ImmutableIf(this.description, this.name, this.conditions, this.match, this.then, 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(0, (ImmutableIf) another); } private boolean equalTo(int synthetic, ImmutableIf another) { return Objects.equals(description, another.description) && name.equals(another.name) && conditions.equals(another.conditions) && match.equals(another.match) && Objects.equals(then, another.then) && Objects.equals(getElse, another.getElse); } /** * Computes a hash code from attributes: {@code description}, {@code name}, {@code conditions}, {@code match}, {@code then}, {@code getElse}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + Objects.hashCode(description); 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); 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("description", description) .add("name", name) .add("conditions", conditions) .add("match", match) .add("then", then) .add("else", getElse) .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 */ @Generated(from = "If", generator = "Immutables") @Deprecated @SuppressWarnings("Immutable") @JsonDeserialize @JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE) static final class Json implements If { @Nullable Optional description = Optional.empty(); @Nullable String name; boolean nameIsSet; @Nullable List conditions = ImmutableList.of(); @Nullable Match match; boolean matchIsSet; @Nullable Container then; @Nullable Optional getElse = Optional.empty(); @JsonProperty("description") public void setDescription(Optional description) { this.description = description; } @JsonProperty("name") public void setName(String name) { this.name = name; this.nameIsSet = null != name; } @JsonProperty("conditions") public void setConditions(List conditions) { this.conditions = conditions; } @JsonProperty("match") @JsonDeserialize(using = MatchDeserializer.class) public void setMatch(Match match) { this.match = match; this.matchIsSet = null != match; } @JsonProperty("then") public void setThen(Container then) { this.then = then; } @JsonProperty("else") public void setElse(Optional getElse) { this.getElse = getElse; } @Override public Element withName(String of) { throw new UnsupportedOperationException(); } @Override public Optional getDescription() { throw new UnsupportedOperationException(); } @Override public String getName() { throw new UnsupportedOperationException(); } @Override public List getConditions() { throw new UnsupportedOperationException(); } @Override public Match getMatch() { throw new UnsupportedOperationException(); } @Override public Container getThen() { throw new UnsupportedOperationException(); } @Override public Optional getElse() { 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.description != null) { builder.description(json.description); } if (json.nameIsSet) { builder.name(json.name); } if (json.conditions != null) { builder.addAllConditions(json.conditions); } if (json.matchIsSet) { builder.match(json.match); } if (json.then != null) { builder.then(json.then); } if (json.getElse != null) { builder.getElse(json.getElse); } 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. */ @Generated(from = "If", generator = "Immutables") @NotThreadSafe public static class Builder { private static final long OPT_BIT_NAME = 0x1L; private static final long OPT_BIT_MATCH = 0x2L; private long optBits; private @Nullable String description; private @Nullable String name; private ImmutableList.Builder conditions = ImmutableList.builder(); private @Nullable Match match; private @Nullable Container then; private @Nullable Container getElse; /** * Creates a builder for {@link ImmutableIf ImmutableIf} instances. *

     * new If.Builder()
     *    .description(String) // optional {@link If#getDescription() description}
     *    .name(String) // optional {@link If#getName() name}
     *    .addConditions|addAllConditions(com.neotys.neoload.model.v3.project.userpath.Condition) // {@link If#getConditions() conditions} elements
     *    .match(com.neotys.neoload.model.v3.project.userpath.Match) // optional {@link If#getMatch() match}
     *    .then(com.neotys.neoload.model.v3.project.userpath.Container | null) // nullable {@link If#getThen() then}
     *    .getElse(com.neotys.neoload.model.v3.project.userpath.Container) // optional {@link If#getElse() else}
     *    .build();
     * 
*/ 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.userpath.Step} 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(Step 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) { @Var long bits = 0; if (object instanceof If) { If instance = (If) object; if ((bits & 0x1L) == 0) { name(instance.getName()); bits |= 0x1L; } match(instance.getMatch()); Optional getElseOptional = instance.getElse(); if (getElseOptional.isPresent()) { getElse(getElseOptional); } if ((bits & 0x2L) == 0) { Optional descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { description(descriptionOptional); } bits |= 0x2L; } Container thenValue = instance.getThen(); if (thenValue != null) { then(thenValue); } addAllConditions(instance.getConditions()); } if (object instanceof Step) { Step instance = (Step) object; if ((bits & 0x1L) == 0) { name(instance.getName()); bits |= 0x1L; } if ((bits & 0x2L) == 0) { Optional descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { description(descriptionOptional); } bits |= 0x2L; } } if (object instanceof Element) { Element instance = (Element) object; if ((bits & 0x1L) == 0) { name(instance.getName()); bits |= 0x1L; } if ((bits & 0x2L) == 0) { Optional descriptionOptional = instance.getDescription(); if (descriptionOptional.isPresent()) { description(descriptionOptional); } bits |= 0x2L; } } } /** * 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(Optional description) { this.description = description.orElse(null); return (If.Builder) this; } /** * 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 = name; optBits |= OPT_BIT_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(@Nullable 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 = match; optBits |= OPT_BIT_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(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(Optional getElse) { this.getElse = getElse.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); } private boolean nameIsSet() { return (optBits & OPT_BIT_NAME) != 0; } private boolean matchIsSet() { return (optBits & OPT_BIT_MATCH) != 0; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy