public class UuidBuilder extends Object
Usage:
SecureRandom random = new SecureRandom();
UUID uuid = new UuidBuilder(4) // sets version 4 (random-based)
.put(random.nextLong()) // put the most significant 64 bits
.put(random.nextLong()) // put the least significant 64 bits
.build(); // return the built UUID
| Constructor and Description |
|---|
UuidBuilder()
Instantiates a new builder without a version number.
|
UuidBuilder(int version)
Instantiates a new builder with a version number.
|
| Modifier and Type | Method and Description |
|---|---|
UUID |
build()
Builds a UUID after all 16 bytes are filled.
|
UuidBuilder |
put(byte value)
Puts the given byte.
|
UuidBuilder |
put(byte[] array)
Puts the given byte array.
|
UuidBuilder |
put(int value)
Puts 4 bytes containing the given int.
|
UuidBuilder |
put(long value)
Puts 8 bytes containing the given long.
|
UuidBuilder |
put(short value)
Puts 2 bytes containing the given short.
|
public UuidBuilder()
public UuidBuilder(int version)
version - a value between 0 and 15public UuidBuilder put(long value)
value - a long valueBufferOverflowException - If there are fewer than 8 bytes remainingpublic UuidBuilder put(int value)
value - an int valueBufferOverflowException - If there are fewer than 4 bytes remainingpublic UuidBuilder put(short value)
value - a short valueBufferOverflowException - If there are fewer than 2 bytes remainingpublic UuidBuilder put(byte value)
value - a byte valueBufferOverflowException - If there are fewer than 1 bytes remainingpublic UuidBuilder put(byte[] array)
value - a byte arrayBufferOverflowException - If there are fewer bytes remaining than the
array lengthpublic UUID build()
This method ends the use of a builder.
Successive calls will always return the same UUID value.
Note: this method overrides bits 48 through 51 (version field) and bits 52 through 63 (variant field), 6 bits total, to comply the UUID specification.
BufferUnderflowException - If there are bytes remaining to be filledCopyright © 2024. All rights reserved.