public final class BaseN extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static String |
ALPHABET_36
The default alphabet for case-insensitive base-n.
|
protected static String |
ALPHABET_64
The default alphabet for case-sensitive base-n.
|
protected static int |
RADIX_MAX
The maximum radix: 64.
|
protected static int |
RADIX_MIN
The minimum radix: 2.
|
| Constructor and Description |
|---|
BaseN(int radix)
Public constructor for the base-n object.
|
BaseN(String alphabet)
Public constructor for the base-n object.
|
| Modifier and Type | Method and Description |
|---|---|
protected static char[] |
expand(char a,
char b)
Expands a character sequence similar to 0-9, a-z and A-Z.
|
protected static String |
expand(String string)
Expands character sequences similar to 0-9, a-z and A-Z.
|
CharArray |
getAlphabet()
Returns the alphabet of the base-n.
|
int |
getLength()
Returns the length of encoded UUIDs.
|
ByteArray |
getMap()
Returns the map of the base-n.
|
char |
getPadding()
Return the padding character.
|
int |
getRadix()
Returns the radix of the base-n.
|
boolean |
isSensitive()
Informs if the base-n is case-sensitive.
|
boolean |
isValid(String uuid)
Checks if the UUID string is valid.
|
void |
validate(String uuid)
Checks if the UUID string is a valid.
|
protected static final int RADIX_MIN
protected static final int RADIX_MAX
protected static final String ALPHABET_36
protected static final String ALPHABET_64
public BaseN(int radix)
The radix is the alphabet size.
The supported alphabet sizes are from 2 to 64.
If there are mixed cases in the alphabet, the base-n is case SENSITIVE.
The encoded string length is equal to `CEIL(128 / LOG2(n))`, where n is the radix. The encoded string is padded to fit the expected length.
The padding character is the first character of the string. For example, the padding character for the alphabet "abcdef0123456" is 'a'.
The example below shows how to create a BaseN for an hypothetical
base-26 encoding that contains only letters. You only need to pass a number
40.
String radix = 40;
BaseN base = new BaseN(radix);
If radix is greater than 36, the alphabet generated is a subset of the character sequence "0-9A-Za-z-_". Otherwise it is a subset of "0-9a-z". In the example above the resulting alphabet is "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd" (0-9A-Za-d).
radix - the radix to be usedpublic BaseN(String alphabet)
The radix is the alphabet size.
The supported alphabet sizes are from 2 to 64.
If there are mixed cases in the alphabet, the base-n is case SENSITIVE.
The encoded string length is equal to `CEIL(128 / LOG2(n))`, where n is the radix. The encoded string is padded to fit the expected length.
The padding character is the first character of the string. For example, the padding character for the alphabet "abcdef0123456" is 'a'.
The example below shows how to create a BaseN for an hypothetical
base-26 encoding that contains only letters. You only need to pass a string
with 26 characters.
String alphabet = "abcdefghijklmnopqrstuvwxyz";
BaseN base = new BaseN(alphabet);
Alphabet strings similar to "a-f0-9" are expanded to "abcdef0123456789". The
same example using the string "a-z" instead of "abcdefghijklmnopqrstuvwxyz":
String alphabet = "a-z";
BaseN base = new BaseN(alphabet);
alphabet - the alphabet to be usedpublic int getRadix()
public int getLength()
public char getPadding()
public boolean isSensitive()
public CharArray getAlphabet()
public ByteArray getMap()
public boolean isValid(String uuid)
uuid - a UUID stringpublic void validate(String uuid)
uuid - a UUID stringInvalidUuidException - if the argument is invalidprotected static String expand(String string)
string - a string to be expandedprotected static char[] expand(char a,
char b)
a - the first character of the sequenceb - the last character of the sequenceCopyright © 2024. All rights reserved.