com.neotys.neoload.model.v3.project.userpath.ImmutableThinkTime Maven / Gradle / Ivy
package com.neotys.neoload.model.v3.project.userpath;
import com.google.common.base.MoreObjects;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.neotys.neoload.model.v3.project.Element;
import com.neotys.neoload.model.v3.validation.groups.NeoLoad;
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.constraints.Pattern;
/**
* Immutable implementation of {@link ThinkTime}.
*
* Use the builder to create immutable instances:
* {@code new ThinkTime.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "ThinkTime"})
@Immutable
@CheckReturnValue
public final class ImmutableThinkTime implements ThinkTime {
private final String name;
private final java.lang.@Pattern(regexp = "(\\d+|\\$\\{\\w+\\})", groups = {NeoLoad.class}) String value;
private final @Nullable String description;
private ImmutableThinkTime(ImmutableThinkTime.Builder builder) {
this.value = builder.value;
this.description = builder.description;
this.name = builder.name != null
? builder.name
: Objects.requireNonNull(ThinkTime.super.getName(), "name");
}
private ImmutableThinkTime(
String name,
java.lang.@Pattern(regexp = "(\\d+|\\$\\{\\w+\\})", groups = {NeoLoad.class}) String value,
@Nullable String description) {
this.name = name;
this.value = value;
this.description = description;
}
/**
* @return The value of the {@code name} attribute
*/
@Override
public String getName() {
return name;
}
/**
* @return The value of the {@code value} attribute
*/
@Override
public java.lang.@Pattern(regexp = "(\\d+|\\$\\{\\w+\\})", groups = {NeoLoad.class}) String getValue() {
return value;
}
/**
* @return The value of the {@code description} attribute
*/
@Override
public Optional getDescription() {
return Optional.ofNullable(description);
}
/**
* Copy the current immutable object by setting a value for the {@link ThinkTime#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 ImmutableThinkTime withName(String value) {
if (this.name.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "name");
return new ImmutableThinkTime(newValue, this.value, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link ThinkTime#getValue() value} 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 value (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableThinkTime withValue(java.lang.@Pattern(regexp = "(\\d+|\\$\\{\\w+\\})", groups = {NeoLoad.class}) String value) {
if (this.value == value) return this;
return new ImmutableThinkTime(this.name, value, this.description);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link ThinkTime#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableThinkTime withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutableThinkTime(this.name, this.value, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link ThinkTime#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 ImmutableThinkTime withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutableThinkTime(this.name, this.value, value);
}
/**
* This instance is equal to all instances of {@code ImmutableThinkTime} 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 ImmutableThinkTime
&& equalTo((ImmutableThinkTime) another);
}
private boolean equalTo(ImmutableThinkTime another) {
return name.equals(another.name)
&& Objects.equals(value, another.value)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code name}, {@code value}, {@code description}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + name.hashCode();
h += (h << 5) + Objects.hashCode(value);
h += (h << 5) + Objects.hashCode(description);
return h;
}
/**
* Prints the immutable value {@code ThinkTime} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("ThinkTime")
.omitNullValues()
.add("name", name)
.add("value", value)
.add("description", description)
.toString();
}
/**
* Creates an immutable copy of a {@link ThinkTime} 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 ThinkTime instance
*/
public static ImmutableThinkTime copyOf(ThinkTime instance) {
if (instance instanceof ImmutableThinkTime) {
return (ImmutableThinkTime) instance;
}
return new ThinkTime.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableThinkTime ImmutableThinkTime}.
* 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 java.lang.@Pattern(regexp = "(\\d+|\\$\\{\\w+\\})", groups = {NeoLoad.class}) String value;
private @Nullable String description;
/**
* Creates a builder for {@link ImmutableThinkTime ImmutableThinkTime} instances.
*/
public Builder() {
if (!(this instanceof ThinkTime.Builder)) {
throw new UnsupportedOperationException("Use: new ThinkTime.Builder()");
}
}
/**
* 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 ThinkTime.Builder from(Element instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (ThinkTime.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.userpath.StepDuration} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final ThinkTime.Builder from(StepDuration instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (ThinkTime.Builder) this;
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.userpath.ThinkTime} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final ThinkTime.Builder from(ThinkTime instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (ThinkTime.Builder) this;
}
private void from(Object object) {
long bits = 0;
if (object instanceof Element) {
Element instance = (Element) object;
if ((bits & 0x1L) == 0) {
name(instance.getName());
bits |= 0x1L;
}
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
description(descriptionOptional);
}
}
if (object instanceof StepDuration) {
StepDuration instance = (StepDuration) object;
if ((bits & 0x1L) == 0) {
name(instance.getName());
bits |= 0x1L;
}
java.lang.@Pattern(regexp = "(\\d+|\\$\\{\\w+\\})", groups = {NeoLoad.class}) String valueValue = instance.getValue();
if (valueValue != null) {
value(valueValue);
}
}
}
/**
* Initializes the value for the {@link ThinkTime#getName() name} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link ThinkTime#getName() name}.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final ThinkTime.Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
return (ThinkTime.Builder) this;
}
/**
* Initializes the value for the {@link ThinkTime#getValue() value} attribute.
* @param value The value for value (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final ThinkTime.Builder value(java.lang.@Pattern(regexp = "(\\d+|\\$\\{\\w+\\})", groups = {NeoLoad.class}) String value) {
this.value = value;
return (ThinkTime.Builder) this;
}
/**
* Initializes the optional value {@link ThinkTime#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final ThinkTime.Builder description(String description) {
this.description = Objects.requireNonNull(description, "description");
return (ThinkTime.Builder) this;
}
/**
* Initializes the optional value {@link ThinkTime#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final ThinkTime.Builder description(Optional description) {
this.description = description.orElse(null);
return (ThinkTime.Builder) this;
}
/**
* Builds a new {@link ImmutableThinkTime ImmutableThinkTime}.
* @return An immutable instance of ThinkTime
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableThinkTime build() {
return new ImmutableThinkTime(this);
}
}
}