com.neotys.neoload.model.v3.project.userpath.ImmutableCondition Maven / Gradle / Ivy
package com.neotys.neoload.model.v3.project.userpath;
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 Condition}.
*
* Use the builder to create immutable instances:
* {@code new Condition.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "Condition"})
@Immutable
@CheckReturnValue
public final class ImmutableCondition implements Condition {
private final java.lang.@Valid String operand1;
private final Condition.@Valid Operator operator;
private final @Nullable String operand2;
private ImmutableCondition(
java.lang.@Valid String operand1,
Condition.@Valid Operator operator,
@Nullable String operand2) {
this.operand1 = operand1;
this.operator = operator;
this.operand2 = operand2;
}
/**
* @return The value of the {@code operand1} attribute
*/
@JsonProperty("operand1")
@Override
public java.lang.@Valid String getOperand1() {
return operand1;
}
/**
* @return The value of the {@code operator} attribute
*/
@JsonProperty("operator")
@Override
public Condition.@Valid Operator getOperator() {
return operator;
}
/**
* @return The value of the {@code operand2} attribute
*/
@JsonProperty("operand2")
@Override
public java.util.@Valid Optional getOperand2() {
return java.util.Optional.ofNullable(operand2);
}
/**
* Copy the current immutable object by setting a value for the {@link Condition#getOperand1() operand1} 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 operand1 (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCondition withOperand1(java.lang.@Valid String value) {
if (this.operand1 == value) return this;
return new ImmutableCondition(value, this.operator, this.operand2);
}
/**
* Copy the current immutable object by setting a value for the {@link Condition#getOperator() operator} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for operator (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableCondition withOperator(Condition.@Valid Operator value) {
if (this.operator == value) return this;
return new ImmutableCondition(this.operand1, value, this.operand2);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Condition#getOperand2() operand2} attribute.
* @param value The value for operand2
* @return A modified copy of {@code this} object
*/
public final ImmutableCondition withOperand2(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "operand2");
if (Objects.equals(this.operand2, newValue)) return this;
return new ImmutableCondition(this.operand1, this.operator, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Condition#getOperand2() operand2} 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 operand2
* @return A modified copy of {@code this} object
*/
public final ImmutableCondition withOperand2(java.util.Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.operand2, value)) return this;
return new ImmutableCondition(this.operand1, this.operator, value);
}
/**
* This instance is equal to all instances of {@code ImmutableCondition} 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 ImmutableCondition
&& equalTo((ImmutableCondition) another);
}
private boolean equalTo(ImmutableCondition another) {
return Objects.equals(operand1, another.operand1)
&& Objects.equals(operator, another.operator)
&& Objects.equals(operand2, another.operand2);
}
/**
* Computes a hash code from attributes: {@code operand1}, {@code operator}, {@code operand2}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(operand1);
h += (h << 5) + Objects.hashCode(operator);
h += (h << 5) + Objects.hashCode(operand2);
return h;
}
/**
* Prints the immutable value {@code Condition} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Condition")
.omitNullValues()
.add("operand1", operand1)
.add("operator", operator)
.add("operand2", operand2)
.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 Condition {
@Nullable java.lang.@Valid String operand1;
@Nullable Condition.@Valid Operator operator;
java.util.@Valid Optional operand2 = java.util.Optional.empty();
@JsonProperty("operand1")
public void setOperand1(java.lang.@Valid String operand1) {
this.operand1 = operand1;
}
@JsonProperty("operator")
public void setOperator(Condition.@Valid Operator operator) {
this.operator = operator;
}
@JsonProperty("operand2")
public void setOperand2(java.util.@Valid Optional operand2) {
this.operand2 = operand2;
}
@Override
public java.lang.@Valid String getOperand1() { throw new UnsupportedOperationException(); }
@Override
public Condition.@Valid Operator getOperator() { throw new UnsupportedOperationException(); }
@Override
public java.util.@Valid Optional getOperand2() { 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 ImmutableCondition fromJson(Json json) {
Condition.Builder builder = new Condition.Builder();
if (json.operand1 != null) {
builder.operand1(json.operand1);
}
if (json.operator != null) {
builder.operator(json.operator);
}
if (json.operand2 != null) {
builder.operand2(json.operand2);
}
return (ImmutableCondition) builder.build();
}
/**
* Creates an immutable copy of a {@link Condition} 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 Condition instance
*/
public static ImmutableCondition copyOf(Condition instance) {
if (instance instanceof ImmutableCondition) {
return (ImmutableCondition) instance;
}
return new Condition.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableCondition ImmutableCondition}.
* 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 java.lang.@Valid String operand1;
private @Nullable Condition.@Valid Operator operator;
private @Nullable String operand2;
/**
* Creates a builder for {@link ImmutableCondition ImmutableCondition} instances.
*/
public Builder() {
if (!(this instanceof Condition.Builder)) {
throw new UnsupportedOperationException("Use: new Condition.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code Condition} 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 Condition.Builder from(Condition instance) {
Objects.requireNonNull(instance, "instance");
java.lang.@Valid String operand1Value = instance.getOperand1();
if (operand1Value != null) {
operand1(operand1Value);
}
Condition.@Valid Operator operatorValue = instance.getOperator();
if (operatorValue != null) {
operator(operatorValue);
}
java.util.@Valid Optional operand2Optional = instance.getOperand2();
if (operand2Optional.isPresent()) {
operand2(operand2Optional);
}
return (Condition.Builder) this;
}
/**
* Initializes the value for the {@link Condition#getOperand1() operand1} attribute.
* @param operand1 The value for operand1 (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("operand1")
public final Condition.Builder operand1(java.lang.@Valid String operand1) {
this.operand1 = operand1;
return (Condition.Builder) this;
}
/**
* Initializes the value for the {@link Condition#getOperator() operator} attribute.
* @param operator The value for operator (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("operator")
public final Condition.Builder operator(Condition.@Valid Operator operator) {
this.operator = operator;
return (Condition.Builder) this;
}
/**
* Initializes the optional value {@link Condition#getOperand2() operand2} to operand2.
* @param operand2 The value for operand2
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Condition.Builder operand2(String operand2) {
this.operand2 = Objects.requireNonNull(operand2, "operand2");
return (Condition.Builder) this;
}
/**
* Initializes the optional value {@link Condition#getOperand2() operand2} to operand2.
* @param operand2 The value for operand2
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("operand2")
public final Condition.Builder operand2(java.util.Optional operand2) {
this.operand2 = operand2.orElse(null);
return (Condition.Builder) this;
}
/**
* Builds a new {@link ImmutableCondition ImmutableCondition}.
* @return An immutable instance of Condition
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableCondition build() {
return new ImmutableCondition(operand1, operator, operand2);
}
}
}