]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.api.uuid/src/org/argeo/api/uuid/BasicNameUuid.java
All typed UUIDs implemented (except v2).
[lgpl/argeo-commons.git] / org.argeo.api.uuid / src / org / argeo / api / uuid / BasicNameUuid.java
diff --git a/org.argeo.api.uuid/src/org/argeo/api/uuid/BasicNameUuid.java b/org.argeo.api.uuid/src/org/argeo/api/uuid/BasicNameUuid.java
new file mode 100644 (file)
index 0000000..b883e0d
--- /dev/null
@@ -0,0 +1,31 @@
+package org.argeo.api.uuid;
+
+import java.util.UUID;
+
+/** A name based UUID (v3 or v5) whose construction values are not known. */
+public class BasicNameUuid extends TypedUuid {
+       private static final long serialVersionUID = APM.SERIAL;
+
+       public BasicNameUuid(UUID uuid) {
+               super(uuid);
+               if ((uuid.version() != 5 && uuid.version() != 3) || uuid.variant() != 2)
+                       throw new IllegalArgumentException("The provided UUID is not a name-based UUID.");
+       }
+
+       /**
+        * Always returns <code>true</true> since it is unknown from which values it was
+        * constructed..
+        */
+       @Override
+       public boolean isOpaque() {
+               return true;
+       }
+
+       /**
+        * Whether the hash of this name UUID was generated with SHA-1 (v5) or with MD5
+        * (v3).
+        */
+       public boolean isSha1() {
+               return uuid.version() == 5;
+       }
+}