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

tinder.core.auth.ImmutableTokenResult Maven / Gradle / Ivy

package tinder.core.auth;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
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 TokenResult}.
 * 

* Use the builder to create immutable instances: * {@code ImmutableTokenResult.builder()}. */ @Generated(from = "TokenResult", generator = "Immutables") @SuppressWarnings({"all"}) @SuppressFBWarnings @ParametersAreNonnullByDefault @javax.annotation.Generated("org.immutables.processor.ProxyProcessor") @Immutable public final class ImmutableTokenResult implements TokenResult { private final String token; private final String expiresIn; private final String expiresAt; private ImmutableTokenResult(String token, String expiresIn, String expiresAt) { this.token = token; this.expiresIn = expiresIn; this.expiresAt = expiresAt; } /** * @return The value of the {@code token} attribute */ @Override public String token() { return token; } /** * @return The value of the {@code expiresIn} attribute */ @Override public String expiresIn() { return expiresIn; } /** * @return The value of the {@code expiresAt} attribute */ @Override public String expiresAt() { return expiresAt; } /** * Copy the current immutable object by setting a value for the {@link TokenResult#token() token} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for token * @return A modified copy of the {@code this} object */ public final ImmutableTokenResult withToken(String value) { String newValue = Objects.requireNonNull(value, "token"); if (this.token.equals(newValue)) return this; return new ImmutableTokenResult(newValue, this.expiresIn, this.expiresAt); } /** * Copy the current immutable object by setting a value for the {@link TokenResult#expiresIn() expiresIn} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for expiresIn * @return A modified copy of the {@code this} object */ public final ImmutableTokenResult withExpiresIn(String value) { String newValue = Objects.requireNonNull(value, "expiresIn"); if (this.expiresIn.equals(newValue)) return this; return new ImmutableTokenResult(this.token, newValue, this.expiresAt); } /** * Copy the current immutable object by setting a value for the {@link TokenResult#expiresAt() expiresAt} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for expiresAt * @return A modified copy of the {@code this} object */ public final ImmutableTokenResult withExpiresAt(String value) { String newValue = Objects.requireNonNull(value, "expiresAt"); if (this.expiresAt.equals(newValue)) return this; return new ImmutableTokenResult(this.token, this.expiresIn, newValue); } /** * This instance is equal to all instances of {@code ImmutableTokenResult} 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 ImmutableTokenResult && equalTo((ImmutableTokenResult) another); } private boolean equalTo(ImmutableTokenResult another) { return token.equals(another.token) && expiresIn.equals(another.expiresIn) && expiresAt.equals(another.expiresAt); } /** * Computes a hash code from attributes: {@code token}, {@code expiresIn}, {@code expiresAt}. * @return hashCode value */ @Override public int hashCode() { int h = 5381; h += (h << 5) + token.hashCode(); h += (h << 5) + expiresIn.hashCode(); h += (h << 5) + expiresAt.hashCode(); return h; } /** * Prints the immutable value {@code TokenResult} with attribute values. * @return A string representation of the value */ @Override public String toString() { return "TokenResult{" + "token=" + token + ", expiresIn=" + expiresIn + ", expiresAt=" + expiresAt + "}"; } /** * Creates an immutable copy of a {@link TokenResult} 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 TokenResult instance */ public static ImmutableTokenResult copyOf(TokenResult instance) { if (instance instanceof ImmutableTokenResult) { return (ImmutableTokenResult) instance; } return ImmutableTokenResult.builder() .from(instance) .build(); } /** * Creates a builder for {@link ImmutableTokenResult ImmutableTokenResult}. *

   * ImmutableTokenResult.builder()
   *    .token(String) // required {@link TokenResult#token() token}
   *    .expiresIn(String) // required {@link TokenResult#expiresIn() expiresIn}
   *    .expiresAt(String) // required {@link TokenResult#expiresAt() expiresAt}
   *    .build();
   * 
* @return A new ImmutableTokenResult builder */ public static ImmutableTokenResult.Builder builder() { return new ImmutableTokenResult.Builder(); } /** * Builds instances of type {@link ImmutableTokenResult ImmutableTokenResult}. * 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 = "TokenResult", generator = "Immutables") @NotThreadSafe public static final class Builder { private static final long INIT_BIT_TOKEN = 0x1L; private static final long INIT_BIT_EXPIRES_IN = 0x2L; private static final long INIT_BIT_EXPIRES_AT = 0x4L; private long initBits = 0x7L; private @Nullable String token; private @Nullable String expiresIn; private @Nullable String expiresAt; private Builder() { } /** * Fill a builder with attribute values from the provided {@code TokenResult} 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(TokenResult instance) { Objects.requireNonNull(instance, "instance"); token(instance.token()); expiresIn(instance.expiresIn()); expiresAt(instance.expiresAt()); return this; } /** * Initializes the value for the {@link TokenResult#token() 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; } /** * Initializes the value for the {@link TokenResult#expiresIn() expiresIn} attribute. * @param expiresIn The value for expiresIn * @return {@code this} builder for use in a chained invocation */ public final Builder expiresIn(String expiresIn) { this.expiresIn = Objects.requireNonNull(expiresIn, "expiresIn"); initBits &= ~INIT_BIT_EXPIRES_IN; return this; } /** * Initializes the value for the {@link TokenResult#expiresAt() expiresAt} attribute. * @param expiresAt The value for expiresAt * @return {@code this} builder for use in a chained invocation */ public final Builder expiresAt(String expiresAt) { this.expiresAt = Objects.requireNonNull(expiresAt, "expiresAt"); initBits &= ~INIT_BIT_EXPIRES_AT; return this; } /** * Builds a new {@link ImmutableTokenResult ImmutableTokenResult}. * @return An immutable instance of TokenResult * @throws java.lang.IllegalStateException if any required attributes are missing */ public ImmutableTokenResult build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new ImmutableTokenResult(token, expiresIn, expiresAt); } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_TOKEN) != 0) attributes.add("token"); if ((initBits & INIT_BIT_EXPIRES_IN) != 0) attributes.add("expiresIn"); if ((initBits & INIT_BIT_EXPIRES_AT) != 0) attributes.add("expiresAt"); return "Cannot build TokenResult, some of required attributes are not set " + attributes; } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy