Class BaseNCodec
- java.lang.Object
-
- com.github.f4b6a3.uuid.codec.base.BaseNCodec
-
- Direct Known Subclasses:
Base16Codec,Base32Codec,Base32CrockfordCodec,Base32HexCodec,Base36Codec,Base58BitcoinCodec,Base58Codec,Base58FlickrCodec,Base62Codec,Base64Codec,Base64UrlCodec
public abstract class BaseNCodec extends Object implements UuidCodec<String>
Abstract class that contains the basic functionality for base-n codecs of this package.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseNCodec(BaseN base)protectedBaseNCodec(BaseN base, BaseNEncoder encoder, BaseNDecoder decoder)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UUIDdecode(String string)Stringencode(UUID uuid)BaseNgetBase()static BaseNCodecnewInstance(int radix)Static factory that returns a new instance ofBaseNCodecusing the specified radix.static BaseNCodecnewInstance(BaseN base)Static factory that returns a new instance ofBaseNCodecusing the specifiedBaseN.static BaseNCodecnewInstance(String alphabet)Static factory that returns a new instance ofBaseNCodecusing the specified alphabet.
-
-
-
Constructor Detail
-
BaseNCodec
protected BaseNCodec(BaseN base)
- Parameters:
base- an object that represents the base-n encoding
-
BaseNCodec
protected BaseNCodec(BaseN base, BaseNEncoder encoder, BaseNDecoder decoder)
- Parameters:
base- an object that represents the base-n encodingencoder- a functional encoderdecoder- a functional decoder
-
-
Method Detail
-
newInstance
public static BaseNCodec newInstance(BaseN base)
Static factory that returns a new instance ofBaseNCodecusing the specifiedBaseN. This method can be used if none of the existing concrete codecs of this package class is desired. TheBaseNCodecobjects provided by this method encode UUIDs using remainder operation (modulus), a common approach to encode integers. If you need aBaseNthat is not available in this package, use the static factoriesnewInstance(String)ornewInstance(int).- Parameters:
base- an object that represents the base-n encoding- Returns:
- a
BaseNCodec
-
newInstance
public static BaseNCodec newInstance(int radix)
Static factory that returns a new instance ofBaseNCodecusing the specified radix. This method can be used if none of the existing concrete codecs of this package class is desired. TheBaseNCodecobjects provided by this method encode UUIDs using remainder operator (modulus), a common approach to encode integers. The example below shows how to create aBaseNCodecfor an hypothetical base-40 encoding that contains only letters. You only need to pass a number 40. TheBaseNCodecinstantiates aBaseNobject internally. SeeBaseN.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).- Parameters:
radix- the radix to be used- Returns:
- a
BaseNCodec
-
newInstance
public static BaseNCodec newInstance(String alphabet)
Static factory that returns a new instance ofBaseNCodecusing the specified alphabet. This method can be used if none of the existing concrete codecs of this package class is desired. TheBaseNCodecobjects provided by this method encode UUIDs using remainder operator (modulus), a common approach to encode integers. The example below shows how to create aBaseNCodecfor an hypothetical base-26 encoding that contains only letters. You only need to pass a string with 26 characters. TheBaseNCodecinstantiates aBaseNobject internally. SeeBaseN.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);
- Parameters:
alphabet- the alphabet to be used- Returns:
- a
BaseNCodec
-
getBase
public BaseN getBase()
-
-