public class Uid extends Object implements Comparable<Uid>, Serializable
UUID.
The main difference is the encoding which is optimized for brevity. In contrast to the hex-encoding used
by UUID, the toString() method uses standard
base64url
(RFC 4648). The difference to normal base64 is
that base64url replaces '+' by '-' and '/' by '_' in order to make the encoded string usable in URLs
without any escaping.
Important: The string-representation is case-sensitive!
Examples showing the difference of UUID vs. Uid:
WQL8yMHUQ4FhZrB0cLux5g WCRAGMeiz-2PPaKdmn-iww Jd6_KRqpMivfuxXO4JmwtQ 284tn0-92bIMRNV_4M53Tg 8b726260-f9f3-439b-bf21-615bb4b6731d 34fadc2b-5a58-4de8-b04c-6f315a6598cd 15c3f6cb-6275-4557-b24c-2cd57cd07a6d 11934d8c-d201-4a95-a714-e03ff48f5053 46875d87-01ef-4ece-98cf-5a96a5946ef7
A string-encoded UUID always has a length 36 characters, while a Uid always has a length
of 22 characters. In other words, the strings are 38.89% shorter.
Instances of this class are immutable.
| Modifier and Type | Field and Description |
|---|---|
static int |
LENGTH_BYTES
Gets the length of an
Uid in bytes. |
static int |
LENGTH_STRING
Gets the length of an
Uid in its String representation. |
| Constructor and Description |
|---|
Uid()
Creates a new random
Uid. |
Uid(byte[] bytes) |
Uid(long hi,
long lo)
Creates a new
Uid with the given value. |
Uid(String uidString)
Creates a new
Uid instance from the encoded value in uidString. |
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(Uid other) |
boolean |
equals(Object obj) |
int |
hashCode() |
byte[] |
toBytes() |
String |
toString()
Gets a base64url-encoded string-representation of this
Uid. |
public static final int LENGTH_BYTES
Uid in bytes.public static final int LENGTH_STRING
Uid in its String representation.public Uid()
Uid.public Uid(long hi, long lo)
Uid with the given value.
This constructor is equivalent to UUID(long, long).
hi - the most significant bits of the new Uid.lo - the least significant bits of the new Uid.public Uid(byte[] bytes)
public Uid(String uidString)
Uid instance from the encoded value in uidString.
This constructor is symmetric to the toString() method: The output of toString() can
be passed to this constructor to create a new instance with the same value as (and thus being
equal to) the first instance.
uidString - the string-encoded value of the Uid.toString()public byte[] toBytes()
public String toString()
Uid.
The string returned by this method can be passed to Uid(String) to create a new equal
Uid instance.
Important: The string-representation is case-sensitive!
Inherited documentation:
public int compareTo(Uid other)
compareTo in interface Comparable<Uid>Copyright © 2013–2017. All rights reserved.