public class StandardStringCodec extends Object implements UuidCodec<String>
In the canonical textual representation, the 16 bytes of a UUID are represented as 32 hexadecimal (base-16) digits, displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 hexadecimal characters and 4 hyphens).
This codec decodes (parses) strings in these formats:
The encoding and decoding processes can be much faster (7x) than
UUID.toString() and UUID.fromString(String) in JDK 8.
If you prefer a string representation without hyphens, use
Base16Codec instead of StandardStringCodec.
Base16Codec can be much faster (22x) than doing
uuid.toString().replaceAll("-", "").
| Modifier and Type | Field and Description |
|---|---|
static StandardStringCodec |
INSTANCE
A shared immutable instance.
|
| Constructor and Description |
|---|
StandardStringCodec() |
| Modifier and Type | Method and Description |
|---|---|
UUID |
decode(String string)
Get a UUID from a string.
|
String |
encode(UUID uuid)
Get a string from a UUID.
|
protected static String |
modify(String string) |
public static final StandardStringCodec INSTANCE
public String encode(UUID uuid)
It can be much faster than UUID.toString() in JDK 8.
encode in interface UuidCodec<String>uuid - a UUIDInvalidUuidException - if the argument is invalidpublic UUID decode(String string)
It accepts strings:
It can be much faster than UUID.fromString(String) in JDK 8.
It also can be twice as fast as UUID.fromString(String) in JDK 11.
decode in interface UuidCodec<String>string - a UUID stringInvalidUuidException - if the argument is invalidCopyright © 2024. All rights reserved.