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

com.neotys.neoload.model.v3.project.scenario.ImmutableRendezvousPolicy Maven / Gradle / Ivy

package com.neotys.neoload.model.v3.project.scenario;

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.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.base.MoreObjects;
import com.google.common.collect.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.neotys.neoload.model.v3.binding.converter.StringToTimeDurationConverter;
import com.neotys.neoload.model.v3.binding.converter.TimeDurationToStringConverter;
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 RendezvousPolicy}.
 * 

* Use the builder to create immutable instances: * {@code new RendezvousPolicy.Builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "RendezvousPolicy"}) @Immutable @CheckReturnValue public final class ImmutableRendezvousPolicy implements RendezvousPolicy { private final String name; private final com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease when; private final Integer timeout; private ImmutableRendezvousPolicy(ImmutableRendezvousPolicy.Builder builder) { this.name = builder.name; if (builder.when != null) { initShim.when(builder.when); } if (builder.timeout != null) { initShim.timeout(builder.timeout); } this.when = initShim.getWhen(); this.timeout = initShim.getTimeout(); this.initShim = null; } private ImmutableRendezvousPolicy( String name, com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease when, Integer timeout) { this.name = name; this.when = when; this.timeout = timeout; 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 com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease when; private int whenBuildStage; com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease getWhen() { if (whenBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (whenBuildStage == STAGE_UNINITIALIZED) { whenBuildStage = STAGE_INITIALIZING; this.when = Objects.requireNonNull(getWhenInitialize(), "when"); whenBuildStage = STAGE_INITIALIZED; } return this.when; } void when(com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease when) { this.when = when; whenBuildStage = STAGE_INITIALIZED; } private Integer timeout; private int timeoutBuildStage; Integer getTimeout() { if (timeoutBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (timeoutBuildStage == STAGE_UNINITIALIZED) { timeoutBuildStage = STAGE_INITIALIZING; this.timeout = Objects.requireNonNull(getTimeoutInitialize(), "timeout"); timeoutBuildStage = STAGE_INITIALIZED; } return this.timeout; } void timeout(Integer timeout) { this.timeout = timeout; timeoutBuildStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { ArrayList attributes = Lists.newArrayList(); if (whenBuildStage == STAGE_INITIALIZING) attributes.add("when"); if (timeoutBuildStage == STAGE_INITIALIZING) attributes.add("timeout"); return "Cannot build RendezvousPolicy, attribute initializers form cycle" + attributes; } } private com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease getWhenInitialize() { return RendezvousPolicy.super.getWhen(); } private Integer getTimeoutInitialize() { return RendezvousPolicy.super.getTimeout(); } /** * @return The value of the {@code name} attribute */ @JsonProperty("name") @Override public String getName() { return name; } /** * @return The value of the {@code when} attribute */ @JsonProperty("when") @Override public com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease getWhen() { InitShim shim = this.initShim; return shim != null ? shim.getWhen() : this.when; } /** * @return The value of the {@code timeout} attribute */ @JsonProperty("timeout") @JsonSerialize(converter = TimeDurationToStringConverter.class) @JsonDeserialize(converter = StringToTimeDurationConverter.class) @Override public Integer getTimeout() { InitShim shim = this.initShim; return shim != null ? shim.getTimeout() : this.timeout; } /** * Copy the current immutable object by setting a value for the {@link RendezvousPolicy#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 ImmutableRendezvousPolicy withName(String value) { if (Objects.equals(this.name, value)) return this; return new ImmutableRendezvousPolicy(value, this.when, this.timeout); } /** * Copy the current immutable object by setting a value for the {@link RendezvousPolicy#getWhen() when} 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 when * @return A modified copy of the {@code this} object */ public final ImmutableRendezvousPolicy withWhen(com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease value) { if (this.when == value) return this; com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease newValue = Objects.requireNonNull(value, "when"); return new ImmutableRendezvousPolicy(this.name, newValue, this.timeout); } /** * Copy the current immutable object by setting a value for the {@link RendezvousPolicy#getTimeout() timeout} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for timeout * @return A modified copy of the {@code this} object */ public final ImmutableRendezvousPolicy withTimeout(Integer value) { if (this.timeout.equals(value)) return this; Integer newValue = Objects.requireNonNull(value, "timeout"); return new ImmutableRendezvousPolicy(this.name, this.when, newValue); } /** * This instance is equal to all instances of {@code ImmutableRendezvousPolicy} 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 ImmutableRendezvousPolicy && equalTo((ImmutableRendezvousPolicy) another); } private boolean equalTo(ImmutableRendezvousPolicy another) { return Objects.equals(name, another.name) && when.equals(another.when) && timeout.equals(another.timeout); } /** * Computes a hash code from attributes: {@code name}, {@code when}, {@code timeout}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + Objects.hashCode(name); h += (h << 5) + when.hashCode(); h += (h << 5) + timeout.hashCode(); return h; } /** * Prints the immutable value {@code RendezvousPolicy} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("RendezvousPolicy") .omitNullValues() .add("name", name) .add("when", when) .add("timeout", timeout) .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 RendezvousPolicy { @Nullable String name; @Nullable com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease when; @Nullable Integer timeout; @JsonProperty("name") public void setName(String name) { this.name = name; } @JsonProperty("when") public void setWhen(com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease when) { this.when = when; } @JsonProperty("timeout") @JsonSerialize(converter = TimeDurationToStringConverter.class) @JsonDeserialize(converter = StringToTimeDurationConverter.class) public void setTimeout(Integer timeout) { this.timeout = timeout; } @Override public String getName() { throw new UnsupportedOperationException(); } @Override public com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease getWhen() { throw new UnsupportedOperationException(); } @Override public Integer getTimeout() { 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 ImmutableRendezvousPolicy fromJson(Json json) { RendezvousPolicy.Builder builder = new RendezvousPolicy.Builder(); if (json.name != null) { builder.name(json.name); } if (json.when != null) { builder.when(json.when); } if (json.timeout != null) { builder.timeout(json.timeout); } return (ImmutableRendezvousPolicy) builder.build(); } /** * Creates an immutable copy of a {@link RendezvousPolicy} 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 RendezvousPolicy instance */ public static ImmutableRendezvousPolicy copyOf(RendezvousPolicy instance) { if (instance instanceof ImmutableRendezvousPolicy) { return (ImmutableRendezvousPolicy) instance; } return new RendezvousPolicy.Builder() .from(instance) .build(); } /** * Builds instances of type {@link ImmutableRendezvousPolicy ImmutableRendezvousPolicy}. * 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 @Nullable com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease when; private @Nullable Integer timeout; /** * Creates a builder for {@link ImmutableRendezvousPolicy ImmutableRendezvousPolicy} instances. */ public Builder() { if (!(this instanceof RendezvousPolicy.Builder)) { throw new UnsupportedOperationException("Use: new RendezvousPolicy.Builder()"); } } /** * Fill a builder with attribute values from the provided {@code RendezvousPolicy} 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 RendezvousPolicy.Builder from(RendezvousPolicy instance) { Objects.requireNonNull(instance, "instance"); String nameValue = instance.getName(); if (nameValue != null) { name(nameValue); } when(instance.getWhen()); timeout(instance.getTimeout()); return (RendezvousPolicy.Builder) this; } /** * Initializes the value for the {@link RendezvousPolicy#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 RendezvousPolicy.Builder name(String name) { this.name = name; return (RendezvousPolicy.Builder) this; } /** * Initializes the value for the {@link RendezvousPolicy#getWhen() when} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link RendezvousPolicy#getWhen() when}. * @param when The value for when * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("when") public final RendezvousPolicy.Builder when(com.neotys.neoload.model.v3.project.scenario.@Valid WhenRelease when) { this.when = Objects.requireNonNull(when, "when"); return (RendezvousPolicy.Builder) this; } /** * Initializes the value for the {@link RendezvousPolicy#getTimeout() timeout} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link RendezvousPolicy#getTimeout() timeout}. * @param timeout The value for timeout * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("timeout") @JsonSerialize(converter = TimeDurationToStringConverter.class) @JsonDeserialize(converter = StringToTimeDurationConverter.class) public final RendezvousPolicy.Builder timeout(Integer timeout) { this.timeout = Objects.requireNonNull(timeout, "timeout"); return (RendezvousPolicy.Builder) this; } /** * Builds a new {@link ImmutableRendezvousPolicy ImmutableRendezvousPolicy}. * @return An immutable instance of RendezvousPolicy * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableRendezvousPolicy build() { return new ImmutableRendezvousPolicy(this); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy