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