X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api.uuid%2Fsrc%2Forg%2Fargeo%2Fapi%2Fuuid%2FNameUuid.java;fp=org.argeo.api.uuid%2Fsrc%2Forg%2Fargeo%2Fapi%2Fuuid%2FNameUuid.java;h=376eea4bcf671e7ec2c6d5a78622107ec308706b;hb=593a4eabb76b74cd382ecf3f181d57abe0d643f9;hp=a1c64a1a12b80b55f512b6436245ae95839f9707;hpb=e8e2c65f356b30b35e4d8a1de66691a789c183bb;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.api.uuid/src/org/argeo/api/uuid/NameUuid.java b/org.argeo.api.uuid/src/org/argeo/api/uuid/NameUuid.java index a1c64a1a1..376eea4bc 100644 --- a/org.argeo.api.uuid/src/org/argeo/api/uuid/NameUuid.java +++ b/org.argeo.api.uuid/src/org/argeo/api/uuid/NameUuid.java @@ -1,16 +1,38 @@ package org.argeo.api.uuid; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.UUID; -/** A name {@link UUID} whose values used for its construction are known. */ -public class NameUuid extends UnkownNameUuid { +/** A name UUID whose values used for its construction are known. */ +public class NameUuid extends BasicNameUuid { private static final long serialVersionUID = APM.SERIAL; protected final TypedUuid namespace; protected final String name; protected final Charset encoding; + /** + * Default static builder which creates a v5 (SHA1) name based {@link UUID}, + * using UTF-8 encoding. Use + * {@link #NameUuid(TypedUuid, String, Charset, boolean)} for more options. + */ + public NameUuid(TypedUuid namespace, String name) { + this(namespace, name, StandardCharsets.UTF_8, true); + } + + /** Static builder (an {@link TypedUuidFactory} may be more efficient). */ + public NameUuid(TypedUuid namespace, String name, Charset encoding, boolean sha1) { + this(sha1 ? AbstractUuidFactory.createNameUUIDv5Static(namespace.uuid, name.getBytes(encoding)) + : AbstractUuidFactory.createNameUUIDv5Static(namespace.uuid, name.getBytes(encoding)), namespace, name, + encoding); + } + + /** + * Since no check is performed, the constructor is protected so that the object + * can only be built by the default methods of {@link TypedUuidFactory} (in this + * package) or by extending the class. + */ protected NameUuid(UUID uuid, TypedUuid namespace, String name, Charset encoding) { super(uuid); assert namespace != null; @@ -21,10 +43,6 @@ public class NameUuid extends UnkownNameUuid { this.encoding = encoding; } - public static long getSerialversionuid() { - return serialVersionUID; - } - /** The namespace used to build this UUID. */ public final TypedUuid getNamespace() { return namespace;