Refactor CMS UUID factory
[lgpl/argeo-commons.git] / org.argeo.api.uuid / src / org / argeo / api / uuid / AbstractUuidFactory.java
index 75a6339b01681f48a1890468b4a56f303bbee43b..4486a9f8b4b907ccb347fa0f78c71b7e3ff30f7a 100644 (file)
@@ -12,7 +12,7 @@ import java.util.UUID;
 /**
  * Implementation of the basic RFC4122 algorithms.
  * 
- * @see https://datatracker.ietf.org/doc/html/rfc4122
+ * @see "https://datatracker.ietf.org/doc/html/rfc4122"
  */
 public abstract class AbstractUuidFactory implements UuidFactory {
 
@@ -23,7 +23,8 @@ public abstract class AbstractUuidFactory implements UuidFactory {
        private final static long MOST_SIG_VERSION1 = (1l << 12);
        private final static long LEAST_SIG_RFC4122_VARIANT = (1l << 63);
 
-       protected UUID newTimeUUID(long timestamp, long clockSequence, byte[] node, int offset) {
+       @Deprecated
+       protected UUID createTimeUUID(long timestamp, long clockSequence, byte[] node, int offset) {
                Objects.requireNonNull(node, "Node array cannot be null");
                if (node.length < offset + 6)
                        throw new IllegalArgumentException("Node array must be at least 6 bytes long");
@@ -53,19 +54,23 @@ public abstract class AbstractUuidFactory implements UuidFactory {
                return uuid;
        }
 
+       @Deprecated
        protected UUID timeUUID(Temporal time, long clockSequence, byte[] node, int offset) {
                // TODO add checks
                Duration duration = Duration.between(TimeUuid.TIMESTAMP_ZERO, time);
                // Number of 100 ns intervals in one second: 1000000000 / 100 = 10000000
                long timestamp = duration.getSeconds() * 10000000 + duration.getNano() / 100;
-               return newTimeUUID(timestamp, clockSequence, node, offset);
+               return createTimeUUID(timestamp, clockSequence, node, offset);
        }
 
        /*
         * NAME BASED (version 3 and 5)
         */
+       protected UUID createNameUUIDv5(UUID namespace, byte[] name) {
+               return createNameUUIDv5Static(namespace, name);
+       }
 
-       protected UUID newNameUUIDv5(UUID namespace, byte[] name) {
+       static UUID createNameUUIDv5Static(UUID namespace, byte[] name) {
                Objects.requireNonNull(namespace, "Namespace cannot be null");
                Objects.requireNonNull(name, "Name cannot be null");
 
@@ -78,7 +83,11 @@ public abstract class AbstractUuidFactory implements UuidFactory {
                return result;
        }
 
-       protected UUID newNameUUIDv3(UUID namespace, byte[] name) {
+       protected UUID createNameUUIDv3(UUID namespace, byte[] name) {
+               return createNameUUIDv3Static(namespace, name);
+       }
+
+       static UUID createNameUUIDv3Static(UUID namespace, byte[] name) {
                Objects.requireNonNull(namespace, "Namespace cannot be null");
                Objects.requireNonNull(name, "Name cannot be null");
 
@@ -91,7 +100,7 @@ public abstract class AbstractUuidFactory implements UuidFactory {
        /*
         * RANDOM v4
         */
-       protected UUID newRandomUUID(Random random) {
+       protected UUID createRandomUUID(Random random) {
                byte[] arr = new byte[16];
                random.nextBytes(arr);
                arr[6] &= 0x0f;
@@ -101,30 +110,6 @@ public abstract class AbstractUuidFactory implements UuidFactory {
                return UuidBinaryUtils.fromBytes(arr);
        }
 
-       /*
-        * SPI UTILITIES
-        */
-       /** Guarantees that a byte array of length 6 will be returned. */
-       protected static byte[] toNodeIdBytes(byte[] source, int offset) {
-               if (source == null)
-                       return null;
-               if (offset < 0 || offset + 6 > source.length)
-                       throw new ArrayIndexOutOfBoundsException(offset);
-               byte[] nodeId = new byte[6];
-               System.arraycopy(source, offset, nodeId, 0, 6);
-               return nodeId;
-       }
-
-       /**
-        * Force this node id to be identified as no MAC address.
-        * 
-        * @see https://datatracker.ietf.org/doc/html/rfc4122#section-4.5
-        */
-       protected static void forceToNoMacAddress(byte[] nodeId, int offset) {
-               assert nodeId != null && offset < nodeId.length;
-               nodeId[offset] = (byte) (nodeId[offset] | 1);
-       }
-
        /*
         * DIGEST UTILITIES
         */