ctf: Make events immutable
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / trace / Utils.java
index efed12738e66b9668f91a0debe709498a0f330eb..f76f055b8821c541ad4f4097e1b14a282261646a 100644 (file)
@@ -14,6 +14,9 @@ package org.eclipse.linuxtools.ctf.core.trace;
 
 import java.util.UUID;
 
+import org.eclipse.linuxtools.ctf.core.event.types.ArrayDefinition;
+import org.eclipse.linuxtools.ctf.core.event.types.IntegerDefinition;
+
 /**
  * Various utilities.
  *
@@ -21,9 +24,10 @@ import java.util.UUID;
  * @author Matthew Khouzam
  * @author Simon Marchi
  */
-public class Utils {
+public final class Utils {
 
-    private Utils() {}
+    private Utils() {
+    }
 
     // ------------------------------------------------------------------------
     // Constants
@@ -73,9 +77,9 @@ public class Utils {
      */
     public static int unsignedCompare(long left, long right) {
         /*
-         * This method assumes that the arithmetic overflow on signed
-         * integer wrap on a circular domain (modulo arithmetic in
-         * two-complement), which is the defined behavior in Java.
+         * This method assumes that the arithmetic overflow on signed integer
+         * wrap on a circular domain (modulo arithmetic in two-complement),
+         * which is the defined behavior in Java.
          *
          * This idea is to rotate the domain by the length of the negative
          * space, and then use the signed operator.
@@ -90,6 +94,31 @@ public class Utils {
         return 0;
     }
 
+    /**
+     * Gets a UUID from an array defintion
+     *
+     * @param uuidDef
+     *            the array defintions, must contain integer bytes
+     * @return the UUID
+     * @throws CTFReaderException
+     *             if the definition contains less than 16 elements
+     * @since 3.0
+     */
+    public static UUID getUUIDfromDefinition(ArrayDefinition uuidDef) throws CTFReaderException {
+        byte[] uuidArray = new byte[16];
+
+        for (int i = 0; i < uuidArray.length; i++) {
+            IntegerDefinition uuidByteDef = (IntegerDefinition) uuidDef.getElem(i);
+            if (uuidByteDef == null) {
+                throw new CTFReaderException("UUID incomplete, only " + i + " bytes available"); //$NON-NLS-1$ //$NON-NLS-2$
+            }
+            uuidArray[i] = (byte) uuidByteDef.getValue();
+        }
+
+        UUID uuid = Utils.makeUUID(uuidArray);
+        return uuid;
+    }
+
     /**
      * Creates a UUID object from an array of 16 bytes.
      *
This page took 0.027455 seconds and 5 git commands to generate.