import java.util.BitSet;
import java.util.Enumeration;
import java.util.Objects;
+import java.util.UUID;
/**
* A configurable implementation of an {@link AsyncUuidFactory}, which can be
assert newTimeUUID().node() == BitSet.valueOf(defaultNodeId).toLongArray()[0];
}
+ /*
+ * DEFAULT
+ */
+ /**
+ * The default {@link UUID} to provide. This implementations returns
+ * {@link #timeUUID()} because it is fast and uses few resources.
+ */
+ @Override
+ public UUID get() {
+ return timeUUID();
+ }
+
@Override
protected SecureRandom newSecureRandom() {
SecureRandom secureRandom;
--- /dev/null
+package org.argeo.api.uuid;
+
+import java.util.UUID;
+
+/**
+ * An {@link UuidFactory} which does not implement any algorith and returns
+ * {@link UnsupportedOperationException} for methods requiring them. Only
+ * {@link UuidFactory#get()} and {@link UuidFactory#randomUUID()} are
+ * implemented, trivially based on {@link UUID#randomUUID()}. It can be useful
+ * as a base class for partial implementations, or whren only random
+ * {@link UUID}s are needed, but one wants to integrate with this UUID API via
+ * {@link UuidFactory}.
+ */
+public class NoOpUuidFactory implements UuidFactory {
+ public static final UuidFactory onlyJavaRandom = new NoOpUuidFactory();
+
+ /** Returns {@link #randomUUID()}. */
+ @Override
+ public UUID get() {
+ return randomUUID();
+ }
+
+ /**
+ * Creates a random UUID (v4) with {@link UUID#randomUUID()}.
+ *
+ * @return a random {@link UUID}
+ */
+ @Override
+ public UUID randomUUID() {
+ return UUID.randomUUID();
+ }
+
+ /**
+ * Throws an {@link UnsupportedOperationException}.
+ *
+ * @throws UnsupportedOperationException always
+ */
+ @Override
+ public UUID timeUUID() {
+ throw new UnsupportedOperationException("Time based UUIDs are not implemented");
+ }
+
+ /**
+ * Throws an {@link UnsupportedOperationException}.
+ *
+ * @throws UnsupportedOperationException always
+ */
+ @Override
+ public UUID nameUUIDv5(UUID namespace, byte[] data) {
+ throw new UnsupportedOperationException("Name based UUIDs are not implemented");
+ }
+
+ /**
+ * Throws an {@link UnsupportedOperationException}.
+ *
+ * @throws UnsupportedOperationException always
+ */
+ @Override
+ public UUID nameUUIDv3(UUID namespace, byte[] data) {
+ throw new UnsupportedOperationException("Name based UUIDs are not implemented");
+ }
+
+ /**
+ * Throws an {@link UnsupportedOperationException}.
+ *
+ * @throws UnsupportedOperationException always
+ */
+ @Override
+ public UUID randomUUIDStrong() {
+ throw new UnsupportedOperationException("Strong random UUIDs are not implemented");
+ }
+
+ /**
+ * Throws an {@link UnsupportedOperationException}.
+ *
+ * @throws UnsupportedOperationException always
+ */
+ @Override
+ public UUID randomUUIDWeak() {
+ throw new UnsupportedOperationException("Weak random UUIDs are not implemented");
+ }
+
+}
* @see https://datatracker.ietf.org/doc/html/rfc4122
*/
public interface UuidFactory extends Supplier<UUID> {
+ /*
+ * DEFAULT
+ */
+ /**
+ * The default {@link UUID} to provide, either random (v4) or time based (v1).
+ * It SHOULD wrap either {@link #timeUUID()} (recommended) or
+ * {@link #randomUUID()}.
+ */
+ @Override
+ UUID get();
+
/*
* TIME-BASED (version 1)
*/
return randomUUIDStrong();
}
- /**
- * The default {@link UUID} to provide, either random (v4) or time based (v1).
- * This default implementations returns {@link #timeUUID()} because it is
- * supposed to be fast and use few resources.
- */
- @Override
- default UUID get() {
- return timeUUID();
- }
-
/*
* STANDARD UUIDs
*/