
org.cloudfoundry.uaa.authorizations.AuthorizeByOpenIdWithIdTokenRequest Maven / Gradle / Ivy
package org.cloudfoundry.uaa.authorizations;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.cloudfoundry.Nullable;
import org.immutables.value.Generated;
/**
* The request payload for authorize by open id with an id token operation
*/
@Generated(from = "_AuthorizeByOpenIdWithIdTokenRequest", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class AuthorizeByOpenIdWithIdTokenRequest
extends org.cloudfoundry.uaa.authorizations._AuthorizeByOpenIdWithIdTokenRequest {
private final String clientId;
private final @Nullable String redirectUri;
private final @Nullable List scopes;
private AuthorizeByOpenIdWithIdTokenRequest(AuthorizeByOpenIdWithIdTokenRequest.Builder builder) {
this.clientId = builder.clientId;
this.redirectUri = builder.redirectUri;
this.scopes = builder.scopes == null ? null : createUnmodifiableList(true, builder.scopes);
}
/**
* A unique string representing the registration information provided by the client
*/
@Override
public String getClientId() {
return clientId;
}
/**
* Redirection URI to which the authorization server will send the user-agent back once access is granted (or denied), optional if pre-registered by the client
*/
@Override
public @Nullable String getRedirectUri() {
return redirectUri;
}
/**
* requested scopes, space-delimited
*/
@Override
public @Nullable List getScopes() {
return scopes;
}
/**
* This instance is equal to all instances of {@code AuthorizeByOpenIdWithIdTokenRequest} 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 AuthorizeByOpenIdWithIdTokenRequest
&& equalTo(0, (AuthorizeByOpenIdWithIdTokenRequest) another);
}
private boolean equalTo(int synthetic, AuthorizeByOpenIdWithIdTokenRequest another) {
return clientId.equals(another.clientId)
&& Objects.equals(redirectUri, another.redirectUri)
&& Objects.equals(scopes, another.scopes);
}
/**
* Computes a hash code from attributes: {@code clientId}, {@code redirectUri}, {@code scopes}.
* @return hashCode value
*/
@Override
public int hashCode() {
int h = 5381;
h += (h << 5) + clientId.hashCode();
h += (h << 5) + Objects.hashCode(redirectUri);
h += (h << 5) + Objects.hashCode(scopes);
return h;
}
/**
* Prints the immutable value {@code AuthorizeByOpenIdWithIdTokenRequest} with attribute values.
* @return A string representation of the value
*/
@Override
public String toString() {
return "AuthorizeByOpenIdWithIdTokenRequest{"
+ "clientId=" + clientId
+ ", redirectUri=" + redirectUri
+ ", scopes=" + scopes
+ "}";
}
/**
* Creates a builder for {@link AuthorizeByOpenIdWithIdTokenRequest AuthorizeByOpenIdWithIdTokenRequest}.
*
* AuthorizeByOpenIdWithIdTokenRequest.builder()
* .clientId(String) // required {@link AuthorizeByOpenIdWithIdTokenRequest#getClientId() clientId}
* .redirectUri(String | null) // nullable {@link AuthorizeByOpenIdWithIdTokenRequest#getRedirectUri() redirectUri}
* .scopes(List<String> | null) // nullable {@link AuthorizeByOpenIdWithIdTokenRequest#getScopes() scopes}
* .build();
*
* @return A new AuthorizeByOpenIdWithIdTokenRequest builder
*/
public static AuthorizeByOpenIdWithIdTokenRequest.Builder builder() {
return new AuthorizeByOpenIdWithIdTokenRequest.Builder();
}
/**
* Builds instances of type {@link AuthorizeByOpenIdWithIdTokenRequest AuthorizeByOpenIdWithIdTokenRequest}.
* 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 = "_AuthorizeByOpenIdWithIdTokenRequest", generator = "Immutables")
public static final class Builder {
private static final long INIT_BIT_CLIENT_ID = 0x1L;
private long initBits = 0x1L;
private String clientId;
private String redirectUri;
private List scopes = null;
private Builder() {
}
/**
* Fill a builder with attribute values from the provided {@code org.cloudfoundry.uaa.authorizations.AbstractAuthorizationRequest} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(AbstractAuthorizationRequest instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
/**
* Fill a builder with attribute values from the provided {@code AuthorizeByOpenIdWithIdTokenRequest} instance.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(AuthorizeByOpenIdWithIdTokenRequest instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
/**
* Copy abstract value type {@code _AuthorizeByOpenIdWithIdTokenRequest} instance into builder.
* @param instance The instance from which to copy values
* @return {@code this} builder for use in a chained invocation
*/
public final Builder from(_AuthorizeByOpenIdWithIdTokenRequest instance) {
Objects.requireNonNull(instance, "instance");
from((short) 0, (Object) instance);
return this;
}
private void from(short _unused, Object object) {
if (object instanceof AbstractAuthorizationRequest) {
AbstractAuthorizationRequest instance = (AbstractAuthorizationRequest) object;
String redirectUriValue = instance.getRedirectUri();
if (redirectUriValue != null) {
redirectUri(redirectUriValue);
}
clientId(instance.getClientId());
List scopesValue = instance.getScopes();
if (scopesValue != null) {
addAllScopes(scopesValue);
}
}
}
/**
* Initializes the value for the {@link AuthorizeByOpenIdWithIdTokenRequest#getClientId() clientId} attribute.
* @param clientId The value for clientId
* @return {@code this} builder for use in a chained invocation
*/
public final Builder clientId(String clientId) {
this.clientId = Objects.requireNonNull(clientId, "clientId");
initBits &= ~INIT_BIT_CLIENT_ID;
return this;
}
/**
* Initializes the value for the {@link AuthorizeByOpenIdWithIdTokenRequest#getRedirectUri() redirectUri} attribute.
* @param redirectUri The value for redirectUri (can be {@code null})
* @return {@code this} builder for use in a chained invocation
*/
public final Builder redirectUri(@Nullable String redirectUri) {
this.redirectUri = redirectUri;
return this;
}
/**
* Adds one element to {@link AuthorizeByOpenIdWithIdTokenRequest#getScopes() scopes} list.
* @param element A scopes element
* @return {@code this} builder for use in a chained invocation
*/
public final Builder scope(String element) {
if (this.scopes == null) {
this.scopes = new ArrayList();
}
this.scopes.add(Objects.requireNonNull(element, "scopes element"));
return this;
}
/**
* Adds elements to {@link AuthorizeByOpenIdWithIdTokenRequest#getScopes() scopes} list.
* @param elements An array of scopes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder scopes(String... elements) {
if (this.scopes == null) {
this.scopes = new ArrayList();
}
for (String element : elements) {
this.scopes.add(Objects.requireNonNull(element, "scopes element"));
}
return this;
}
/**
* Sets or replaces all elements for {@link AuthorizeByOpenIdWithIdTokenRequest#getScopes() scopes} list.
* @param elements An iterable of scopes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder scopes(@Nullable Iterable elements) {
if (elements == null) {
this.scopes = null;
return this;
}
this.scopes = new ArrayList();
return addAllScopes(elements);
}
/**
* Adds elements to {@link AuthorizeByOpenIdWithIdTokenRequest#getScopes() scopes} list.
* @param elements An iterable of scopes elements
* @return {@code this} builder for use in a chained invocation
*/
public final Builder addAllScopes(Iterable elements) {
Objects.requireNonNull(elements, "scopes element");
if (this.scopes == null) {
this.scopes = new ArrayList();
}
for (String element : elements) {
this.scopes.add(Objects.requireNonNull(element, "scopes element"));
}
return this;
}
/**
* Builds a new {@link AuthorizeByOpenIdWithIdTokenRequest AuthorizeByOpenIdWithIdTokenRequest}.
* @return An immutable instance of AuthorizeByOpenIdWithIdTokenRequest
* @throws java.lang.IllegalStateException if any required attributes are missing
*/
public AuthorizeByOpenIdWithIdTokenRequest build() {
if (initBits != 0) {
throw new IllegalStateException(formatRequiredAttributesMessage());
}
return new AuthorizeByOpenIdWithIdTokenRequest(this);
}
private String formatRequiredAttributesMessage() {
List attributes = new ArrayList<>();
if ((initBits & INIT_BIT_CLIENT_ID) != 0) attributes.add("clientId");
return "Cannot build AuthorizeByOpenIdWithIdTokenRequest, some of required attributes are not set " + attributes;
}
}
private static List createSafeList(Iterable extends T> iterable, boolean checkNulls, boolean skipNulls) {
ArrayList list;
if (iterable instanceof Collection>) {
int size = ((Collection>) iterable).size();
if (size == 0) return Collections.emptyList();
list = new ArrayList<>(size);
} else {
list = new ArrayList<>();
}
for (T element : iterable) {
if (skipNulls && element == null) continue;
if (checkNulls) Objects.requireNonNull(element, "element");
list.add(element);
}
return list;
}
private static List createUnmodifiableList(boolean clone, List list) {
switch(list.size()) {
case 0: return Collections.emptyList();
case 1: return Collections.singletonList(list.get(0));
default:
if (clone) {
return Collections.unmodifiableList(new ArrayList<>(list));
} else {
if (list instanceof ArrayList>) {
((ArrayList>) list).trimToSize();
}
return Collections.unmodifiableList(list);
}
}
}
}