Skip to content

Commit a74857e

Browse files
committed
Minor javadoc changes, cleanup post #84
1 parent 7ddb95a commit a74857e

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

release-notes/VERSION

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ Releases
88

99
#78: TimeBasedEpochGenerator (UUIDv7) can't be provided a `UUIDClock`
1010
(reported by @Frozenlock)
11+
#84: Add `construct()` methods to specify the milliseconds being used
12+
for time-based UUID generation
13+
(contributed by @BranchPredictor)
1114

1215
4.2.0 (14-May-2023)
1316

src/main/java/com/fasterxml/uuid/impl/TimeBasedEpochGenerator.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,18 @@ public UUID generate()
105105
}
106106

107107
/**
108-
* @since 4.3
108+
* Method that will construct actual {@link UUID} instance for given
109+
* unix epoch timestamp: called by {@link #generate()} but may alternatively be
110+
* called directly to construct an instance with known timestamp.
111+
* NOTE: calling this method directly produces somewhat distinct UUIDs as
112+
* "entropy" value is still generated as necessary to avoid producing same
113+
* {@link UUID} even if same timestamp is being passed.
114+
*
109115
* @param rawTimestamp unix epoch millis
116+
*
110117
* @return unix epoch time based UUID
118+
*
119+
* @since 4.3
111120
*/
112121
public UUID construct(long rawTimestamp)
113122
{

src/main/java/com/fasterxml/uuid/impl/TimeBasedGenerator.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,22 @@ public TimeBasedGenerator(EthernetAddress ethAddr, UUIDTimer timer)
8989
@Override
9090
public UUID generate()
9191
{
92-
final long rawTimestamp = _timer.getTimestamp();
93-
return construct(rawTimestamp);
92+
return construct(_timer.getTimestamp());
9493
}
9594

9695
/**
96+
* Method that will construct actual {@link UUID} instance for given
97+
* timestamp: called by {@link #generate()} but may alternatively be
98+
* called directly to construct an instance with known timestamp.
99+
* NOTE: calling this method directly does NOT guarantee uniqueness of resulting
100+
* {@link UUID} (caller has to guarantee uniqueness)
101+
*
102+
* @param rawTimestamp Timestamp usually obtained from {@link UUIDTimer#getTimestamp()},
103+
* used for constructing UUID instance
104+
*
105+
* @return unix Time-based UUID constructed for given timestamp
106+
*
97107
* @since 4.3
98-
* @param rawTimestamp unix epoch millis
99-
* @return unix epoch time based UUID
100108
*/
101109
public UUID construct(long rawTimestamp)
102110
{

src/main/java/com/fasterxml/uuid/impl/TimeBasedReorderedGenerator.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,22 @@ public TimeBasedReorderedGenerator(EthernetAddress ethAddr, UUIDTimer timer)
9595
public UUID generate()
9696
{
9797
// Ok, get 60-bit timestamp (4 MSB are ignored)
98-
final long rawTimestamp = _timer.getTimestamp();
99-
return construct(rawTimestamp);
98+
return construct(_timer.getTimestamp());
10099
}
101100

102101
/**
102+
* Method that will construct actual {@link UUID} instance for given
103+
* timestamp: called by {@link #generate()} but may alternatively be
104+
* called directly to construct an instance with known timestamp.
105+
* NOTE: calling this method directly does NOT guarantee uniqueness of resulting
106+
* {@link UUID} (caller has to guarantee uniqueness)
107+
*
108+
* @param rawTimestamp Timestamp usually obtained from {@link UUIDTimer#getTimestamp()},
109+
* used for constructing UUID instance
110+
*
111+
* @return unix Time-based, Reordered UUID constructed for given timestamp
112+
*
103113
* @since 4.3
104-
* @param rawTimestamp unix epoch millis
105-
* @return unix epoch time based UUID
106114
*/
107115
public UUID construct(long rawTimestamp)
108116
{

0 commit comments

Comments
 (0)