Package dev.orne.beans
Class StringIdentity
- All Implemented Interfaces:
Identity,Serializable
Implementation for
Identity for identities composed
of a single inner String value.- Since:
- 0.1
- Version:
- 1.0, 2020-05
- Author:
- (w) Iker Hernaez
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionStringIdentity(@NotNull StringIdentity copy) Copy constructor.StringIdentity(String value) Creates a new instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull StringextractRequiredTokenValue(@NotNull String prefix, @NotNull String token) Extracts theStringvalue of a token generated byStringIdentity.static StringextractTokenValue(@NotNull String prefix, @NotNull String token) Extracts theStringvalue of a token generated byStringIdentity.static @NotNull StringIdentityfromIdentityToken(@NotNull String token) Resolves the specified identity token to a validStringIdentity.Methods inherited from class dev.orne.beans.AbstractSimpleIdentity
equals, getIdentityTokenBody, getValue, hashCodeMethods inherited from class dev.orne.beans.AbstractIdentity
getIdentityToken, getIdentityTokenPrefix, parseIdentityTokenBody, toString
-
Constructor Details
-
StringIdentity
Creates a new instance.- Parameters:
value- The identity value
-
StringIdentity
Copy constructor.- Parameters:
copy- The instance to copy
-
-
Method Details
-
fromIdentityToken
@IdentityTokenResolver @NotNull public static @NotNull StringIdentity fromIdentityToken(@NotNull @NotNull String token) Resolves the specified identity token to a validStringIdentity.- Parameters:
token- The identity token- Returns:
- The resolved identity token
- Throws:
NullPointerException- If the identity token isnullUnrecognizedIdentityTokenException- If the identity token is not a valid identity token or it doesn't start with the expected prefix
-
extractTokenValue
public static String extractTokenValue(@NotNull @NotNull String prefix, @NotNull @NotNull String token) Extracts theStringvalue of a token generated byStringIdentity.Note that the resulting value can be
null. If a non-null value is expected useextractRequiredTokenValue(String, String).- Parameters:
prefix- The expected identity token prefix.token- The identity token.- Returns:
- The extracted
Stringvalue. - Throws:
NullPointerException- If the identity token isnullUnrecognizedIdentityTokenException- If the identity token is not a valid simple identity token or if it doesn't start with the expected prefix.- See Also:
-
extractRequiredTokenValue
@NotNull public static @NotNull String extractRequiredTokenValue(@NotNull @NotNull String prefix, @NotNull @NotNull String token) Extracts theStringvalue of a token generated byStringIdentity.If the resulting value is
nullan exception is thrown.- Parameters:
prefix- The expected identity token prefix.token- The identity token.- Returns:
- The extracted
Stringvalue. - Throws:
NullPointerException- If the identity token isnullUnrecognizedIdentityTokenException- If the identity token is not a valid simple identity token, if it doesn't start with the expected prefix or if the extracted value is null.- See Also:
-