public abstract class BaseNCodec extends Object implements UuidCodec<String>
| 限定符和类型 | 类和说明 |
|---|---|
static interface |
BaseNCodec.CustomDivider
A division function that returns quotient and remainder.
|
| 限定符和类型 | 方法和说明 |
|---|---|
UUID |
decode(String string)
Get a UUID from an encoded string.
|
String |
encode(UUID uuid)
Get an encoded string from a UUID.
|
BaseN |
getBase()
Get the base-n encoding object.
|
static BaseNCodec |
newInstance(BaseN base)
Static factory that returns a new instance of
BaseNCodec using the
specified BaseN. |
static BaseNCodec |
newInstance(BaseN base,
BaseNCodec.CustomDivider divider)
Static factory that returns a new instance of
BaseNCodec using the
specified BaseN and a BaseNCodec.CustomDivider. |
static BaseNCodec |
newInstance(int radix)
Static factory that returns a new instance of
BaseNCodec using the
specified radix. |
static BaseNCodec |
newInstance(int radix,
BaseNCodec.CustomDivider divider)
Static factory that returns a new instance of
BaseNCodec using the
specified radix and a BaseNCodec.CustomDivider. |
static BaseNCodec |
newInstance(String alphabet)
Static factory that returns a new instance of
BaseNCodec using the
specified alphabet. |
static BaseNCodec |
newInstance(String alphabet,
BaseNCodec.CustomDivider divider)
Static factory that returns a new instance of
BaseNCodec using the
specified alphabet and a BaseNCodec.CustomDivider. |
public static BaseNCodec newInstance(BaseN base)
BaseNCodec using the
specified BaseN.
This method can be used if none of the existing concrete codecs of this package class is desired.
The BaseNCodec objects provided by this method encode UUIDs using
remainder operation (modulus), a common approach to encode integers.
If you need a BaseN that is not available in this package, use the
static factories newInstance(String) or
newInstance(int).
base - an object that represents the base-n encodingBaseNCodecpublic static BaseNCodec newInstance(int radix)
BaseNCodec using the
specified radix.
This method can be used if none of the existing concrete codecs of this package class is desired.
The BaseNCodec objects provided by this method encode UUIDs using
remainder operator (modulus), a common approach to encode integers.
The example below shows how to create a BaseNCodec for an
hypothetical base-40 encoding that contains only letters. You only need to
pass a number 40. The BaseNCodec instantiates a BaseN object
internally. See BaseN.
String radix = 40;
BaseNCodec codec = BaseNCodec.newInstance(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 usedBaseNCodecpublic static BaseNCodec newInstance(String alphabet)
BaseNCodec using the
specified alphabet.
This method can be used if none of the existing concrete codecs of this package class is desired.
The BaseNCodec objects provided by this method encode UUIDs using
remainder operator (modulus), a common approach to encode integers.
The example below shows how to create a BaseNCodec for an
hypothetical base-26 encoding that contains only letters. You only need to
pass a string with 26 characters. The BaseNCodec instantiates a
BaseN object internally. See BaseN.
String alphabet = "abcdefghijklmnopqrstuvwxyz";
BaseNCodec codec = BaseNCodec.newInstance(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";
BaseNCodec codec = BaseNCodec.newInstance(alphabet);
alphabet - the alphabet to be usedBaseNCodecpublic static BaseNCodec newInstance(BaseN base, BaseNCodec.CustomDivider divider)
BaseNCodec using the
specified BaseN and a BaseNCodec.CustomDivider.base - an object that represents the base-n encodingdivider - a division function that returns quotient and remainderBaseNCodecpublic static BaseNCodec newInstance(int radix, BaseNCodec.CustomDivider divider)
BaseNCodec using the
specified radix and a BaseNCodec.CustomDivider.radix - the radix to be useddivider - a division function that returns quotient and remainderBaseNCodecpublic static BaseNCodec newInstance(String alphabet, BaseNCodec.CustomDivider divider)
BaseNCodec using the
specified alphabet and a BaseNCodec.CustomDivider.alphabet - the alphabet to be useddivider - a division function that returns quotient and remainderBaseNCodecpublic BaseN getBase()
public String encode(UUID uuid)
encode 在接口中 UuidCodec<String>uuid - a UUIDInvalidUuidException - if the argument is invalidCopyright © 2024. All rights reserved.