Package com.github.f4b6a3.ulid.util
Class UlidUtil
- java.lang.Object
-
- com.github.f4b6a3.ulid.util.UlidUtil
-
public final class UlidUtil extends Object
-
-
Field Summary
Fields Modifier and Type Field Description protected static char[]ALPHABET_CROCKFORDprotected static char[]ALPHABET_JAVAprotected static intBASE_32protected static intULID_LENGTH
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static longdecode(char[] chars, char[] alphabet)Decode a base 32 char array to a long number.protected static char[]encode(long number, char[] alphabet)Encode a long number to base 32 char array.static InstantextractInstant(String ulid)static StringextractRandomnessComponent(String ulid)static longextractTimestamp(String ulid)static StringextractTimestampComponent(String ulid)protected static longextractUnixMilliseconds(String ulid)static longfromBase32Crockford(char[] chars)protected static booleanisCrockfordBase32(char c)protected static booleanisCrockfordBase32(char[] chars)protected static char[]lpad(char[] chars, int length, char fill)protected static char[]removeHyphens(char[] input)static char[]toBase32Crockford(long number)protected static byte[]toBytes(long number)Get an array of bytes from a given number.static longtoNumber(byte[] bytes)Get a number from a given array of bytes.static longtoNumber(byte[] bytes, int start, int end)protected static char[]toUpperCase(char[] chars)protected static char[]transliterate(char[] chars, char[] alphabet1, char[] alphabet2)protected static Stringtransliterate(String string, char[] alphabet1, char[] alphabet2)protected static char[]zerofill(char[] chars, int length)
-
-
-
Field Detail
-
BASE_32
protected static final int BASE_32
- See Also:
- Constant Field Values
-
ULID_LENGTH
protected static final int ULID_LENGTH
- See Also:
- Constant Field Values
-
ALPHABET_CROCKFORD
protected static final char[] ALPHABET_CROCKFORD
-
ALPHABET_JAVA
protected static final char[] ALPHABET_JAVA
-
-
Method Detail
-
extractTimestamp
public static long extractTimestamp(String ulid)
-
extractUnixMilliseconds
protected static long extractUnixMilliseconds(String ulid)
-
toNumber
public static long toNumber(byte[] bytes)
Get a number from a given array of bytes.- Parameters:
bytes- a byte array- Returns:
- a long
-
toNumber
public static long toNumber(byte[] bytes, int start, int end)
-
toBytes
protected static byte[] toBytes(long number)
Get an array of bytes from a given number.- Parameters:
number- a long value- Returns:
- a byte array
-
removeHyphens
protected static char[] removeHyphens(char[] input)
-
toBase32Crockford
public static char[] toBase32Crockford(long number)
-
fromBase32Crockford
public static long fromBase32Crockford(char[] chars)
-
isCrockfordBase32
protected static boolean isCrockfordBase32(char[] chars)
-
isCrockfordBase32
protected static boolean isCrockfordBase32(char c)
-
zerofill
protected static char[] zerofill(char[] chars, int length)
-
lpad
protected static char[] lpad(char[] chars, int length, char fill)
-
transliterate
protected static String transliterate(String string, char[] alphabet1, char[] alphabet2)
-
transliterate
protected static char[] transliterate(char[] chars, char[] alphabet1, char[] alphabet2)
-
toUpperCase
protected static char[] toUpperCase(char[] chars)
-
encode
protected static char[] encode(long number, char[] alphabet)Encode a long number to base 32 char array.- Parameters:
number- a long numberalphabet- an alphabet- Returns:
- a base32 encoded char array
-
decode
protected static long decode(char[] chars, char[] alphabet)Decode a base 32 char array to a long number.- Parameters:
chars- a base 32 encoded char arrayalphabet- an alphabet- Returns:
- a long number
-
-