]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.uuid/src/org/argeo/api/uuid/RandomUuid.java
Experiment with package-based make
[lgpl/argeo-commons.git] / org.argeo.api.uuid / src / org / argeo / api / uuid / RandomUuid.java
1 package org.argeo.api.uuid;
2
3 import java.util.UUID;
4
5 /** An opaque variant 2 random {@link UUID} (v4). */
6 public final class RandomUuid extends TypedUuid {
7 private static final long serialVersionUID = APM.SERIAL;
8
9 /** Constructor based on a {@link UUID}. */
10 public RandomUuid(UUID uuid) {
11 super(uuid);
12 if (uuid.version() != 4 && uuid.variant() != 2)
13 throw new IllegalArgumentException("The provided UUID is not a time-based UUID.");
14 }
15
16 /**
17 * Always returns <code>true</code> since random UUIDs are by definition not
18 * opaque.
19 */
20 @Override
21 public final boolean isOpaque() {
22 return true;
23 }
24
25 /** Creates a new {@link RandomUuid} using {@link UUID#randomUUID()}. */
26 public static RandomUuid newRandomUuid() {
27 return new RandomUuid(UUID.randomUUID());
28 }
29
30 }