All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.neotys.neoload.model.repository.ImmutableServer Maven / Gradle / Ivy

package com.neotys.neoload.model.repository;

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.Lists;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.List;
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 Server}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableServer.builder()}. */ @SuppressWarnings({"all"}) @ParametersAreNonnullByDefault @Generated({"Immutables.generator", "Server"}) @Deprecated @Immutable @CheckReturnValue public final class ImmutableServer implements Server { private final String name; private final String host; private final String port; private final @Nullable String scheme; private ImmutableServer( String name, String host, String port, @Nullable String scheme) { this.name = name; this.host = host; this.port = port; this.scheme = scheme; } /** * @return The value of the {@code name} attribute */ @JsonProperty("name") @Override public String getName() { return name; } /** * @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 String getPort() { return port; } /** * @return The value of the {@code scheme} attribute */ @JsonProperty("scheme") @Override public Optional getScheme() { return Optional.ofNullable(scheme); } /** * 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 * @return A modified copy of the {@code this} object */ public final ImmutableServer withName(String value) { if (this.name.equals(value)) return this; String newValue = Objects.requireNonNull(value, "name"); return new ImmutableServer(newValue, this.host, this.port, this.scheme); } /** * 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 * @return A modified copy of the {@code this} object */ public final ImmutableServer withHost(String value) { if (this.host.equals(value)) return this; String newValue = Objects.requireNonNull(value, "host"); return new ImmutableServer(this.name, newValue, this.port, this.scheme); } /** * Copy the current immutable object by setting a value for the {@link Server#getPort() port} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for port * @return A modified copy of the {@code this} object */ public final ImmutableServer withPort(String value) { if (this.port.equals(value)) return this; String newValue = Objects.requireNonNull(value, "port"); return new ImmutableServer(this.name, this.host, newValue, this.scheme); } /** * Copy the current immutable object by setting a present value for the optional {@link Server#getScheme() scheme} attribute. * @param value The value for scheme * @return A modified copy of {@code this} object */ public final ImmutableServer withScheme(String value) { @Nullable String newValue = Objects.requireNonNull(value, "scheme"); if (Objects.equals(this.scheme, newValue)) return this; return new ImmutableServer(this.name, this.host, this.port, newValue); } /** * Copy the current immutable object by setting an optional value for the {@link Server#getScheme() scheme} 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 scheme * @return A modified copy of {@code this} object */ public final ImmutableServer withScheme(Optional optional) { @Nullable String value = optional.orElse(null); if (Objects.equals(this.scheme, value)) return this; return new ImmutableServer(this.name, this.host, this.port, 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 name.equals(another.name) && host.equals(another.host) && port.equals(another.port) && Objects.equals(scheme, another.scheme); } /** * Computes a hash code from attributes: {@code name}, {@code host}, {@code port}, {@code scheme}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + name.hashCode(); h += (h << 5) + host.hashCode(); h += (h << 5) + port.hashCode(); h += (h << 5) + Objects.hashCode(scheme); 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("name", name) .add("host", host) .add("port", port) .add("scheme", scheme) .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 name; @Nullable String host; @Nullable String port; Optional scheme = Optional.empty(); @JsonProperty("name") public void setName(String name) { this.name = name; } @JsonProperty("host") public void setHost(String host) { this.host = host; } @JsonProperty("port") public void setPort(String port) { this.port = port; } @JsonProperty("scheme") public void setScheme(Optional scheme) { this.scheme = scheme; } @Override public String getName() { throw new UnsupportedOperationException(); } @Override public String getHost() { throw new UnsupportedOperationException(); } @Override public String getPort() { throw new UnsupportedOperationException(); } @Override public Optional getScheme() { 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) { ImmutableServer.Builder builder = ImmutableServer.builder(); if (json.name != null) { builder.name(json.name); } if (json.host != null) { builder.host(json.host); } if (json.port != null) { builder.port(json.port); } if (json.scheme != null) { builder.scheme(json.scheme); } return 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 ImmutableServer.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableServer ImmutableServer}. * @return A new ImmutableServer builder */ public static ImmutableServer.Builder builder() { return new ImmutableServer.Builder(); } /** * 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 final class Builder { private static final long INIT_BIT_NAME = 0x1L; private static final long INIT_BIT_HOST = 0x2L; private static final long INIT_BIT_PORT = 0x4L; private long initBits = 0x7L; private @Nullable String name; private @Nullable String host; private @Nullable String port; private @Nullable String scheme; private Builder() { } /** * Fill a builder with attribute values from the provided {@code Server} 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 Builder from(Server instance) { Objects.requireNonNull(instance, "instance"); name(instance.getName()); host(instance.getHost()); port(instance.getPort()); Optional schemeOptional = instance.getScheme(); if (schemeOptional.isPresent()) { scheme(schemeOptional); } return this; } /** * Initializes the value for the {@link Server#getName() name} attribute. * @param name The value for name * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("name") public final Builder name(String name) { this.name = Objects.requireNonNull(name, "name"); initBits &= ~INIT_BIT_NAME; return this; } /** * Initializes the value for the {@link Server#getHost() host} attribute. * @param host The value for host * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("host") public final Builder host(String host) { this.host = Objects.requireNonNull(host, "host"); initBits &= ~INIT_BIT_HOST; return this; } /** * Initializes the value for the {@link Server#getPort() port} attribute. * @param port The value for port * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("port") public final Builder port(String port) { this.port = Objects.requireNonNull(port, "port"); initBits &= ~INIT_BIT_PORT; return this; } /** * Initializes the optional value {@link Server#getScheme() scheme} to scheme. * @param scheme The value for scheme * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder scheme(String scheme) { this.scheme = Objects.requireNonNull(scheme, "scheme"); return this; } /** * Initializes the optional value {@link Server#getScheme() scheme} to scheme. * @param scheme The value for scheme * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue @JsonProperty("scheme") public final Builder scheme(Optional scheme) { this.scheme = scheme.orElse(null); return 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() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableServer(name, host, port, scheme); } private String formatRequiredAttributesMessage() { List attributes = Lists.newArrayList(); if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name"); if ((initBits & INIT_BIT_HOST) != 0) attributes.add("host"); if ((initBits & INIT_BIT_PORT) != 0) attributes.add("port"); return "Cannot build Server, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy