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

org.cloudfoundry.uaa.tokens.CheckTokenRequest Maven / Gradle / Ivy

There is a newer version: 5.12.2.RELEASE
Show newest version
package org.cloudfoundry.uaa.tokens;

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 the check token operation
 */
@Generated(from = "_CheckTokenRequest", generator = "Immutables")
@SuppressWarnings({"all"})
@javax.annotation.Generated("org.immutables.processor.ProxyProcessor")
public final class CheckTokenRequest extends org.cloudfoundry.uaa.tokens._CheckTokenRequest {
  private final String clientId;
  private final String clientSecret;
  private final @Nullable List scopes;
  private final String token;

  private CheckTokenRequest(CheckTokenRequest.Builder builder) {
    this.clientId = builder.clientId;
    this.clientSecret = builder.clientSecret;
    this.scopes = builder.scopes == null ? null : createUnmodifiableList(true, builder.scopes);
    this.token = builder.token;
  }

  /**
   * The client id
   */
  @Override
  public String getClientId() {
    return clientId;
  }

  /**
   * The client secret
   */
  @Override
  public String getClientSecret() {
    return clientSecret;
  }

  /**
   * The scopes authorized by the user for this client
   */
  @Override
  public @Nullable List getScopes() {
    return scopes;
  }

  /**
   * The token
   */
  @Override
  public String getToken() {
    return token;
  }

  /**
   * This instance is equal to all instances of {@code CheckTokenRequest} 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 CheckTokenRequest
        && equalTo(0, (CheckTokenRequest) another);
  }

  private boolean equalTo(int synthetic, CheckTokenRequest another) {
    return clientId.equals(another.clientId)
        && clientSecret.equals(another.clientSecret)
        && Objects.equals(scopes, another.scopes)
        && token.equals(another.token);
  }

  /**
   * Computes a hash code from attributes: {@code clientId}, {@code clientSecret}, {@code scopes}, {@code token}.
   * @return hashCode value
   */
  @Override
  public int hashCode() {
    int h = 5381;
    h += (h << 5) + clientId.hashCode();
    h += (h << 5) + clientSecret.hashCode();
    h += (h << 5) + Objects.hashCode(scopes);
    h += (h << 5) + token.hashCode();
    return h;
  }

  /**
   * Prints the immutable value {@code CheckTokenRequest} with attribute values.
   * @return A string representation of the value
   */
  @Override
  public String toString() {
    return "CheckTokenRequest{"
        + "clientId=" + clientId
        + ", clientSecret=" + clientSecret
        + ", scopes=" + scopes
        + ", token=" + token
        + "}";
  }

  /**
   * Creates a builder for {@link CheckTokenRequest CheckTokenRequest}.
   * 
   * CheckTokenRequest.builder()
   *    .clientId(String) // required {@link CheckTokenRequest#getClientId() clientId}
   *    .clientSecret(String) // required {@link CheckTokenRequest#getClientSecret() clientSecret}
   *    .scopes(List&lt;String&gt; | null) // nullable {@link CheckTokenRequest#getScopes() scopes}
   *    .token(String) // required {@link CheckTokenRequest#getToken() token}
   *    .build();
   * 
* @return A new CheckTokenRequest builder */ public static CheckTokenRequest.Builder builder() { return new CheckTokenRequest.Builder(); } /** * Builds instances of type {@link CheckTokenRequest CheckTokenRequest}. * 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 = "_CheckTokenRequest", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_CLIENT_ID = 0x1L; private static final long INIT_BIT_CLIENT_SECRET = 0x2L; private static final long INIT_BIT_TOKEN = 0x4L; private long initBits = 0x7L; private String clientId; private String clientSecret; private List scopes = null; private String token; private Builder() { } /** * Fill a builder with attribute values from the provided {@code CheckTokenRequest} 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 */ public final Builder from(CheckTokenRequest instance) { return from((_CheckTokenRequest) instance); } /** * Copy abstract value type {@code _CheckTokenRequest} instance into builder. * @param instance The instance from which to copy values * @return {@code this} builder for use in a chained invocation */ final Builder from(_CheckTokenRequest instance) { Objects.requireNonNull(instance, "instance"); clientId(instance.getClientId()); clientSecret(instance.getClientSecret()); List scopesValue = instance.getScopes(); if (scopesValue != null) { addAllScopes(scopesValue); } token(instance.getToken()); return this; } /** * Initializes the value for the {@link CheckTokenRequest#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 CheckTokenRequest#getClientSecret() clientSecret} attribute. * @param clientSecret The value for clientSecret * @return {@code this} builder for use in a chained invocation */ public final Builder clientSecret(String clientSecret) { this.clientSecret = Objects.requireNonNull(clientSecret, "clientSecret"); initBits &= ~INIT_BIT_CLIENT_SECRET; return this; } /** * Adds one element to {@link CheckTokenRequest#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 CheckTokenRequest#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 CheckTokenRequest#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 CheckTokenRequest#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; } /** * Initializes the value for the {@link CheckTokenRequest#getToken() token} attribute. * @param token The value for token * @return {@code this} builder for use in a chained invocation */ public final Builder token(String token) { this.token = Objects.requireNonNull(token, "token"); initBits &= ~INIT_BIT_TOKEN; return this; } /** * Builds a new {@link CheckTokenRequest CheckTokenRequest}. * @return An immutable instance of CheckTokenRequest * @throws java.lang.IllegalStateException if any required attributes are missing */ public CheckTokenRequest build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new CheckTokenRequest(this); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_CLIENT_ID) != 0) attributes.add("clientId"); if ((initBits & INIT_BIT_CLIENT_SECRET) != 0) attributes.add("clientSecret"); if ((initBits & INIT_BIT_TOKEN) != 0) attributes.add("token"); return "Cannot build CheckTokenRequest, some of required attributes are not set " + attributes; } } private static List createSafeList(Iterable 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); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy