com.neotys.neoload.model.scenario.ImmutableScenario 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.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.neotys.neoload.model.core.Element;
import java.util.Objects;
import java.util.Optional;
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 Scenario}.
*
* Use the builder to create immutable instances:
* {@code new Scenario.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "Scenario"})
@Deprecated
@Immutable
@CheckReturnValue
public final class ImmutableScenario implements Scenario {
private final String slaProfile;
private final ImmutableList populations;
private final String name;
private final @Nullable String description;
private ImmutableScenario(
String slaProfile,
ImmutableList populations,
String name,
@Nullable String description) {
this.slaProfile = slaProfile;
this.populations = populations;
this.name = name;
this.description = description;
}
/**
* @return The value of the {@code slaProfile} attribute
*/
@JsonProperty("sla_profile")
@Override
public String getSlaProfile() {
return slaProfile;
}
/**
* @return The value of the {@code populations} attribute
*/
@JsonProperty("populations")
@Override
public ImmutableList getPopulations() {
return populations;
}
/**
* @return The value of the {@code name} attribute
*/
@JsonProperty("name")
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code description} attribute
*/
@JsonProperty("description")
@Override
public Optional getDescription() {
return Optional.ofNullable(description);
}
/**
* Copy the current immutable object by setting a value for the {@link Scenario#getSlaProfile() slaProfile} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for slaProfile (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableScenario withSlaProfile(String value) {
if (Objects.equals(this.slaProfile, value)) return this;
return new ImmutableScenario(value, this.populations, this.name, this.description);
}
/**
* Copy the current immutable object with elements that replace the content of {@link Scenario#getPopulations() populations}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableScenario withPopulations(PopulationPolicy... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableScenario(this.slaProfile, newValue, this.name, this.description);
}
/**
* Copy the current immutable object with elements that replace the content of {@link Scenario#getPopulations() populations}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of populations elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableScenario withPopulations(Iterable extends PopulationPolicy> elements) {
if (this.populations == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableScenario(this.slaProfile, newValue, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link Scenario#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 ImmutableScenario withName(String value) {
if (Objects.equals(this.name, value)) return this;
return new ImmutableScenario(this.slaProfile, this.populations, value, this.description);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Scenario#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableScenario withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutableScenario(this.slaProfile, this.populations, this.name, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Scenario#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 ImmutableScenario withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutableScenario(this.slaProfile, this.populations, this.name, value);
}
/**
* This instance is equal to all instances of {@code ImmutableScenario} 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 ImmutableScenario
&& equalTo((ImmutableScenario) another);
}
private boolean equalTo(ImmutableScenario another) {
return Objects.equals(slaProfile, another.slaProfile)
&& populations.equals(another.populations)
&& Objects.equals(name, another.name)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code slaProfile}, {@code populations}, {@code name}, {@code description}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(slaProfile);
h += (h << 5) + populations.hashCode();
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + Objects.hashCode(description);
return h;
}
/**
* Prints the immutable value {@code Scenario} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Scenario")
.omitNullValues()
.add("slaProfile", slaProfile)
.add("populations", populations)
.add("name", name)
.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 Scenario {
@Nullable String slaProfile;
java.util.@Valid List populations = ImmutableList.of();
@Nullable String name;
Optional description = Optional.empty();
@JsonProperty("sla_profile")
public void setSlaProfile(String slaProfile) {
this.slaProfile = slaProfile;
}
@JsonProperty("populations")
public void setPopulations(java.util.@Valid List populations) {
this.populations = populations;
}
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("description")
public void setDescription(Optional description) {
this.description = description;
}
@Override
public Element withName(String of) { throw new UnsupportedOperationException(); }
@Override
public String getSlaProfile() { throw new UnsupportedOperationException(); }
@Override
public java.util.@Valid List getPopulations() { throw new UnsupportedOperationException(); }
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public 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 ImmutableScenario fromJson(Json json) {
Scenario.Builder builder = new Scenario.Builder();
if (json.slaProfile != null) {
builder.slaProfile(json.slaProfile);
}
if (json.populations != null) {
builder.addAllPopulations(json.populations);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.description != null) {
builder.description(json.description);
}
return (ImmutableScenario) builder.build();
}
/**
* Creates an immutable copy of a {@link Scenario} 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 Scenario instance
*/
public static ImmutableScenario copyOf(Scenario instance) {
if (instance instanceof ImmutableScenario) {
return (ImmutableScenario) instance;
}
return new Scenario.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableScenario ImmutableScenario}.
* 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 slaProfile;
private ImmutableList.Builder populations = ImmutableList.builder();
private @Nullable String name;
private @Nullable String description;
/**
* Creates a builder for {@link ImmutableScenario ImmutableScenario} instances.
*/
public Builder() {
if (!(this instanceof Scenario.Builder)) {
throw new UnsupportedOperationException("Use: new Scenario.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.core.Element} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Scenario.Builder from(Element instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (Scenario.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.scenario.Scenario} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Scenario.Builder from(Scenario instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (Scenario.Builder) this;
}
private void from(Object object) {
if (object instanceof Element) {
Element instance = (Element) object;
String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
description(descriptionOptional);
}
}
if (object instanceof Scenario) {
Scenario instance = (Scenario) object;
String slaProfileValue = instance.getSlaProfile();
if (slaProfileValue != null) {
slaProfile(slaProfileValue);
}
addAllPopulations(instance.getPopulations());
}
}
/**
* Initializes the value for the {@link Scenario#getSlaProfile() slaProfile} attribute.
* @param slaProfile The value for slaProfile (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("sla_profile")
public final Scenario.Builder slaProfile(String slaProfile) {
this.slaProfile = slaProfile;
return (Scenario.Builder) this;
}
/**
* Adds one element to {@link Scenario#getPopulations() populations} list.
* @param element A populations element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Scenario.Builder addPopulations(PopulationPolicy element) {
this.populations.add(element);
return (Scenario.Builder) this;
}
/**
* Adds elements to {@link Scenario#getPopulations() populations} list.
* @param elements An array of populations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Scenario.Builder addPopulations(PopulationPolicy... elements) {
this.populations.add(elements);
return (Scenario.Builder) this;
}
/**
* Sets or replaces all elements for {@link Scenario#getPopulations() populations} list.
* @param elements An iterable of populations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("populations")
public final Scenario.Builder populations(Iterable extends PopulationPolicy> elements) {
this.populations = ImmutableList.builder();
return addAllPopulations(elements);
}
/**
* Adds elements to {@link Scenario#getPopulations() populations} list.
* @param elements An iterable of populations elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Scenario.Builder addAllPopulations(Iterable extends PopulationPolicy> elements) {
this.populations.addAll(elements);
return (Scenario.Builder) this;
}
/**
* Initializes the value for the {@link Scenario#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 Scenario.Builder name(String name) {
this.name = name;
return (Scenario.Builder) this;
}
/**
* Initializes the optional value {@link Scenario#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Scenario.Builder description(String description) {
this.description = Objects.requireNonNull(description, "description");
return (Scenario.Builder) this;
}
/**
* Initializes the optional value {@link Scenario#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 Scenario.Builder description(Optional description) {
this.description = description.orElse(null);
return (Scenario.Builder) this;
}
/**
* Builds a new {@link ImmutableScenario ImmutableScenario}.
* @return An immutable instance of Scenario
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableScenario build() {
return new ImmutableScenario(slaProfile, populations.build(), name, description);
}
}
}