com.neotys.neoload.model.v3.project.sla.ImmutableSlaThreshold Maven / Gradle / Ivy
package com.neotys.neoload.model.v3.project.sla;
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.v3.validation.constraints.RangeCheck;
import com.neotys.neoload.model.v3.validation.groups.NeoLoad;
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 SlaThreshold}.
*
* Use the builder to create immutable instances:
* {@code new SlaThreshold.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "SlaThreshold"})
@Immutable
@CheckReturnValue
public final class ImmutableSlaThreshold implements SlaThreshold {
private final SlaThreshold.KPI kpi;
private final @Nullable Integer percent;
private final ImmutableList conditions;
private final SlaThreshold.Scope scope;
private ImmutableSlaThreshold(ImmutableSlaThreshold.Builder builder) {
this.kpi = builder.kpi;
this.percent = builder.percent;
this.conditions = builder.conditions.build();
this.scope = builder.scope != null
? builder.scope
: Objects.requireNonNull(SlaThreshold.super.getScope(), "scope");
}
private ImmutableSlaThreshold(
SlaThreshold.KPI kpi,
@Nullable Integer percent,
ImmutableList conditions,
SlaThreshold.Scope scope) {
this.kpi = kpi;
this.percent = percent;
this.conditions = conditions;
this.scope = scope;
}
/**
* @return The value of the {@code kpi} attribute
*/
@JsonProperty("kpi")
@Override
public SlaThreshold.KPI getKpi() {
return kpi;
}
/**
* @return The value of the {@code percent} attribute
*/
@JsonProperty("percent")
@Override
public java.util.@RangeCheck(min = 0, max = 100, groups = {NeoLoad.class}) Optional getPercent() {
return java.util.Optional.ofNullable(percent);
}
/**
* @return The value of the {@code conditions} attribute
*/
@JsonProperty("conditions")
@Override
public ImmutableList getConditions() {
return conditions;
}
/**
* @return The value of the {@code scope} attribute
*/
@JsonProperty("scope")
@Override
public SlaThreshold.Scope getScope() {
return scope;
}
/**
* Copy the current immutable object by setting a value for the {@link SlaThreshold#getKpi() kpi} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for kpi (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableSlaThreshold withKpi(SlaThreshold.KPI value) {
if (this.kpi == value) return this;
return new ImmutableSlaThreshold(value, this.percent, this.conditions, this.scope);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link SlaThreshold#getPercent() percent} attribute.
* @param value The value for percent
* @return A modified copy of {@code this} object
*/
public final ImmutableSlaThreshold withPercent(int value) {
@Nullable Integer newValue = value;
if (Objects.equals(this.percent, newValue)) return this;
return new ImmutableSlaThreshold(this.kpi, newValue, this.conditions, this.scope);
}
/**
* Copy the current immutable object by setting an optional value for the {@link SlaThreshold#getPercent() percent} 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 percent
* @return A modified copy of {@code this} object
*/
public final ImmutableSlaThreshold withPercent(java.util.Optional optional) {
@Nullable Integer value = optional.orElse(null);
if (Objects.equals(this.percent, value)) return this;
return new ImmutableSlaThreshold(this.kpi, value, this.conditions, this.scope);
}
/**
* Copy the current immutable object with elements that replace the content of {@link SlaThreshold#getConditions() conditions}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableSlaThreshold withConditions(SlaThresholdCondition... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableSlaThreshold(this.kpi, this.percent, newValue, this.scope);
}
/**
* Copy the current immutable object with elements that replace the content of {@link SlaThreshold#getConditions() conditions}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of conditions elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableSlaThreshold withConditions(Iterable extends SlaThresholdCondition> elements) {
if (this.conditions == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableSlaThreshold(this.kpi, this.percent, newValue, this.scope);
}
/**
* Copy the current immutable object by setting a value for the {@link SlaThreshold#getScope() scope} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for scope
* @return A modified copy of the {@code this} object
*/
public final ImmutableSlaThreshold withScope(SlaThreshold.Scope value) {
if (this.scope == value) return this;
SlaThreshold.Scope newValue = Objects.requireNonNull(value, "scope");
return new ImmutableSlaThreshold(this.kpi, this.percent, this.conditions, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableSlaThreshold} 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 ImmutableSlaThreshold
&& equalTo((ImmutableSlaThreshold) another);
}
private boolean equalTo(ImmutableSlaThreshold another) {
return Objects.equals(kpi, another.kpi)
&& Objects.equals(percent, another.percent)
&& conditions.equals(another.conditions)
&& scope.equals(another.scope);
}
/**
* Computes a hash code from attributes: {@code kpi}, {@code percent}, {@code conditions}, {@code scope}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(kpi);
h += (h << 5) + Objects.hashCode(percent);
h += (h << 5) + conditions.hashCode();
h += (h << 5) + scope.hashCode();
return h;
}
/**
* Prints the immutable value {@code SlaThreshold} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SlaThreshold")
.omitNullValues()
.add("kpi", kpi)
.add("percent", percent)
.add("conditions", conditions)
.add("scope", scope)
.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 SlaThreshold {
@Nullable SlaThreshold.KPI kpi;
java.util.@RangeCheck(min = 0, max = 100, groups = {NeoLoad.class}) Optional percent = java.util.Optional.empty();
java.util.@Valid List conditions = ImmutableList.of();
@Nullable SlaThreshold.Scope scope;
@JsonProperty("kpi")
public void setKpi(SlaThreshold.KPI kpi) {
this.kpi = kpi;
}
@JsonProperty("percent")
public void setPercent(java.util.@RangeCheck(min = 0, max = 100, groups = {NeoLoad.class}) Optional percent) {
this.percent = percent;
}
@JsonProperty("conditions")
public void setConditions(java.util.@Valid List conditions) {
this.conditions = conditions;
}
@JsonProperty("scope")
public void setScope(SlaThreshold.Scope scope) {
this.scope = scope;
}
@Override
public SlaThreshold.KPI getKpi() { throw new UnsupportedOperationException(); }
@Override
public java.util.@RangeCheck(min = 0, max = 100, groups = {NeoLoad.class}) Optional getPercent() { throw new UnsupportedOperationException(); }
@Override
public java.util.@Valid List getConditions() { throw new UnsupportedOperationException(); }
@Override
public SlaThreshold.Scope getScope() { 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 ImmutableSlaThreshold fromJson(Json json) {
SlaThreshold.Builder builder = new SlaThreshold.Builder();
if (json.kpi != null) {
builder.kpi(json.kpi);
}
if (json.percent != null) {
builder.percent(json.percent);
}
if (json.conditions != null) {
builder.addAllConditions(json.conditions);
}
if (json.scope != null) {
builder.scope(json.scope);
}
return (ImmutableSlaThreshold) builder.build();
}
/**
* Creates an immutable copy of a {@link SlaThreshold} 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 SlaThreshold instance
*/
public static ImmutableSlaThreshold copyOf(SlaThreshold instance) {
if (instance instanceof ImmutableSlaThreshold) {
return (ImmutableSlaThreshold) instance;
}
return new SlaThreshold.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableSlaThreshold ImmutableSlaThreshold}.
* 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 SlaThreshold.KPI kpi;
private @Nullable Integer percent;
private ImmutableList.Builder conditions = ImmutableList.builder();
private @Nullable SlaThreshold.Scope scope;
/**
* Creates a builder for {@link ImmutableSlaThreshold ImmutableSlaThreshold} instances.
*/
public Builder() {
if (!(this instanceof SlaThreshold.Builder)) {
throw new UnsupportedOperationException("Use: new SlaThreshold.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code SlaThreshold} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SlaThreshold.Builder from(SlaThreshold instance) {
Objects.requireNonNull(instance, "instance");
SlaThreshold.KPI kpiValue = instance.getKpi();
if (kpiValue != null) {
kpi(kpiValue);
}
java.util.@RangeCheck(min = 0, max = 100, groups = {NeoLoad.class}) Optional percentOptional = instance.getPercent();
if (percentOptional.isPresent()) {
percent(percentOptional);
}
addAllConditions(instance.getConditions());
scope(instance.getScope());
return (SlaThreshold.Builder) this;
}
/**
* Initializes the value for the {@link SlaThreshold#getKpi() kpi} attribute.
* @param kpi The value for kpi (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("kpi")
public final SlaThreshold.Builder kpi(SlaThreshold.KPI kpi) {
this.kpi = kpi;
return (SlaThreshold.Builder) this;
}
/**
* Initializes the optional value {@link SlaThreshold#getPercent() percent} to percent.
* @param percent The value for percent
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final SlaThreshold.Builder percent(int percent) {
this.percent = percent;
return (SlaThreshold.Builder) this;
}
/**
* Initializes the optional value {@link SlaThreshold#getPercent() percent} to percent.
* @param percent The value for percent
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("percent")
public final SlaThreshold.Builder percent(java.util.Optional percent) {
this.percent = percent.orElse(null);
return (SlaThreshold.Builder) this;
}
/**
* Adds one element to {@link SlaThreshold#getConditions() conditions} list.
* @param element A conditions element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SlaThreshold.Builder addConditions(SlaThresholdCondition element) {
this.conditions.add(element);
return (SlaThreshold.Builder) this;
}
/**
* Adds elements to {@link SlaThreshold#getConditions() conditions} list.
* @param elements An array of conditions elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SlaThreshold.Builder addConditions(SlaThresholdCondition... elements) {
this.conditions.add(elements);
return (SlaThreshold.Builder) this;
}
/**
* Sets or replaces all elements for {@link SlaThreshold#getConditions() conditions} list.
* @param elements An iterable of conditions elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("conditions")
public final SlaThreshold.Builder conditions(Iterable extends SlaThresholdCondition> elements) {
this.conditions = ImmutableList.builder();
return addAllConditions(elements);
}
/**
* Adds elements to {@link SlaThreshold#getConditions() conditions} list.
* @param elements An iterable of conditions elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SlaThreshold.Builder addAllConditions(Iterable extends SlaThresholdCondition> elements) {
this.conditions.addAll(elements);
return (SlaThreshold.Builder) this;
}
/**
* Initializes the value for the {@link SlaThreshold#getScope() scope} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link SlaThreshold#getScope() scope}.
* @param scope The value for scope
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("scope")
public final SlaThreshold.Builder scope(SlaThreshold.Scope scope) {
this.scope = Objects.requireNonNull(scope, "scope");
return (SlaThreshold.Builder) this;
}
/**
* Builds a new {@link ImmutableSlaThreshold ImmutableSlaThreshold}.
* @return An immutable instance of SlaThreshold
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSlaThreshold build() {
return new ImmutableSlaThreshold(this);
}
}
}