org.cloudfoundry.client.lib.domain.ImmutableDockerCredentials Maven / Gradle / Ivy
Show all versions of cloudfoundry-client-lib Show documentation
package org.cloudfoundry.client.lib.domain;
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 java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link DockerCredentials}.
*
* Use the builder to create immutable instances:
* {@code ImmutableDockerCredentials.builder()}.
*/
@Generated(from = "DockerCredentials", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
public final class ImmutableDockerCredentials implements DockerCredentials {
private final String username;
private final String password;
private ImmutableDockerCredentials(String username, String password) {
this.username = username;
this.password = password;
}
/**
* @return The value of the {@code username} attribute
*/
@JsonProperty("username")
@Override
public String getUsername() {
return username;
}
/**
* @return The value of the {@code password} attribute
*/
@JsonProperty("password")
@Override
public String getPassword() {
return password;
}
/**
* Copy the current immutable object by setting a value for the {@link DockerCredentials#getUsername() username} attribute.
* An equals check used to prevent copying of the same value by returning {@code this}.
* @param value A new value for username
* @return A modified copy of the {@code this} object
*/
public final ImmutableDockerCredentials withUsername(String value) {
String newValue = Objects.requireNonNull(value, "username");
if (this.username.equals(newValue)) return this;
return new ImmutableDockerCredentials(newValue, this.password);
}
/**
* Copy the current immutable object by setting a value for the {@link DockerCredentials#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
* @return A modified copy of the {@code this} object
*/
public final ImmutableDockerCredentials withPassword(String value) {
String newValue = Objects.requireNonNull(value, "password");
if (this.password.equals(newValue)) return this;
return new ImmutableDockerCredentials(this.username, newValue);
}
/**
* This instance is equal to all instances of {@code ImmutableDockerCredentials} that have equal attribute values.
* @return {@code true} if {@code this} is equal to {@code another} instance
*/
@Override
public boolean equals(Object another) {
if (this == another) return true;
return another instanceof ImmutableDockerCredentials
&& equalTo((ImmutableDockerCredentials) another);
}
private boolean equalTo(ImmutableDockerCredentials another) {
return username.equals(another.username)
&& password.equals(another.password);
}
/**
* Computes a hash code from attributes: {@code username}, {@code password}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + username.hashCode();
h += (h << 5) + password.hashCode();
return h;
}
/**
* Prints the immutable value {@code DockerCredentials} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "DockerCredentials{"
+ "username=" + username
+ ", password=" + password
+ "}";
}
/**
* 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
*/
@Generated(from = "DockerCredentials", generator = "Immutables")
@Deprecated
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements DockerCredentials {
String username;
String password;
@JsonProperty("username")
public void setUsername(String username) {
this.username = username;
}
@JsonProperty("password")
public void setPassword(String password) {
this.password = password;
}
@Override
public String getUsername() { 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 ImmutableDockerCredentials fromJson(Json json) {
ImmutableDockerCredentials.Builder builder = ImmutableDockerCredentials.builder();
if (json.username != null) {
builder.username(json.username);
}
if (json.password != null) {
builder.password(json.password);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link DockerCredentials} 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 DockerCredentials instance
*/
public static ImmutableDockerCredentials copyOf(DockerCredentials instance) {
if (instance instanceof ImmutableDockerCredentials) {
return (ImmutableDockerCredentials) instance;
}
return ImmutableDockerCredentials.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableDockerCredentials ImmutableDockerCredentials}.
*
* ImmutableDockerCredentials.builder()
* .username(String) // required {@link DockerCredentials#getUsername() username}
* .password(String) // required {@link DockerCredentials#getPassword() password}
* .build();
*
* @return A new ImmutableDockerCredentials builder
*/
public static ImmutableDockerCredentials.Builder builder() {
return new ImmutableDockerCredentials.Builder();
}
/**
* Builds instances of type {@link ImmutableDockerCredentials ImmutableDockerCredentials}.
* 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.
*/
@Generated(from = "DockerCredentials", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_USERNAME = 0x1L;
private static final long INIT_BIT_PASSWORD = 0x2L;
private long initBits = 0x3L;
private String username;
private String password;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code DockerCredentials} 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
*/
public final Builder from(DockerCredentials instance) {
Objects.requireNonNull(instance, "instance");
username(instance.getUsername());
password(instance.getPassword());
return this;
}
/**
* Initializes the value for the {@link DockerCredentials#getUsername() username} attribute.
* @param username The value for username
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("username")
public final Builder username(String username) {
this.username = Objects.requireNonNull(username, "username");
initBits &= ~INIT_BIT_USERNAME;
return this;
}
/**
* Initializes the value for the {@link DockerCredentials#getPassword() password} attribute.
* @param password The value for password
* @return {@code this} builder for use in a chained invocation
*/
@JsonProperty("password")
public final Builder password(String password) {
this.password = Objects.requireNonNull(password, "password");
initBits &= ~INIT_BIT_PASSWORD;
return this;
}
/**
* Builds a new {@link ImmutableDockerCredentials ImmutableDockerCredentials}.
* @return An immutable instance of DockerCredentials
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableDockerCredentials build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new ImmutableDockerCredentials(username, password);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_USERNAME) != 0) attributes.add("username");
if ((initBits & INIT_BIT_PASSWORD) != 0) attributes.add("password");
return "Cannot build DockerCredentials, some of required attributes are not set " + attributes;
}
}
}