com.neotys.neoload.model.v3.project.server.ImmutableServer Maven / Gradle / Ivy
package com.neotys.neoload.model.v3.project.server;
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 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;
import javax.validation.constraints.Pattern;
/**
* Immutable implementation of {@link Server}.
*
* Use the builder to create immutable instances:
* {@code new Server.Builder()}.
*/
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@Generated({"Immutables.generator", "Server"})
@Immutable
@CheckReturnValue
public final class ImmutableServer implements Server {
private final String host;
private final java.lang.@Pattern(regexp = "^((\\d+)|(\\$\\{.+\\}))$", groups = {NeoLoad.class}) String port;
private final Server.Scheme scheme;
private final @Nullable Authentication authentication;
private final String name;
private final @Nullable String description;
private ImmutableServer(ImmutableServer.Builder builder) {
this.host = builder.host;
this.port = builder.port;
this.authentication = builder.authentication;
this.name = builder.name;
this.description = builder.description;
this.scheme = builder.scheme != null
? builder.scheme
: Objects.requireNonNull(Server.super.getScheme(), "scheme");
}
private ImmutableServer(
String host,
java.lang.@Pattern(regexp = "^((\\d+)|(\\$\\{.+\\}))$", groups = {NeoLoad.class}) String port,
Server.Scheme scheme,
@Nullable Authentication authentication,
String name,
@Nullable String description) {
this.host = host;
this.port = port;
this.scheme = scheme;
this.authentication = authentication;
this.name = name;
this.description = description;
}
/**
* @return The value of the {@code host} attribute
*/
@JsonProperty("host")
@Override
public String getHost() {
return host;
}
/**
* @return The value of the {@code port} attribute
*/
@JsonProperty("port")
@Override
public java.lang.@Pattern(regexp = "^((\\d+)|(\\$\\{.+\\}))$", groups = {NeoLoad.class}) String getPort() {
return port;
}
/**
* @return The value of the {@code scheme} attribute
*/
@JsonProperty("scheme")
@Override
public Server.Scheme getScheme() {
return scheme;
}
/**
* @return The value of the {@code authentication} attribute
*/
@JsonProperty("authentication")
@Override
public java.util.@Valid Optional getAuthentication() {
return java.util.Optional.ofNullable(authentication);
}
/**
* @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 java.util.Optional getDescription() {
return java.util.Optional.ofNullable(description);
}
/**
* Copy the current immutable object by setting a value for the {@link Server#getHost() host} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for host (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableServer withHost(String value) {
if (Objects.equals(this.host, value)) return this;
return new ImmutableServer(value, this.port, this.scheme, this.authentication, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link Server#getPort() port} 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 port (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableServer withPort(java.lang.@Pattern(regexp = "^((\\d+)|(\\$\\{.+\\}))$", groups = {NeoLoad.class}) String value) {
if (this.port == value) return this;
return new ImmutableServer(this.host, value, this.scheme, this.authentication, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link Server#getScheme() scheme} attribute.
* A value equality check is used to prevent copying of the same value by returning {@code this}.
* @param value A new value for scheme
* @return A modified copy of the {@code this} object
*/
public final ImmutableServer withScheme(Server.Scheme value) {
if (this.scheme == value) return this;
Server.Scheme newValue = Objects.requireNonNull(value, "scheme");
return new ImmutableServer(this.host, this.port, newValue, this.authentication, this.name, this.description);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Server#getAuthentication() authentication} attribute.
* @param value The value for authentication
* @return A modified copy of {@code this} object
*/
public final ImmutableServer withAuthentication(Authentication value) {
@Nullable Authentication newValue = Objects.requireNonNull(value, "authentication");
if (this.authentication == newValue) return this;
return new ImmutableServer(this.host, this.port, this.scheme, newValue, this.name, this.description);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Server#getAuthentication() authentication} attribute.
* A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}.
* @param optional A value for authentication
* @return A modified copy of {@code this} object
*/
public final ImmutableServer withAuthentication(java.util.Optional extends Authentication> optional) {
@Nullable Authentication value = optional.orElse(null);
if (this.authentication == value) return this;
return new ImmutableServer(this.host, this.port, this.scheme, value, this.name, this.description);
}
/**
* Copy the current immutable object by setting a value for the {@link Server#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 ImmutableServer withName(String value) {
if (Objects.equals(this.name, value)) return this;
return new ImmutableServer(this.host, this.port, this.scheme, this.authentication, value, this.description);
}
/**
* Copy the current immutable object by setting a present value for the optional {@link Server#getDescription() description} attribute.
* @param value The value for description
* @return A modified copy of {@code this} object
*/
public final ImmutableServer withDescription(String value) {
@Nullable String newValue = Objects.requireNonNull(value, "description");
if (Objects.equals(this.description, newValue)) return this;
return new ImmutableServer(this.host, this.port, this.scheme, this.authentication, this.name, newValue);
}
/**
* Copy the current immutable object by setting an optional value for the {@link Server#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 ImmutableServer withDescription(java.util.Optional optional) {
@Nullable String value = optional.orElse(null);
if (Objects.equals(this.description, value)) return this;
return new ImmutableServer(this.host, this.port, this.scheme, this.authentication, this.name, value);
}
/**
* This instance is equal to all instances of {@code ImmutableServer} 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 ImmutableServer
&& equalTo((ImmutableServer) another);
}
private boolean equalTo(ImmutableServer another) {
return Objects.equals(host, another.host)
&& Objects.equals(port, another.port)
&& scheme.equals(another.scheme)
&& Objects.equals(authentication, another.authentication)
&& Objects.equals(name, another.name)
&& Objects.equals(description, another.description);
}
/**
* Computes a hash code from attributes: {@code host}, {@code port}, {@code scheme}, {@code authentication}, {@code name}, {@code description}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + Objects.hashCode(host);
h += (h << 5) + Objects.hashCode(port);
h += (h << 5) + scheme.hashCode();
h += (h << 5) + Objects.hashCode(authentication);
h += (h << 5) + Objects.hashCode(name);
h += (h << 5) + Objects.hashCode(description);
return h;
}
/**
* Prints the immutable value {@code Server} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("Server")
.omitNullValues()
.add("host", host)
.add("port", port)
.add("scheme", scheme)
.add("authentication", authentication)
.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 Server {
@Nullable String host;
@Nullable java.lang.@Pattern(regexp = "^((\\d+)|(\\$\\{.+\\}))$", groups = {NeoLoad.class}) String port;
@Nullable Server.Scheme scheme;
java.util.@Valid Optional authentication = java.util.Optional.empty();
@Nullable String name;
java.util.Optional description = java.util.Optional.empty();
@JsonProperty("host")
public void setHost(String host) {
this.host = host;
}
@JsonProperty("port")
public void setPort(java.lang.@Pattern(regexp = "^((\\d+)|(\\$\\{.+\\}))$", groups = {NeoLoad.class}) String port) {
this.port = port;
}
@JsonProperty("scheme")
public void setScheme(Server.Scheme scheme) {
this.scheme = scheme;
}
@JsonProperty("authentication")
public void setAuthentication(java.util.@Valid Optional authentication) {
this.authentication = authentication;
}
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
@JsonProperty("description")
public void setDescription(java.util.Optional description) {
this.description = description;
}
@Override
public Element withName(String of) { throw new UnsupportedOperationException(); }
@Override
public String getHost() { throw new UnsupportedOperationException(); }
@Override
public java.lang.@Pattern(regexp = "^((\\d+)|(\\$\\{.+\\}))$", groups = {NeoLoad.class}) String getPort() { throw new UnsupportedOperationException(); }
@Override
public Server.Scheme getScheme() { throw new UnsupportedOperationException(); }
@Override
public java.util.@Valid Optional getAuthentication() { throw new UnsupportedOperationException(); }
@Override
public String getName() { throw new UnsupportedOperationException(); }
@Override
public java.util.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 ImmutableServer fromJson(Json json) {
Server.Builder builder = new Server.Builder();
if (json.host != null) {
builder.host(json.host);
}
if (json.port != null) {
builder.port(json.port);
}
if (json.scheme != null) {
builder.scheme(json.scheme);
}
if (json.authentication != null) {
builder.authentication(json.authentication);
}
if (json.name != null) {
builder.name(json.name);
}
if (json.description != null) {
builder.description(json.description);
}
return (ImmutableServer) builder.build();
}
/**
* Creates an immutable copy of a {@link Server} 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 Server instance
*/
public static ImmutableServer copyOf(Server instance) {
if (instance instanceof ImmutableServer) {
return (ImmutableServer) instance;
}
return new Server.Builder()
.from(instance)
.build();
}
/**
* Builds instances of type {@link ImmutableServer ImmutableServer}.
* 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 host;
private @Nullable java.lang.@Pattern(regexp = "^((\\d+)|(\\$\\{.+\\}))$", groups = {NeoLoad.class}) String port;
private @Nullable Server.Scheme scheme;
private @Nullable Authentication authentication;
private @Nullable String name;
private @Nullable String description;
/**
* Creates a builder for {@link ImmutableServer ImmutableServer} instances.
*/
public Builder() {
if (!(this instanceof Server.Builder)) {
throw new UnsupportedOperationException("Use: new Server.Builder()");
}
}
/**
* Fill a builder with attribute values from the provided {@code com.neotys.neoload.model.v3.project.server.Server} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Server.Builder from(Server instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (Server.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 Server.Builder from(Element instance) {
Objects.requireNonNull(instance, "instance");
from((Object) instance);
return (Server.Builder) this;
}
private void from(Object object) {
if (object instanceof Server) {
Server instance = (Server) object;
String hostValue = instance.getHost();
if (hostValue != null) {
host(hostValue);
}
scheme(instance.getScheme());
java.lang.@Pattern(regexp = "^((\\d+)|(\\$\\{.+\\}))$", groups = {NeoLoad.class}) String portValue = instance.getPort();
if (portValue != null) {
port(portValue);
}
java.util.@Valid Optional authenticationOptional = instance.getAuthentication();
if (authenticationOptional.isPresent()) {
authentication(authenticationOptional);
}
}
if (object instanceof Element) {
Element instance = (Element) object;
String nameValue = instance.getName();
if (nameValue != null) {
name(nameValue);
}
java.util.Optional descriptionOptional = instance.getDescription();
if (descriptionOptional.isPresent()) {
description(descriptionOptional);
}
}
}
/**
* Initializes the value for the {@link Server#getHost() host} attribute.
* @param host The value for host (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("host")
public final Server.Builder host(String host) {
this.host = host;
return (Server.Builder) this;
}
/**
* Initializes the value for the {@link Server#getPort() port} attribute.
* @param port The value for port (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("port")
public final Server.Builder port(java.lang.@Pattern(regexp = "^((\\d+)|(\\$\\{.+\\}))$", groups = {NeoLoad.class}) String port) {
this.port = port;
return (Server.Builder) this;
}
/**
* Initializes the value for the {@link Server#getScheme() scheme} attribute.
* If not set, this attribute will have a default value as returned by the initializer of {@link Server#getScheme() scheme}.
* @param scheme The value for scheme
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("scheme")
public final Server.Builder scheme(Server.Scheme scheme) {
this.scheme = Objects.requireNonNull(scheme, "scheme");
return (Server.Builder) this;
}
/**
* Initializes the optional value {@link Server#getAuthentication() authentication} to authentication.
* @param authentication The value for authentication
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Server.Builder authentication(Authentication authentication) {
this.authentication = Objects.requireNonNull(authentication, "authentication");
return (Server.Builder) this;
}
/**
* Initializes the optional value {@link Server#getAuthentication() authentication} to authentication.
* @param authentication The value for authentication
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("authentication")
public final Server.Builder authentication(java.util.Optional extends Authentication> authentication) {
this.authentication = authentication.orElse(null);
return (Server.Builder) this;
}
/**
* Initializes the value for the {@link Server#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 Server.Builder name(String name) {
this.name = name;
return (Server.Builder) this;
}
/**
* Initializes the optional value {@link Server#getDescription() description} to description.
* @param description The value for description
* @return {@code this} builder for chained invocation
*/
@CanIgnoreReturnValue
public final Server.Builder description(String description) {
this.description = Objects.requireNonNull(description, "description");
return (Server.Builder) this;
}
/**
* Initializes the optional value {@link Server#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 Server.Builder description(java.util.Optional description) {
this.description = description.orElse(null);
return (Server.Builder) this;
}
/**
* Builds a new {@link ImmutableServer ImmutableServer}.
* @return An immutable instance of Server
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableServer build() {
return new ImmutableServer(this);
}
}
}