Package ai.bizone.shortuuid
Class ShortUuid
java.lang.Object
ai.bizone.shortuuid.ShortUuid
ShortUuid is a class that can be used to encode and decode UUIDs to a shorter string representation.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringrandom(boolean caseSensitive) Create a ShortUuidstatic StringtoShortUuid(UUID uuid, boolean caseSensitive) Encode UUID to ShortUuidstatic UUIDDecode ShortUuid to UUIDstatic StringtryShorteningId(String id, boolean caseSensitive) Try to shorten an identifier, if it is a UUID it will be converted to Base36.
-
Field Details
-
UUID_BITS
private static final int UUID_BITS- See Also:
-
-
Constructor Details
-
ShortUuid
public ShortUuid()
-
-
Method Details
-
random
Create a ShortUuid- Parameters:
caseSensitive- whether the id can be case-sensitive (in this case use a larger base to encode the id)- Returns:
- ShortUuid encoded UUID
-
toShortUuid
Encode UUID to ShortUuid- Parameters:
uuid- UUID to be encodedcaseSensitive- whether the id can be case-sensitive (in this case use a larger base to encode the id)- Returns:
- ShortUuid encoded UUID
-
toUuid
Decode ShortUuid to UUID- Parameters:
shortId- encoded UUIDcaseSensitive- whether the id can be case-sensitive (in this case use a larger base to encode the id)- Returns:
- decoded UUID
-
tryShorteningId
Try to shorten an identifier, if it is a UUID it will be converted to Base36. Otherwise, all non-alphanumeric characters will be removed- Parameters:
id- An identifier to shortcaseSensitive- whether the id can be case-sensitive (in this case use a larger base to encode the id)- Returns:
- The shortened string
-