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

com.mercateo.spring.security.jwt.token.claim.JWTClaim Maven / Gradle / Ivy

The newest version!
package com.mercateo.spring.security.jwt.token.claim;

import com.google.common.base.MoreObjects;
import com.google.common.primitives.Booleans;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.errorprone.annotations.Var;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import org.immutables.value.Generated;

/**
 * Immutable implementation of {@link _JWTClaim}.
 * 

* Use the builder to create immutable instances: * {@code JWTClaim.builder()}. */ @Generated(from = "_JWTClaim", generator = "Immutables") @SuppressWarnings({"all"}) public final class JWTClaim implements com.mercateo.spring.security.jwt.token.claim._JWTClaim { private final String name; private final Object value; private final String issuer; private final boolean verified; private final JWTClaim innerClaim; private final int depth; private JWTClaim(JWTClaim.Builder builder) { this.name = builder.name; this.value = builder.value; this.innerClaim = builder.innerClaim; if (builder.issuer != null) { initShim.issuer(builder.issuer); } if (builder.verifiedIsSet()) { initShim.verified(builder.verified); } if (builder.depthIsSet()) { initShim.depth(builder.depth); } this.issuer = initShim.issuer(); this.verified = initShim.verified(); this.depth = initShim.depth(); this.initShim = null; } private JWTClaim( String name, Object value, String issuer, boolean verified, JWTClaim innerClaim, int depth) { this.name = name; this.value = value; this.issuer = issuer; this.verified = verified; this.innerClaim = innerClaim; this.depth = depth; this.initShim = null; } private static final byte STAGE_INITIALIZING = -1; private static final byte STAGE_UNINITIALIZED = 0; private static final byte STAGE_INITIALIZED = 1; @SuppressWarnings("Immutable") private transient volatile InitShim initShim = new InitShim(); @Generated(from = "_JWTClaim", generator = "Immutables") private final class InitShim { private byte issuerBuildStage = STAGE_UNINITIALIZED; private String issuer; String issuer() { if (issuerBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (issuerBuildStage == STAGE_UNINITIALIZED) { issuerBuildStage = STAGE_INITIALIZING; this.issuer = Objects.requireNonNull(issuerInitialize(), "issuer"); issuerBuildStage = STAGE_INITIALIZED; } return this.issuer; } void issuer(String issuer) { this.issuer = issuer; issuerBuildStage = STAGE_INITIALIZED; } private byte verifiedBuildStage = STAGE_UNINITIALIZED; private boolean verified; boolean verified() { if (verifiedBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (verifiedBuildStage == STAGE_UNINITIALIZED) { verifiedBuildStage = STAGE_INITIALIZING; this.verified = verifiedInitialize(); verifiedBuildStage = STAGE_INITIALIZED; } return this.verified; } void verified(boolean verified) { this.verified = verified; verifiedBuildStage = STAGE_INITIALIZED; } private byte depthBuildStage = STAGE_UNINITIALIZED; private int depth; int depth() { if (depthBuildStage == STAGE_INITIALIZING) throw new IllegalStateException(formatInitCycleMessage()); if (depthBuildStage == STAGE_UNINITIALIZED) { depthBuildStage = STAGE_INITIALIZING; this.depth = depthInitialize(); depthBuildStage = STAGE_INITIALIZED; } return this.depth; } void depth(int depth) { this.depth = depth; depthBuildStage = STAGE_INITIALIZED; } private String formatInitCycleMessage() { List attributes = new ArrayList<>(); if (issuerBuildStage == STAGE_INITIALIZING) attributes.add("issuer"); if (verifiedBuildStage == STAGE_INITIALIZING) attributes.add("verified"); if (depthBuildStage == STAGE_INITIALIZING) attributes.add("depth"); return "Cannot build JWTClaim, attribute initializers form cycle " + attributes; } } private String issuerInitialize() { return _JWTClaim.super.issuer(); } private boolean verifiedInitialize() { return _JWTClaim.super.verified(); } private int depthInitialize() { return _JWTClaim.super.depth(); } /** * @return The value of the {@code name} attribute */ @Override public String name() { return name; } /** * @return The value of the {@code value} attribute */ @Override public Object value() { return value; } /** * @return The value of the {@code issuer} attribute */ @Override public String issuer() { InitShim shim = this.initShim; return shim != null ? shim.issuer() : this.issuer; } /** * @return The value of the {@code verified} attribute */ @Override public boolean verified() { InitShim shim = this.initShim; return shim != null ? shim.verified() : this.verified; } /** * @return The value of the {@code innerClaim} attribute */ @Override public Optional innerClaim() { return Optional.ofNullable(innerClaim); } /** * @return The value of the {@code depth} attribute */ @Override public int depth() { InitShim shim = this.initShim; return shim != null ? shim.depth() : this.depth; } /** * Copy the current immutable object by setting a value for the {@link _JWTClaim#name() name} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for name * @return A modified copy of the {@code this} object */ public final JWTClaim withName(String value) { String newValue = Objects.requireNonNull(value, "name"); if (this.name.equals(newValue)) return this; return new JWTClaim(newValue, this.value, this.issuer, this.verified, this.innerClaim, this.depth); } /** * Copy the current immutable object by setting a value for the {@link _JWTClaim#value() value} 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 value * @return A modified copy of the {@code this} object */ public final JWTClaim withValue(Object value) { if (this.value == value) return this; Object newValue = Objects.requireNonNull(value, "value"); return new JWTClaim(this.name, newValue, this.issuer, this.verified, this.innerClaim, this.depth); } /** * Copy the current immutable object by setting a value for the {@link _JWTClaim#issuer() issuer} attribute. * An equals check used to prevent copying of the same value by returning {@code this}. * @param value A new value for issuer * @return A modified copy of the {@code this} object */ public final JWTClaim withIssuer(String value) { String newValue = Objects.requireNonNull(value, "issuer"); if (this.issuer.equals(newValue)) return this; return new JWTClaim(this.name, this.value, newValue, this.verified, this.innerClaim, this.depth); } /** * Copy the current immutable object by setting a value for the {@link _JWTClaim#verified() verified} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for verified * @return A modified copy of the {@code this} object */ public final JWTClaim withVerified(boolean value) { if (this.verified == value) return this; return new JWTClaim(this.name, this.value, this.issuer, value, this.innerClaim, this.depth); } /** * Copy the current immutable object by setting a present value for the optional {@link _JWTClaim#innerClaim() innerClaim} attribute. * @param value The value for innerClaim * @return A modified copy of {@code this} object */ public final JWTClaim withInnerClaim(JWTClaim value) { JWTClaim newValue = Objects.requireNonNull(value, "innerClaim"); if (this.innerClaim == newValue) return this; return new JWTClaim(this.name, this.value, this.issuer, this.verified, newValue, this.depth); } /** * Copy the current immutable object by setting an optional value for the {@link _JWTClaim#innerClaim() innerClaim} attribute. * A shallow reference equality check is used on unboxed optional value to prevent copying of the same value by returning {@code this}. * @param optional A value for innerClaim * @return A modified copy of {@code this} object */ @SuppressWarnings("unchecked") // safe covariant cast public final JWTClaim withInnerClaim(Optional optional) { JWTClaim value = optional.orElse(null); if (this.innerClaim == value) return this; return new JWTClaim(this.name, this.value, this.issuer, this.verified, value, this.depth); } /** * Copy the current immutable object by setting a value for the {@link _JWTClaim#depth() depth} attribute. * A value equality check is used to prevent copying of the same value by returning {@code this}. * @param value A new value for depth * @return A modified copy of the {@code this} object */ public final JWTClaim withDepth(int value) { if (this.depth == value) return this; return new JWTClaim(this.name, this.value, this.issuer, this.verified, this.innerClaim, value); } /** * This instance is equal to all instances of {@code JWTClaim} 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 JWTClaim && equalTo((JWTClaim) another); } private boolean equalTo(JWTClaim another) { return name.equals(another.name) && value.equals(another.value) && issuer.equals(another.issuer) && verified == another.verified && Objects.equals(innerClaim, another.innerClaim) && depth == another.depth; } /** * Computes a hash code from attributes: {@code name}, {@code value}, {@code issuer}, {@code verified}, {@code innerClaim}, {@code depth}. * @return hashCode value */ @Override public int hashCode() { @Var int h = 5381; h += (h << 5) + name.hashCode(); h += (h << 5) + value.hashCode(); h += (h << 5) + issuer.hashCode(); h += (h << 5) + Booleans.hashCode(verified); h += (h << 5) + Objects.hashCode(innerClaim); h += (h << 5) + depth; return h; } /** * Prints the immutable value {@code JWTClaim} with attribute values. * @return A string representation of the value */ @Override public String toString() { return MoreObjects.toStringHelper("JWTClaim") .omitNullValues() .add("name", name) .add("value", value) .add("issuer", issuer) .add("verified", verified) .add("innerClaim", innerClaim) .add("depth", depth) .toString(); } /** * Creates an immutable copy of a {@link _JWTClaim} 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 JWTClaim instance */ public static JWTClaim copyOf(_JWTClaim instance) { if (instance instanceof JWTClaim) { return (JWTClaim) instance; } return JWTClaim.builder() .from(instance) .build(); } /** * Creates a builder for {@link JWTClaim JWTClaim}. *

   * JWTClaim.builder()
   *    .name(String) // required {@link _JWTClaim#name() name}
   *    .value(Object) // required {@link _JWTClaim#value() value}
   *    .issuer(String) // optional {@link _JWTClaim#issuer() issuer}
   *    .verified(boolean) // optional {@link _JWTClaim#verified() verified}
   *    .innerClaim(JWTClaim) // optional {@link _JWTClaim#innerClaim() innerClaim}
   *    .depth(int) // optional {@link _JWTClaim#depth() depth}
   *    .build();
   * 
* @return A new JWTClaim builder */ public static JWTClaim.Builder builder() { return new JWTClaim.Builder(); } /** * Builds instances of type {@link JWTClaim JWTClaim}. * 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 = "_JWTClaim", generator = "Immutables") public static final class Builder { private static final long INIT_BIT_NAME = 0x1L; private static final long INIT_BIT_VALUE = 0x2L; private static final long OPT_BIT_VERIFIED = 0x1L; private static final long OPT_BIT_DEPTH = 0x2L; private long initBits = 0x3L; private long optBits; private String name; private Object value; private String issuer; private boolean verified; private JWTClaim innerClaim; private int depth; private Builder() { } /** * Fill a builder with attribute values from the provided {@code _JWTClaim} 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 */ @CanIgnoreReturnValue public final Builder from(_JWTClaim instance) { Objects.requireNonNull(instance, "instance"); name(instance.name()); value(instance.value()); issuer(instance.issuer()); verified(instance.verified()); Optional innerClaimOptional = instance.innerClaim(); if (innerClaimOptional.isPresent()) { innerClaim(innerClaimOptional); } depth(instance.depth()); return this; } /** * Initializes the value for the {@link _JWTClaim#name() name} attribute. * @param name The value for name * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder name(String name) { this.name = Objects.requireNonNull(name, "name"); initBits &= ~INIT_BIT_NAME; return this; } /** * Initializes the value for the {@link _JWTClaim#value() value} attribute. * @param value The value for value * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder value(Object value) { this.value = Objects.requireNonNull(value, "value"); initBits &= ~INIT_BIT_VALUE; return this; } /** * Initializes the value for the {@link _JWTClaim#issuer() issuer} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link _JWTClaim#issuer() issuer}. * @param issuer The value for issuer * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder issuer(String issuer) { this.issuer = Objects.requireNonNull(issuer, "issuer"); return this; } /** * Initializes the value for the {@link _JWTClaim#verified() verified} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link _JWTClaim#verified() verified}. * @param verified The value for verified * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder verified(boolean verified) { this.verified = verified; optBits |= OPT_BIT_VERIFIED; return this; } /** * Initializes the optional value {@link _JWTClaim#innerClaim() innerClaim} to innerClaim. * @param innerClaim The value for innerClaim * @return {@code this} builder for chained invocation */ @CanIgnoreReturnValue public final Builder innerClaim(JWTClaim innerClaim) { this.innerClaim = Objects.requireNonNull(innerClaim, "innerClaim"); return this; } /** * Initializes the optional value {@link _JWTClaim#innerClaim() innerClaim} to innerClaim. * @param innerClaim The value for innerClaim * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder innerClaim(Optional innerClaim) { this.innerClaim = innerClaim.orElse(null); return this; } /** * Initializes the value for the {@link _JWTClaim#depth() depth} attribute. *

If not set, this attribute will have a default value as returned by the initializer of {@link _JWTClaim#depth() depth}. * @param depth The value for depth * @return {@code this} builder for use in a chained invocation */ @CanIgnoreReturnValue public final Builder depth(int depth) { this.depth = depth; optBits |= OPT_BIT_DEPTH; return this; } /** * Builds a new {@link JWTClaim JWTClaim}. * @return An immutable instance of JWTClaim * @throws java.lang.IllegalStateException if any required attributes are missing */ public JWTClaim build() { if (initBits != 0) { throw new IllegalStateException(formatRequiredAttributesMessage()); } return new JWTClaim(this); } private boolean verifiedIsSet() { return (optBits & OPT_BIT_VERIFIED) != 0; } private boolean depthIsSet() { return (optBits & OPT_BIT_DEPTH) != 0; } private String formatRequiredAttributesMessage() { List attributes = new ArrayList<>(); if ((initBits & INIT_BIT_NAME) != 0) attributes.add("name"); if ((initBits & INIT_BIT_VALUE) != 0) attributes.add("value"); return "Cannot build JWTClaim, some of required attributes are not set " + attributes; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy