com.neotys.neoload.model.v3.project.scenario.ImmutableLoadDuration 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.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;
/**
* Immutable implementation of {@link LoadDuration}.
*
* Use the builder to create immutable instances:
* {@code new LoadDuration.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "LoadDuration"})
@Immutable
@CheckReturnValue
public final class ImmutableLoadDuration implements LoadDuration {
private final Integer value;
private final LoadDuration.Type type;
private ImmutableLoadDuration(Integer value, LoadDuration.Type type) {
this.value = value;
this.type = type;
}
/**
* @return The value of the {@code value} attribute
*/
@JsonProperty("value")
@Override
public Integer getValue() {
return value;
}
/**
* @return The value of the {@code type} attribute
*/
@JsonProperty("type")
@Override
public LoadDuration.Type getType() {
return type;
}
/**
* Copy the current immutable object by setting a value for the {@link LoadDuration#getValue() value} attribute.
* An equals check 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 ImmutableLoadDuration withValue(Integer value) {
if (Objects.equals(this.value, value)) return this;
return new ImmutableLoadDuration(value, this.type);
}
/**
* Copy the current immutable object by setting a value for the {@link LoadDuration#getType() type} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for type (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableLoadDuration withType(LoadDuration.Type value) {
if (this.type == value) return this;
return new ImmutableLoadDuration(this.value, value);
}
/**
* This instance is equal to all instances of {@code ImmutableLoadDuration} 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 ImmutableLoadDuration
&& equalTo((ImmutableLoadDuration) another);
}
private boolean equalTo(ImmutableLoadDuration another) {
return Objects.equals(value, another.value)
&& Objects.equals(type, another.type);
}
/**
* Computes a hash code from attributes: {@code value}, {@code type}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(value);
h += (h << 5) + Objects.hashCode(type);
return h;
}
/**
* Prints the immutable value {@code LoadDuration} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("LoadDuration")
.omitNullValues()
.add("value", value)
.add("type", type)
.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 LoadDuration {
@Nullable Integer value;
@Nullable LoadDuration.Type type;
@JsonProperty("value")
public void setValue(Integer value) {
this.value = value;
}
@JsonProperty("type")
public void setType(LoadDuration.Type type) {
this.type = type;
}
@Override
public Integer getValue() { throw new UnsupportedOperationException(); }
@Override
public LoadDuration.Type getType() { 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 ImmutableLoadDuration fromJson(Json json) {
LoadDuration.Builder builder = new LoadDuration.Builder();
if (json.value != null) {
builder.value(json.value);
}
if (json.type != null) {
builder.type(json.type);
}
return (ImmutableLoadDuration) builder.build();
}
/**
* Creates an immutable copy of a {@link LoadDuration} 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 LoadDuration instance
*/
public static ImmutableLoadDuration copyOf(LoadDuration instance) {
if (instance instanceof ImmutableLoadDuration) {
return (ImmutableLoadDuration) instance;
}
return new LoadDuration.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableLoadDuration ImmutableLoadDuration}.
* 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 Integer value;
private @Nullable LoadDuration.Type type;
/**
* Creates a builder for {@link ImmutableLoadDuration ImmutableLoadDuration} instances.
*/
public Builder() {
if (!(this instanceof LoadDuration.Builder)) {
throw new UnsupportedOperationException("Use: new LoadDuration.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code LoadDuration} 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 LoadDuration.Builder from(LoadDuration instance) {
Objects.requireNonNull(instance, "instance");
Integer valueValue = instance.getValue();
if (valueValue != null) {
value(valueValue);
}
LoadDuration.Type typeValue = instance.getType();
if (typeValue != null) {
type(typeValue);
}
return (LoadDuration.Builder) this;
}
/**
* Initializes the value for the {@link LoadDuration#getValue() value} attribute.
* @param value The value for value (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("value")
public final LoadDuration.Builder value(Integer value) {
this.value = value;
return (LoadDuration.Builder) this;
}
/**
* Initializes the value for the {@link LoadDuration#getType() type} attribute.
* @param type The value for type (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("type")
public final LoadDuration.Builder type(LoadDuration.Type type) {
this.type = type;
return (LoadDuration.Builder) this;
}
/**
* Builds a new {@link ImmutableLoadDuration ImmutableLoadDuration}.
* @return An immutable instance of LoadDuration
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableLoadDuration build() {
return new ImmutableLoadDuration(value, type);
}
}
}