All typed UUIDs implemented (except v2).
[lgpl/argeo-commons.git] / org.argeo.api.uuid / src / org / argeo / api / uuid / TypedUuid.java
index 55a67abef04dfde862d8b7e9de56e943cb73e950..2a0842fe6ef3679f5a82c9827b99441f5113d5b5 100644 (file)
@@ -4,8 +4,9 @@ import java.util.Objects;
 import java.util.UUID;
 
 /**
- * Base class for objects which are explicitly typed, based on the various UUID
- * versions. Such a derivation hierarchy still represents the {@link UUID}
+ * Base class for objects which are explicitly typed, based on the various
+ * variant 2 (RFC 4122) UUID versions (and variant 6 with {@link GUID}, for
+ * completion). Such a derivation hierarchy still represents the {@link UUID}
  * itself, not the objects, data or concept that it identifies. Just like
  * {@link UUID}s, {@link TypedUuid} should be used as identifier, not as base
  * class for complex objects. It should rather be seen as a framework to build
@@ -35,7 +36,9 @@ public abstract class TypedUuid extends UuidHolder {
 
        /**
         * Constructs a {@link TypedUuid} of the most appropriate subtype, based on this
-        * {@link UUID}.
+        * {@link UUID}. For name based UUIDs, it will return an opaque
+        * {@link BasicNameUuid}; {@link NameUuid} and {@link BinaryNameUuid} may be
+        * more useful.
         */
        public static TypedUuid of(UUID uuid) {
                Objects.requireNonNull(uuid, "UUID cannot be null");
@@ -47,14 +50,15 @@ public abstract class TypedUuid extends UuidHolder {
                                return new RandomUuid(uuid);
                        case 3:
                        case 5:
-                               return new UnkownNameUuid(uuid);
+                               return new BasicNameUuid(uuid);
                        default:
                                throw new IllegalArgumentException("UUIDs with version " + uuid.version() + " are not supported.");
                        }
-               } else if (uuid.variant() == 6) {// Microsoft
-                       throw new IllegalArgumentException("Microsoft UUIDs (aka. GUIDs) are not supported.");
+               } else if (uuid.variant() == 6) {// GUID
+                       return new GUID(uuid);
                } else {
                        throw new IllegalArgumentException("UUIDs with variant " + uuid.variant() + " are not supported.");
                }
        }
+
 }