com.neotys.neoload.model.repository.ImmutableIfThenElse Maven / Gradle / Ivy
package com.neotys.neoload.model.repository;
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.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.neotys.neoload.model.core.Element;
import java.util.List;
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;
/**
* Immutable implementation of {@link IfThenElse}.
*
* Use the builder to create immutable instances:
* {@code ImmutableIfThenElse.builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "IfThenElse"})
@Deprecated
@Immutable
@CheckReturnValue
public final class ImmutableIfThenElse implements IfThenElse {
private final Conditions conditions;
private final ContainerForMulti then;
private final ContainerForMulti getElse;
private final String name;
private final @Nullable String description;
private ImmutableIfThenElse(
Conditions conditions,
ContainerForMulti then,
ContainerForMulti getElse,
String name,
@Nullable String description) {
this.conditions = conditions;
this.then = then;
this.getElse = getElse;
this.name = name;
this.description = description;
}
/**
* @return The value of the {@code conditions} attribute
*/
@JsonProperty("conditions")
@Override
public Conditions getConditions() {
return conditions;
}
/**
* @return The value of the {@code then} attribute
*/
@JsonProperty("then")
@Override
public ContainerForMulti getThen() {
return then;
}
/**
* @return The value of the {@code getElse} attribute
*/
@JsonProperty("else")
@Override
public ContainerForMulti getElse() {
return getElse;
}
/**
* @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 IfThenElse#getConditions() conditions} 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 conditions
* @return A modified copy of the {@code this} object
*/
public final ImmutableIfThenElse withConditions(Conditions value) {
if (this.conditions == value) return this;
Conditions newValue = Objects.requireNonNull(value, "conditions");
return new ImmutableIfThenElse(newValue, this.then, this.getElse, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link IfThenElse#getThen() then} 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 then
* @return A modified copy of the {@code this} object
*/
public final ImmutableIfThenElse withThen(ContainerForMulti value) {
if (this.then == value) return this;
ContainerForMulti newValue = Objects.requireNonNull(value, "then");
return new ImmutableIfThenElse(this.conditions, newValue, this.getElse, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link IfThenElse#getElse() else} 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 getElse
* @return A modified copy of the {@code this} object
*/
public final ImmutableIfThenElse withElse(ContainerForMulti value) {
if (this.getElse == value) return this;
ContainerForMulti newValue = Objects.requireNonNull(value, "getElse");
return new ImmutableIfThenElse(this.conditions, this.then, newValue, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link IfThenElse#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 ImmutableIfThenElse withName(String value) {
if (this.name.equals(value)) return this;
String newValue = Objects.requireNonNull(value, "name");
return new ImmutableIfThenElse(this.conditions, this.then, this.getElse, newValue, this.description);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link IfThenElse#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableIfThenElse withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutableIfThenElse(this.conditions, this.then, this.getElse, this.name, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link IfThenElse#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 ImmutableIfThenElse withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutableIfThenElse(this.conditions, this.then, this.getElse, this.name, value);
}
/**
* This instance is equal to all instances of {@code ImmutableIfThenElse} 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 ImmutableIfThenElse
&& equalTo((ImmutableIfThenElse) another);
}
private boolean equalTo(ImmutableIfThenElse another) {
return conditions.equals(another.conditions)
&& then.equals(another.then)
&& getElse.equals(another.getElse)
&& name.equals(another.name)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code conditions}, {@code then}, {@code getElse}, {@code name}, {@code description}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + conditions.hashCode();
h += (h << 5) + then.hashCode();
h += (h << 5) + getElse.hashCode();
h += (h << 5) + name.hashCode();
h += (h << 5) + Objects.hashCode(description);
return h;
}
/**
* Prints the immutable value {@code IfThenElse} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("IfThenElse")
.omitNullValues()
.add("conditions", conditions)
.add("then", then)
.add("else", getElse)
.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 IfThenElse {
@Nullable Conditions conditions;
@Nullable ContainerForMulti then;
@Nullable ContainerForMulti getElse;
@Nullable String name;
Optional description = Optional.empty();
@JsonProperty("conditions")
public void setConditions(Conditions conditions) {
this.conditions = conditions;
}
@JsonProperty("then")
public void setThen(ContainerForMulti then) {
this.then = then;
}
@JsonProperty("else")
public void setElse(ContainerForMulti getElse) {
this.getElse = getElse;
}
@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 Conditions getConditions() { throw new UnsupportedOperationException(); }
@Override
public ContainerForMulti getThen() { throw new UnsupportedOperationException(); }
@Override
public ContainerForMulti getElse() { 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 ImmutableIfThenElse fromJson(Json json) {
ImmutableIfThenElse.Builder builder = ImmutableIfThenElse.builder();
if (json.conditions != null) {
builder.conditions(json.conditions);
}
if (json.then != null) {
builder.then(json.then);
}
if (json.getElse != null) {
builder.getElse(json.getElse);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.description != null) {
builder.description(json.description);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link IfThenElse} 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 IfThenElse instance
*/
public static ImmutableIfThenElse copyOf(IfThenElse instance) {
if (instance instanceof ImmutableIfThenElse) {
return (ImmutableIfThenElse) instance;
}
return ImmutableIfThenElse.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableIfThenElse ImmutableIfThenElse}.
* @return A new ImmutableIfThenElse builder
*/
public static ImmutableIfThenElse.Builder builder() {
return new ImmutableIfThenElse.Builder();
}
/**
* Builds instances of type {@link ImmutableIfThenElse ImmutableIfThenElse}.
* 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 final class Builder {
private static final long INIT_BIT_CONDITIONS = 0x1L;
private static final long INIT_BIT_THEN = 0x2L;
private static final long INIT_BIT_GET_ELSE = 0x4L;
private static final long INIT_BIT_NAME = 0x8L;
private long initBits = 0xfL;
private @Nullable Conditions conditions;
private @Nullable ContainerForMulti then;
private @Nullable ContainerForMulti getElse;
private @Nullable String name;
private @Nullable String description;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.repository.IfThenElse} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(IfThenElse instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
/**
* 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 Builder from(Element instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return this;
}
private void from(Object object) {
if (object instanceof IfThenElse) {
IfThenElse instance = (IfThenElse) object;
conditions(instance.getConditions());
getElse(instance.getElse());
then(instance.getThen());
}
if (object instanceof Element) {
Element instance = (Element) object;
name(instance.getName());
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
description(descriptionOptional);
}
}
}
/**
* Initializes the value for the {@link IfThenElse#getConditions() conditions} attribute.
* @param conditions The value for conditions
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("conditions")
public final Builder conditions(Conditions conditions) {
this.conditions = Objects.requireNonNull(conditions, "conditions");
initBits &= ~INIT_BIT_CONDITIONS;
return this;
}
/**
* Initializes the value for the {@link IfThenElse#getThen() then} attribute.
* @param then The value for then
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("then")
public final Builder then(ContainerForMulti then) {
this.then = Objects.requireNonNull(then, "then");
initBits &= ~INIT_BIT_THEN;
return this;
}
/**
* Initializes the value for the {@link IfThenElse#getElse() else} attribute.
* @param getElse The value for getElse
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("else")
public final Builder getElse(ContainerForMulti getElse) {
this.getElse = Objects.requireNonNull(getElse, "getElse");
initBits &= ~INIT_BIT_GET_ELSE;
return this;
}
/**
* Initializes the value for the {@link IfThenElse#getName() name} attribute.
* @param name The value for name
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("name")
public final Builder name(String name) {
this.name = Objects.requireNonNull(name, "name");
initBits &= ~INIT_BIT_NAME;
return this;
}
/**
* Initializes the optional value {@link IfThenElse#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Builder description(String description) {
this.description = Objects.requireNonNull(description, "description");
return this;
}
/**
* Initializes the optional value {@link IfThenElse#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 Builder description(Optional description) {
this.description = description.orElse(null);
return this;
}
/**
* Builds a new {@link ImmutableIfThenElse ImmutableIfThenElse}.
* @return An immutable instance of IfThenElse
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableIfThenElse build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableIfThenElse(conditions, then, getElse, name, description);
}
private String formatRequiredAttributesMessage() {
List attributes = Lists.newArrayList();
if ((initBits & INIT_BIT_CONDITIONS) != 0) attributes.add("conditions");
if ((initBits & INIT_BIT_THEN) != 0) attributes.add("then");
if ((initBits & INIT_BIT_GET_ELSE) != 0) attributes.add("else");
if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name");
return "Cannot build IfThenElse, some of required attributes are not set " + attributes;
}
}
}