]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.api.uuid/src/org/argeo/api/uuid/RandomUuid.java
Improve build and local deployment
[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 opaque.
18 */
19 @Override
20 public final boolean isOpaque() {
21 return true;
22 }
23
24 /** Creates a new {@link RandomUuid} using {@link UUID#randomUUID()}. */
25 public static RandomUuid newRandomUuid() {
26 return new RandomUuid(UUID.randomUUID());
27 }
28
29 }