com.neotys.neoload.model.v3.project.sla.ImmutableSlaProfile 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.project.Element;
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.Valid;
/**
* Immutable implementation of {@link SlaProfile}.
*
* Use the builder to create immutable instances:
* {@code new SlaProfile.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "SlaProfile"})
@Immutable
@CheckReturnValue
public final class ImmutableSlaProfile implements SlaProfile {
private final ImmutableList thresholds;
private final String name;
private final @Nullable String description;
private ImmutableSlaProfile(
ImmutableList thresholds,
String name,
@Nullable String description) {
this.thresholds = thresholds;
this.name = name;
this.description = description;
}
/**
* @return The value of the {@code thresholds} attribute
*/
@JsonProperty("thresholds")
@Override
public ImmutableList getThresholds() {
return thresholds;
}
/**
* @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 with elements that replace the content of {@link SlaProfile#getThresholds() thresholds}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableSlaProfile withThresholds(SlaThreshold... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableSlaProfile(newValue, this.name, this.description);
}
/**
* Copy the current immutable object with elements that replace the content of {@link SlaProfile#getThresholds() thresholds}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of thresholds elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableSlaProfile withThresholds(Iterable extends SlaThreshold> elements) {
if (this.thresholds == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableSlaProfile(newValue, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link SlaProfile#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 (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableSlaProfile withName(String value) {
if (Objects.equals(this.name, value)) return this;
return new ImmutableSlaProfile(this.thresholds, value, this.description);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link SlaProfile#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableSlaProfile withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutableSlaProfile(this.thresholds, this.name, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link SlaProfile#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 ImmutableSlaProfile withDescription(Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutableSlaProfile(this.thresholds, this.name, value);
}
/**
* This instance is equal to all instances of {@code ImmutableSlaProfile} 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 ImmutableSlaProfile
&& equalTo((ImmutableSlaProfile) another);
}
private boolean equalTo(ImmutableSlaProfile another) {
return thresholds.equals(another.thresholds)
&& Objects.equals(name, another.name)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code thresholds}, {@code name}, {@code description}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + thresholds.hashCode();
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + Objects.hashCode(description);
return h;
}
/**
* Prints the immutable value {@code SlaProfile} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("SlaProfile")
.omitNullValues()
.add("thresholds", thresholds)
.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 SlaProfile {
java.util.@Valid List thresholds = ImmutableList.of();
@Nullable String name;
Optional description = Optional.empty();
@JsonProperty("thresholds")
public void setThresholds(java.util.@Valid List thresholds) {
this.thresholds = thresholds;
}
@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 java.util.@Valid List getThresholds() { 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 ImmutableSlaProfile fromJson(Json json) {
SlaProfile.Builder builder = new SlaProfile.Builder();
if (json.thresholds != null) {
builder.addAllThresholds(json.thresholds);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.description != null) {
builder.description(json.description);
}
return (ImmutableSlaProfile) builder.build();
}
/**
* Creates an immutable copy of a {@link SlaProfile} 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 SlaProfile instance
*/
public static ImmutableSlaProfile copyOf(SlaProfile instance) {
if (instance instanceof ImmutableSlaProfile) {
return (ImmutableSlaProfile) instance;
}
return new SlaProfile.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableSlaProfile ImmutableSlaProfile}.
* 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 ImmutableList.Builder thresholds = ImmutableList.builder();
private @Nullable String name;
private @Nullable String description;
/**
* Creates a builder for {@link ImmutableSlaProfile ImmutableSlaProfile} instances.
*/
public Builder() {
if (!(this instanceof SlaProfile.Builder)) {
throw new UnsupportedOperationException("Use: new SlaProfile.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.sla.SlaProfile} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SlaProfile.Builder from(SlaProfile instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (SlaProfile.Builder) this;
}
/**
* 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 SlaProfile.Builder from(Element instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (SlaProfile.Builder) this;
}
private void from(Object object) {
if (object instanceof SlaProfile) {
SlaProfile instance = (SlaProfile) object;
addAllThresholds(instance.getThresholds());
}
if (object instanceof Element) {
Element instance = (Element) object;
String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
description(descriptionOptional);
}
}
}
/**
* Adds one element to {@link SlaProfile#getThresholds() thresholds} list.
* @param element A thresholds element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SlaProfile.Builder addThresholds(SlaThreshold element) {
this.thresholds.add(element);
return (SlaProfile.Builder) this;
}
/**
* Adds elements to {@link SlaProfile#getThresholds() thresholds} list.
* @param elements An array of thresholds elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SlaProfile.Builder addThresholds(SlaThreshold... elements) {
this.thresholds.add(elements);
return (SlaProfile.Builder) this;
}
/**
* Sets or replaces all elements for {@link SlaProfile#getThresholds() thresholds} list.
* @param elements An iterable of thresholds elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("thresholds")
public final SlaProfile.Builder thresholds(Iterable extends SlaThreshold> elements) {
this.thresholds = ImmutableList.builder();
return addAllThresholds(elements);
}
/**
* Adds elements to {@link SlaProfile#getThresholds() thresholds} list.
* @param elements An iterable of thresholds elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final SlaProfile.Builder addAllThresholds(Iterable extends SlaThreshold> elements) {
this.thresholds.addAll(elements);
return (SlaProfile.Builder) this;
}
/**
* Initializes the value for the {@link SlaProfile#getName() name} attribute.
* @param name The value for name (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("name")
public final SlaProfile.Builder name(String name) {
this.name = name;
return (SlaProfile.Builder) this;
}
/**
* Initializes the optional value {@link SlaProfile#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final SlaProfile.Builder description(String description) {
this.description = Objects.requireNonNull(description, "description");
return (SlaProfile.Builder) this;
}
/**
* Initializes the optional value {@link SlaProfile#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 SlaProfile.Builder description(Optional description) {
this.description = description.orElse(null);
return (SlaProfile.Builder) this;
}
/**
* Builds a new {@link ImmutableSlaProfile ImmutableSlaProfile}.
* @return An immutable instance of SlaProfile
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableSlaProfile build() {
return new ImmutableSlaProfile(thresholds.build(), name, description);
}
}
}