io.thestencil.iam.api.ImmutableUserRoles Maven / Gradle / Ivy
package io.thestencil.iam.api;
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.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.List;
import java.util.Objects;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.concurrent.Immutable;
import javax.annotation.concurrent.NotThreadSafe;
import org.immutables.value.Generated;
/**
* Immutable implementation of {@link IAMClient.UserRoles}.
*
* Use the builder to create immutable instances:
* {@code ImmutableUserRoles.builder()}.
*/
@Generated(from = "IAMClient.UserRoles", generator = "Immutables")
@SuppressWarnings({"all"})
@ParametersAreNonnullByDefault
@javax.annotation.processing.Generated("org.immutables.processor.ProxyProcessor")
@Immutable
@CheckReturnValue
public final class ImmutableUserRoles implements IAMClient.UserRoles {
private final ImmutableList roles;
private final @Nullable IAMClient.UserRolesPrincipal principal;
private ImmutableUserRoles(
ImmutableList roles,
@Nullable IAMClient.UserRolesPrincipal principal) {
this.roles = roles;
this.principal = principal;
}
/**
* @return The value of the {@code roles} attribute
*/
@JsonProperty("roles")
@Override
public ImmutableList getRoles() {
return roles;
}
/**
* @return The value of the {@code principal} attribute
*/
@JsonProperty("principal")
@Override
public @Nullable IAMClient.UserRolesPrincipal getPrincipal() {
return principal;
}
/**
* Copy the current immutable object with elements that replace the content of {@link IAMClient.UserRoles#getRoles() roles}.
* @param elements The elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableUserRoles withRoles(String... elements) {
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableUserRoles(newValue, this.principal);
}
/**
* Copy the current immutable object with elements that replace the content of {@link IAMClient.UserRoles#getRoles() roles}.
* A shallow reference equality check is used to prevent copying of the same value by returning {@code this}.
* @param elements An iterable of roles elements to set
* @return A modified copy of {@code this} object
*/
public final ImmutableUserRoles withRoles(Iterable elements) {
if (this.roles == elements) return this;
ImmutableList newValue = ImmutableList.copyOf(elements);
return new ImmutableUserRoles(newValue, this.principal);
}
/**
* Copy the current immutable object by setting a value for the {@link IAMClient.UserRoles#getPrincipal() principal} 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 principal (can be {@code null})
* @return A modified copy of the {@code this} object
*/
public final ImmutableUserRoles withPrincipal(@Nullable IAMClient.UserRolesPrincipal value) {
if (this.principal == value) return this;
return new ImmutableUserRoles(this.roles, value);
}
/**
* This instance is equal to all instances of {@code ImmutableUserRoles} 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 ImmutableUserRoles
&& equalTo((ImmutableUserRoles) another);
}
private boolean equalTo(ImmutableUserRoles another) {
return roles.equals(another.roles)
&& Objects.equals(principal, another.principal);
}
/**
* Computes a hash code from attributes: {@code roles}, {@code principal}.
* @return hashCode value
*/
@Override
public int hashCode() {
@Var int h = 5381;
h += (h << 5) + roles.hashCode();
h += (h << 5) + Objects.hashCode(principal);
return h;
}
/**
* Prints the immutable value {@code UserRoles} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return MoreObjects.toStringHelper("UserRoles")
.omitNullValues()
.add("roles", roles)
.add("principal", principal)
.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
*/
@Generated(from = "IAMClient.UserRoles", generator = "Immutables")
@Deprecated
@SuppressWarnings("Immutable")
@JsonDeserialize
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.NONE)
static final class Json implements IAMClient.UserRoles {
@Nullable List roles = ImmutableList.of();
@Nullable IAMClient.UserRolesPrincipal principal;
@JsonProperty("roles")
public void setRoles(List roles) {
this.roles = roles;
}
@JsonProperty("principal")
public void setPrincipal(@Nullable IAMClient.UserRolesPrincipal principal) {
this.principal = principal;
}
@Override
public List getRoles() { throw new UnsupportedOperationException(); }
@Override
public IAMClient.UserRolesPrincipal getPrincipal() { 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 ImmutableUserRoles fromJson(Json json) {
ImmutableUserRoles.Builder builder = ImmutableUserRoles.builder();
if (json.roles != null) {
builder.addAllRoles(json.roles);
}
if (json.principal != null) {
builder.principal(json.principal);
}
return builder.build();
}
/**
* Creates an immutable copy of a {@link IAMClient.UserRoles} 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 UserRoles instance
*/
public static ImmutableUserRoles copyOf(IAMClient.UserRoles instance) {
if (instance instanceof ImmutableUserRoles) {
return (ImmutableUserRoles) instance;
}
return ImmutableUserRoles.builder()
.from(instance)
.build();
}
/**
* Creates a builder for {@link ImmutableUserRoles ImmutableUserRoles}.
*
* ImmutableUserRoles.builder()
* .addRoles|addAllRoles(String) // {@link IAMClient.UserRoles#getRoles() roles} elements
* .principal(io.thestencil.iam.api.IAMClient.UserRolesPrincipal | null) // nullable {@link IAMClient.UserRoles#getPrincipal() principal}
* .build();
*
* @return A new ImmutableUserRoles builder
*/
public static ImmutableUserRoles.Builder builder() {
return new ImmutableUserRoles.Builder();
}
/**
* Builds instances of type {@link ImmutableUserRoles ImmutableUserRoles}.
* 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 = "IAMClient.UserRoles", generator = "Immutables")
@NotThreadSafe
public static final class Builder {
private ImmutableList.Builder roles = ImmutableList.builder();
private @Nullable IAMClient.UserRolesPrincipal principal;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code UserRoles} instance.
* Regular attribute values will be replaced with those from the given instance.
* Absent optional values will not replace present values.
* Collection elements and entries will be added, not replaced.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder from(IAMClient.UserRoles instance) {
Objects.requireNonNull(instance, "instance");
addAllRoles(instance.getRoles());
@Nullable IAMClient.UserRolesPrincipal principalValue = instance.getPrincipal();
if (principalValue != null) {
principal(principalValue);
}
return this;
}
/**
* Adds one element to {@link IAMClient.UserRoles#getRoles() roles} list.
* @param element A roles element
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRoles(String element) {
this.roles.add(element);
return this;
}
/**
* Adds elements to {@link IAMClient.UserRoles#getRoles() roles} list.
* @param elements An array of roles elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addRoles(String... elements) {
this.roles.add(elements);
return this;
}
/**
* Sets or replaces all elements for {@link IAMClient.UserRoles#getRoles() roles} list.
* @param elements An iterable of roles elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("roles")
public final Builder roles(Iterable elements) {
this.roles = ImmutableList.builder();
return addAllRoles(elements);
}
/**
* Adds elements to {@link IAMClient.UserRoles#getRoles() roles} list.
* @param elements An iterable of roles elements
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
public final Builder addAllRoles(Iterable elements) {
this.roles.addAll(elements);
return this;
}
/**
* Initializes the value for the {@link IAMClient.UserRoles#getPrincipal() principal} attribute.
* @param principal The value for principal (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
@CanIgnoreReturnValue
@JsonProperty("principal")
public final Builder principal(@Nullable IAMClient.UserRolesPrincipal principal) {
this.principal = principal;
return this;
}
/**
* Builds a new {@link ImmutableUserRoles ImmutableUserRoles}.
* @return An immutable instance of UserRoles
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public ImmutableUserRoles build() {
return new ImmutableUserRoles(roles.build(), principal);
}
}
}