com.neotys.neoload.model.scenario.ImmutablePeakLoadPolicy Maven / Gradle / Ivy
package com.neotys.neoload.model.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.google.common.base.MoreObjects;
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 PeakLoadPolicy}.
*
* Use the builder to create immutable instances:
* {@code new PeakLoadPolicy.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "PeakLoadPolicy"})
@Deprecated
@Immutable
@CheckReturnValue
public final class ImmutablePeakLoadPolicy implements PeakLoadPolicy {
private final int users;
private final com.neotys.neoload.model.scenario.@Valid Duration duration;
private ImmutablePeakLoadPolicy(int users, com.neotys.neoload.model.scenario.@Valid Duration duration) {
this.users = users;
this.duration = duration;
}
/**
* @return The value of the {@code users} attribute
*/
@JsonProperty("users")
@Override
public int getUsers() {
return users;
}
/**
* @return The value of the {@code duration} attribute
*/
@JsonProperty("duration")
@Override
public com.neotys.neoload.model.scenario.@Valid Duration getDuration() {
return duration;
}
/**
* Copy the current immutable object by setting a value for the {@link PeakLoadPolicy#getUsers() users} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for users
* @return A modified copy of the {@code this} object
*/
public final ImmutablePeakLoadPolicy withUsers(int value) {
if (this.users == value) return this;
return new ImmutablePeakLoadPolicy(value, this.duration);
}
/**
* Copy the current immutable object by setting a value for the {@link PeakLoadPolicy#getDuration() duration} 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 duration (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutablePeakLoadPolicy withDuration(com.neotys.neoload.model.scenario.@Valid Duration value) {
if (this.duration == value) return this;
return new ImmutablePeakLoadPolicy(this.users, value);
}
/**
* This instance is equal to all instances of {@code ImmutablePeakLoadPolicy} 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 ImmutablePeakLoadPolicy
&& equalTo((ImmutablePeakLoadPolicy) another);
}
private boolean equalTo(ImmutablePeakLoadPolicy another) {
return users == another.users
&& Objects.equals(duration, another.duration);
}
/**
* Computes a hash code from attributes: {@code users}, {@code duration}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + users;
h += (h << 5) + Objects.hashCode(duration);
return h;
}
/**
* Prints the immutable value {@code PeakLoadPolicy} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("PeakLoadPolicy")
.omitNullValues()
.add("users", users)
.add("duration", duration)
.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 PeakLoadPolicy {
int users;
boolean usersIsSet;
@Nullable com.neotys.neoload.model.scenario.@Valid Duration duration;
@JsonProperty("users")
public void setUsers(int users) {
this.users = users;
this.usersIsSet = true;
}
@JsonProperty("duration")
public void setDuration(com.neotys.neoload.model.scenario.@Valid Duration duration) {
this.duration = duration;
}
@Override
public int getUsers() { throw new UnsupportedOperationException(); }
@Override
public com.neotys.neoload.model.scenario.@Valid Duration getDuration() { 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 ImmutablePeakLoadPolicy fromJson(Json json) {
PeakLoadPolicy.Builder builder = new PeakLoadPolicy.Builder();
if (json.usersIsSet) {
builder.users(json.users);
}
if (json.duration != null) {
builder.duration(json.duration);
}
return (ImmutablePeakLoadPolicy) builder.build();
}
/**
* Creates an immutable copy of a {@link PeakLoadPolicy} 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 PeakLoadPolicy instance
*/
public static ImmutablePeakLoadPolicy copyOf(PeakLoadPolicy instance) {
if (instance instanceof ImmutablePeakLoadPolicy) {
return (ImmutablePeakLoadPolicy) instance;
}
return new PeakLoadPolicy.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutablePeakLoadPolicy ImmutablePeakLoadPolicy}.
* 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 int users;
private @Nullable com.neotys.neoload.model.scenario.@Valid Duration duration;
/**
* Creates a builder for {@link ImmutablePeakLoadPolicy ImmutablePeakLoadPolicy} instances.
*/
public Builder() {
if (!(this instanceof PeakLoadPolicy.Builder)) {
throw new UnsupportedOperationException("Use: new PeakLoadPolicy.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code PeakLoadPolicy} 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 PeakLoadPolicy.Builder from(PeakLoadPolicy instance) {
Objects.requireNonNull(instance, "instance");
users(instance.getUsers());
com.neotys.neoload.model.scenario.@Valid Duration durationValue = instance.getDuration();
if (durationValue != null) {
duration(durationValue);
}
return (PeakLoadPolicy.Builder) this;
}
/**
* Initializes the value for the {@link PeakLoadPolicy#getUsers() users} attribute.
* @param users The value for users
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("users")
public final PeakLoadPolicy.Builder users(int users) {
this.users = users;
return (PeakLoadPolicy.Builder) this;
}
/**
* Initializes the value for the {@link PeakLoadPolicy#getDuration() duration} attribute.
* @param duration The value for duration (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("duration")
public final PeakLoadPolicy.Builder duration(com.neotys.neoload.model.scenario.@Valid Duration duration) {
this.duration = duration;
return (PeakLoadPolicy.Builder) this;
}
/**
* Builds a new {@link ImmutablePeakLoadPolicy ImmutablePeakLoadPolicy}.
* @return An immutable instance of PeakLoadPolicy
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutablePeakLoadPolicy build() {
return new ImmutablePeakLoadPolicy(users, duration);
}
}
}