com.neotys.neoload.model.v3.project.scenario.ImmutableCustomLoadPolicy 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.JsonIgnore;
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 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 CustomLoadPolicy}.
*
* Use the builder to create immutable instances:
* {@code new CustomLoadPolicy.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "CustomLoadPolicy"})
@Immutable
@CheckReturnValue
public final class ImmutableCustomLoadPolicy
implements CustomLoadPolicy {
private final ImmutableList steps;
private final Integer rampup;
private final @Nullable LoadDuration duration;
private final com.neotys.neoload.model.v3.project.scenario.@Valid StartAfter startAfter;
private final com.neotys.neoload.model.v3.project.scenario.@Valid StopAfter stopAfter;
private ImmutableCustomLoadPolicy(
ImmutableList steps,
Integer rampup,
com.neotys.neoload.model.v3.project.scenario.@Valid StartAfter startAfter,
com.neotys.neoload.model.v3.project.scenario.@Valid StopAfter stopAfter) {
this.steps = steps;
this.rampup = rampup;
this.startAfter = startAfter;
this.stopAfter = stopAfter;
this.duration = CustomLoadPolicy.super.getDuration();
}
/**
* @return The value of the {@code steps} attribute
*/
@JsonProperty("steps")
@Override
public ImmutableList getSteps() {
return steps;
}
/**
* @return The value of the {@code rampup} attribute
*/
@JsonProperty("rampup")
@Override
public Integer getRampup() {
return rampup;
}
/**
* @return The computed-at-construction value of the {@code duration} attribute
*/
@JsonProperty("duration")
@JsonIgnore
@Override
public @Nullable LoadDuration getDuration() {
return duration;
}
/**
* @return The value of the {@code startAfter} attribute
*/
@JsonProperty("start_after")
@Override
public com.neotys.neoload.model.v3.project.scenario.@Valid StartAfter getStartAfter() {
return startAfter;
}
/**
* @return The value of the {@code stopAfter} attribute
*/
@JsonProperty("stop_after")
@Override
public com.neotys.neoload.model.v3.project.scenario.@Valid StopAfter getStopAfter() {
return stopAfter;
}
/**
* Copy the current immutable object with elements that replace the content of {@link CustomLoadPolicy#getSteps() steps}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableCustomLoadPolicy withSteps(CustomPolicyStep... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableCustomLoadPolicy(newValue, this.rampup, this.startAfter, this.stopAfter);
}
/**
* Copy the current immutable object with elements that replace the content of {@link CustomLoadPolicy#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 ImmutableCustomLoadPolicy withSteps(Iterable extends CustomPolicyStep> elements) {
if (this.steps == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableCustomLoadPolicy(newValue, this.rampup, this.startAfter, this.stopAfter);
}
/**
* Copy the current immutable object by setting a value for the {@link CustomLoadPolicy#getRampup() rampup} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for rampup (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCustomLoadPolicy withRampup(Integer value) {
if (Objects.equals(this.rampup, value)) return this;
return new ImmutableCustomLoadPolicy(this.steps, value, this.startAfter, this.stopAfter);
}
/**
* Copy the current immutable object by setting a value for the {@link CustomLoadPolicy#getStartAfter() startAfter} 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 startAfter (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCustomLoadPolicy withStartAfter(com.neotys.neoload.model.v3.project.scenario.@Valid StartAfter value) {
if (this.startAfter == value) return this;
return new ImmutableCustomLoadPolicy(this.steps, this.rampup, value, this.stopAfter);
}
/**
* Copy the current immutable object by setting a value for the {@link CustomLoadPolicy#getStopAfter() stopAfter} 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 stopAfter (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCustomLoadPolicy withStopAfter(com.neotys.neoload.model.v3.project.scenario.@Valid StopAfter value) {
if (this.stopAfter == value) return this;
return new ImmutableCustomLoadPolicy(this.steps, this.rampup, this.startAfter, value);
}
/**
* This instance is equal to all instances of {@code ImmutableCustomLoadPolicy} 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 ImmutableCustomLoadPolicy
&& equalTo((ImmutableCustomLoadPolicy) another);
}
private boolean equalTo(ImmutableCustomLoadPolicy another) {
return steps.equals(another.steps)
&& Objects.equals(rampup, another.rampup)
&& Objects.equals(duration, another.duration)
&& Objects.equals(startAfter, another.startAfter)
&& Objects.equals(stopAfter, another.stopAfter);
}
/**
* Computes a hash code from attributes: {@code steps}, {@code rampup}, {@code duration}, {@code startAfter}, {@code stopAfter}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + steps.hashCode();
h += (h << 5) + Objects.hashCode(rampup);
h += (h << 5) + Objects.hashCode(duration);
h += (h << 5) + Objects.hashCode(startAfter);
h += (h << 5) + Objects.hashCode(stopAfter);
return h;
}
/**
* Prints the immutable value {@code CustomLoadPolicy} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("CustomLoadPolicy")
.omitNullValues()
.add("steps", steps)
.add("rampup", rampup)
.add("duration", duration)
.add("startAfter", startAfter)
.add("stopAfter", stopAfter)
.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 CustomLoadPolicy {
java.util.@Valid List steps = ImmutableList.of();
@Nullable Integer rampup;
@Nullable com.neotys.neoload.model.v3.project.scenario.@Valid StartAfter startAfter;
@Nullable com.neotys.neoload.model.v3.project.scenario.@Valid StopAfter stopAfter;
@JsonProperty("steps")
public void setSteps(java.util.@Valid List steps) {
this.steps = steps;
}
@JsonProperty("rampup")
public void setRampup(Integer rampup) {
this.rampup = rampup;
}
@JsonProperty("start_after")
public void setStartAfter(com.neotys.neoload.model.v3.project.scenario.@Valid StartAfter startAfter) {
this.startAfter = startAfter;
}
@JsonProperty("stop_after")
public void setStopAfter(com.neotys.neoload.model.v3.project.scenario.@Valid StopAfter stopAfter) {
this.stopAfter = stopAfter;
}
@Override
public java.util.@Valid List getSteps() { throw new UnsupportedOperationException(); }
@Override
public Integer getRampup() { throw new UnsupportedOperationException(); }
@Override
public LoadDuration getDuration() { throw new UnsupportedOperationException(); }
@Override
public com.neotys.neoload.model.v3.project.scenario.@Valid StartAfter getStartAfter() { throw new UnsupportedOperationException(); }
@Override
public com.neotys.neoload.model.v3.project.scenario.@Valid StopAfter getStopAfter() { 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 ImmutableCustomLoadPolicy fromJson(Json json) {
CustomLoadPolicy.Builder builder = new CustomLoadPolicy.Builder();
if (json.steps != null) {
builder.addAllSteps(json.steps);
}
if (json.rampup != null) {
builder.rampup(json.rampup);
}
if (json.startAfter != null) {
builder.startAfter(json.startAfter);
}
if (json.stopAfter != null) {
builder.stopAfter(json.stopAfter);
}
return (ImmutableCustomLoadPolicy) builder.build();
}
/**
* Creates an immutable copy of a {@link CustomLoadPolicy} 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 CustomLoadPolicy instance
*/
public static ImmutableCustomLoadPolicy copyOf(CustomLoadPolicy instance) {
if (instance instanceof ImmutableCustomLoadPolicy) {
return (ImmutableCustomLoadPolicy) instance;
}
return new CustomLoadPolicy.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableCustomLoadPolicy ImmutableCustomLoadPolicy}.
* 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 ImmutableList.Builder steps = ImmutableList.builder();
private @Nullable Integer rampup;
private @Nullable com.neotys.neoload.model.v3.project.scenario.@Valid StartAfter startAfter;
private @Nullable com.neotys.neoload.model.v3.project.scenario.@Valid StopAfter stopAfter;
/**
* Creates a builder for {@link ImmutableCustomLoadPolicy ImmutableCustomLoadPolicy} instances.
*/
public Builder() {
if (!(this instanceof CustomLoadPolicy.Builder)) {
throw new UnsupportedOperationException("Use: new CustomLoadPolicy.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.scenario.StartStopPolicy} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final CustomLoadPolicy.Builder from(StartStopPolicy instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (CustomLoadPolicy.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.scenario.CustomLoadPolicy} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final CustomLoadPolicy.Builder from(CustomLoadPolicy instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (CustomLoadPolicy.Builder) this;
}
private void from(Object object) {
long bits = 0;
if (object instanceof StartStopPolicy) {
StartStopPolicy instance = (StartStopPolicy) object;
com.neotys.neoload.model.v3.project.scenario.@Valid StartAfter startAfterValue = instance.getStartAfter();
if (startAfterValue != null) {
startAfter(startAfterValue);
}
com.neotys.neoload.model.v3.project.scenario.@Valid StopAfter stopAfterValue = instance.getStopAfter();
if (stopAfterValue != null) {
stopAfter(stopAfterValue);
}
if ((bits & 0x1L) == 0) {
Integer rampupValue = instance.getRampup();
if (rampupValue != null) {
rampup(rampupValue);
}
bits |= 0x1L;
}
}
if (object instanceof CustomLoadPolicy) {
CustomLoadPolicy instance = (CustomLoadPolicy) object;
addAllSteps(instance.getSteps());
if ((bits & 0x1L) == 0) {
Integer rampupValue = instance.getRampup();
if (rampupValue != null) {
rampup(rampupValue);
}
bits |= 0x1L;
}
}
}
/**
* Adds one element to {@link CustomLoadPolicy#getSteps() steps} list.
* @param element A steps element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final CustomLoadPolicy.Builder addSteps(CustomPolicyStep element) {
this.steps.add(element);
return (CustomLoadPolicy.Builder) this;
}
/**
* Adds elements to {@link CustomLoadPolicy#getSteps() steps} list.
* @param elements An array of steps elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final CustomLoadPolicy.Builder addSteps(CustomPolicyStep... elements) {
this.steps.add(elements);
return (CustomLoadPolicy.Builder) this;
}
/**
* Sets or replaces all elements for {@link CustomLoadPolicy#getSteps() steps} list.
* @param elements An iterable of steps elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("steps")
public final CustomLoadPolicy.Builder steps(Iterable extends CustomPolicyStep> elements) {
this.steps = ImmutableList.builder();
return addAllSteps(elements);
}
/**
* Adds elements to {@link CustomLoadPolicy#getSteps() steps} list.
* @param elements An iterable of steps elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final CustomLoadPolicy.Builder addAllSteps(Iterable extends CustomPolicyStep> elements) {
this.steps.addAll(elements);
return (CustomLoadPolicy.Builder) this;
}
/**
* Initializes the value for the {@link CustomLoadPolicy#getRampup() rampup} attribute.
* @param rampup The value for rampup (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("rampup")
public final CustomLoadPolicy.Builder rampup(Integer rampup) {
this.rampup = rampup;
return (CustomLoadPolicy.Builder) this;
}
/**
* Initializes the value for the {@link CustomLoadPolicy#getStartAfter() startAfter} attribute.
* @param startAfter The value for startAfter (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("start_after")
public final CustomLoadPolicy.Builder startAfter(com.neotys.neoload.model.v3.project.scenario.@Valid StartAfter startAfter) {
this.startAfter = startAfter;
return (CustomLoadPolicy.Builder) this;
}
/**
* Initializes the value for the {@link CustomLoadPolicy#getStopAfter() stopAfter} attribute.
* @param stopAfter The value for stopAfter (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("stop_after")
public final CustomLoadPolicy.Builder stopAfter(com.neotys.neoload.model.v3.project.scenario.@Valid StopAfter stopAfter) {
this.stopAfter = stopAfter;
return (CustomLoadPolicy.Builder) this;
}
/**
* Builds a new {@link ImmutableCustomLoadPolicy ImmutableCustomLoadPolicy}.
* @return An immutable instance of CustomLoadPolicy
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableCustomLoadPolicy build() {
return new ImmutableCustomLoadPolicy(steps.build(), rampup, startAfter, stopAfter);
}
}
}