Updates for 0.9.3
[debian/openrocket] / src / net / sf / openrocket / util / UniqueID.java
diff --git a/src/net/sf/openrocket/util/UniqueID.java b/src/net/sf/openrocket/util/UniqueID.java
new file mode 100644 (file)
index 0000000..1cc082e
--- /dev/null
@@ -0,0 +1,33 @@
+package net.sf.openrocket.util;
+
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class UniqueID {
+       
+       private static AtomicInteger nextId = new AtomicInteger(1);
+       
+       /**
+        * Return a positive integer ID unique during this program execution.  
+        * The values are taken as sequential numbers, and will re-occur in 
+        * later executions of the program.
+        * <p>
+        * This method is thread-safe and fast.
+        * 
+        * @return      a positive integer ID unique in this program execution.
+        */
+       public static int next() {
+               return nextId.getAndIncrement();
+       }
+
+       
+       /**
+        * Return a new universally unique ID string.
+        * 
+        * @return      a unique identifier string.
+        */
+       public static String uuid() {
+               return UUID.randomUUID().toString();
+       }
+       
+}