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

com.neotys.neoload.model.v3.project.server.ImmutableBasicAuthentication 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 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 BasicAuthentication}.
 * 

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





© 2015 - 2024 Weber Informatics LLC | Privacy Policy