- java.lang.Object
-
- com.github.f4b6a3.uuid.util.UuidBuilder
-
public class UuidBuilder extends Object
A UUID builder.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 Summary
Constructors Constructor Description UuidBuilder()Instantiates a new builder without a version number.UuidBuilder(int version)Instantiates a new builder with a version number.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UUIDbuild()Builds a UUID after all 16 bytes are filled.UuidBuilderput(byte value)Puts the given byte.UuidBuilderput(byte[] array)Puts the given byte array.UuidBuilderput(int value)Puts 4 bytes containing the given int.UuidBuilderput(long value)Puts 8 bytes containing the given long.UuidBuilderput(short value)Puts 2 bytes containing the given short.
-
-
-
Method Detail
-
put
public UuidBuilder put(long value)
Puts 8 bytes containing the given long.- Parameters:
value- a long value- Returns:
- This buffer
- Throws:
BufferOverflowException- If there are fewer than 8 bytes remaining
-
put
public UuidBuilder put(int value)
Puts 4 bytes containing the given int.- Parameters:
value- an int value- Returns:
- This buffer
- Throws:
BufferOverflowException- If there are fewer than 4 bytes remaining
-
put
public UuidBuilder put(short value)
Puts 2 bytes containing the given short.- Parameters:
value- a short value- Returns:
- This buffer
- Throws:
BufferOverflowException- If there are fewer than 2 bytes remaining
-
put
public UuidBuilder put(byte value)
Puts the given byte.- Parameters:
value- a byte value- Returns:
- This buffer
- Throws:
BufferOverflowException- If there are fewer than 1 bytes remaining
-
put
public UuidBuilder put(byte[] array)
Puts the given byte array.- Parameters:
value- a byte array- Returns:
- This buffer
- Throws:
BufferOverflowException- If there are fewer bytes remaining than the array length
-
build
public UUID build()
Builds a UUID after all 16 bytes are filled.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.
- Throws:
BufferUnderflowException- If there are bytes remaining to be filled
-
-