Bug 378401: Implementation of time graph widget.
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / widgets / timegraph / widgets / Utils.java
index 7f2b41fe60046eeda861443f7aa2da27d191f668..e50cf37394800007ad7390be1551577ddb4f2591 100644 (file)
@@ -1,16 +1,16 @@
 /*****************************************************************************\r
- * Copyright (c) 2007, 2008 Intel Corporation and others.\r
+ * Copyright (c) 2007, 2008 Intel Corporation, 2009, 2012 Ericsson.\r
  * All rights reserved. This program and the accompanying materials\r
  * are made available under the terms of the Eclipse Public License v1.0\r
  * which accompanies this distribution, and is available at\r
  * http://www.eclipse.org/legal/epl-v10.html\r
  *\r
  * Contributors:\r
- *    Intel Corporation - Initial API and implementation\r
- *    Ruslan A. Scherbakov, Intel - Initial API and implementation\r
- *    Alvaro Sanchex-Leon - Udpated for TMF\r
+ *   Intel Corporation - Initial API and implementation\r
+ *   Ruslan A. Scherbakov, Intel - Initial API and implementation\r
+ *   Alvaro Sanchez-Leon - Udpated for TMF\r
+ *   Patrick Tasse - Refactoring\r
  *\r
- * $Id: Utils.java,v 1.11 2008/06/16 21:04:49 jkubasta Exp $ \r
  *****************************************************************************/\r
 \r
 package org.eclipse.linuxtools.tmf.ui.widgets.timegraph.widgets;\r
@@ -20,9 +20,8 @@ import java.util.Date;
 import java.util.Iterator;\r
 import java.util.TimeZone;\r
 \r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.ITimeAnalysisViewer.TimeFormat;\r
 import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeEvent;\r
-import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITmfTimeAnalysisEntry;\r
+import org.eclipse.linuxtools.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;\r
 import org.eclipse.swt.graphics.Color;\r
 import org.eclipse.swt.graphics.Device;\r
 import org.eclipse.swt.graphics.GC;\r
@@ -32,316 +31,295 @@ import org.eclipse.swt.widgets.Display;
 \r
 public class Utils {\r
 \r
-       static public final int IMG_THREAD_RUNNING = 0;\r
-       static public final int IMG_THREAD_SUSPENDED = 1;\r
-       static public final int IMG_THREAD_STOPPED = 2;\r
-       static public final int IMG_METHOD_RUNNING = 3;\r
-       static public final int IMG_METHOD = 4;\r
-       static public final int IMG_NUM = 5;\r
+    public enum TimeFormat {\r
+        RELATIVE, ABSOLUTE\r
+    };\r
 \r
-       static public final Object[] _empty = new Object[0];\r
+    static public final int IMG_THREAD_RUNNING = 0;\r
+    static public final int IMG_THREAD_SUSPENDED = 1;\r
+    static public final int IMG_THREAD_STOPPED = 2;\r
+    static public final int IMG_METHOD_RUNNING = 3;\r
+    static public final int IMG_METHOD = 4;\r
+    static public final int IMG_NUM = 5;\r
 \r
-       static enum Resolution {\r
-               SECONDS, MILLISEC, MICROSEC, NANOSEC\r
-       };\r
+    static public final Object[] _empty = new Object[0];\r
 \r
-       static private final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$\r
-       static private final SimpleDateFormat sdateformat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$\r
-       static {\r
+    static enum Resolution {\r
+        SECONDS, MILLISEC, MICROSEC, NANOSEC\r
+    };\r
+\r
+    static private final SimpleDateFormat stimeformat = new SimpleDateFormat("HH:mm:ss"); //$NON-NLS-1$\r
+    static private final SimpleDateFormat sdateformat = new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$\r
+    static {\r
         stimeformat.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$\r
         sdateformat.setTimeZone(TimeZone.getTimeZone("GMT")); //$NON-NLS-1$\r
-       }\r
-\r
-//     static private String _externalPlugin[] = { "org.eclipse.debug.ui",\r
-//                     "org.eclipse.debug.ui", "org.eclipse.debug.ui",\r
-//                     "org.eclipse.debug.ui", "org.eclipse.debug.ui", };\r
-//\r
-//     static private String _externalPath[] = {\r
-//                     "icons/full/obj16/thread_obj.gif", // running thread\r
-//                     "icons/full/obj16/threads_obj.gif", // suspended\r
-//                     "icons/full/obj16/threadt_obj.gif", // stopped\r
-//                     "icons/full/obj16/stckframe_running_obj.gif", // running stack frame\r
-//                     "icons/full/obj16/stckframe_obj.gif", // stack frame\r
-//     };\r
-\r
-//     static public Image getImage(int idx) {\r
-//             if (idx < 0 || idx >= IMG_NUM)\r
-//                     SWT.error(SWT.ERROR_INVALID_ARGUMENT);\r
-//             String key = "trace.img." + idx;\r
-//             Image img = TimeAnalysisPlugin.getDefault().getImageRegistry().get(key);\r
-//             if (null == img) {\r
-//                     ImageDescriptor desc = AbstractUIPlugin.imageDescriptorFromPlugin(\r
-//                                     _externalPlugin[idx], _externalPath[idx]);\r
-//                     TimeAnalysisPlugin.getDefault().getImageRegistry().put(key, desc);\r
-//                     img = TimeAnalysisPlugin.getDefault().getImageRegistry().get(key);\r
-//             }\r
-//             return img;\r
-//     }\r
-\r
-       static public void init(Rectangle rect) {\r
-               rect.x = 0;\r
-               rect.y = 0;\r
-               rect.width = 0;\r
-               rect.height = 0;\r
-       }\r
-\r
-       static public void init(Rectangle rect, int x, int y, int width, int height) {\r
-               rect.x = x;\r
-               rect.y = y;\r
-               rect.width = width;\r
-               rect.height = height;\r
-       }\r
-\r
-       static public void init(Rectangle rect, Rectangle source) {\r
-               rect.x = source.x;\r
-               rect.y = source.y;\r
-               rect.width = source.width;\r
-               rect.height = source.height;\r
-       }\r
-\r
-       static public void deflate(Rectangle rect, int x, int y) {\r
-               rect.x += x;\r
-               rect.y += y;\r
-               rect.width -= x + x;\r
-               rect.height -= y + y;\r
-       }\r
-\r
-       static public void inflate(Rectangle rect, int x, int y) {\r
-               rect.x -= x;\r
-               rect.y -= y;\r
-               rect.width += x + x;\r
-               rect.height += y + y;\r
-       }\r
-\r
-       static void dispose(Color col) {\r
-               if (null != col)\r
-                       col.dispose();\r
-       }\r
-\r
-       static public Color mixColors(Device display, Color c1, Color c2, int w1,\r
-                       int w2) {\r
-               return new Color(display, (w1 * c1.getRed() + w2 * c2.getRed())\r
-                               / (w1 + w2), (w1 * c1.getGreen() + w2 * c2.getGreen())\r
-                               / (w1 + w2), (w1 * c1.getBlue() + w2 * c2.getBlue())\r
-                               / (w1 + w2));\r
-       }\r
-\r
-       static public Color getSysColor(int id) {\r
-               Color col = Display.getCurrent().getSystemColor(id);\r
-               return new Color(col.getDevice(), col.getRGB());\r
-       }\r
-\r
-       static public Color mixColors(Color col1, Color col2, int w1, int w2) {\r
-               return mixColors(Display.getCurrent(), col1, col2, w1, w2);\r
-       }\r
-\r
-       static public int drawText(GC gc, String text, Rectangle rect,\r
-                       boolean transp) {\r
-               Point size = gc.stringExtent(text);\r
-               gc.drawText(text, rect.x, rect.y, transp);\r
-               return size.x;\r
-       }\r
-\r
-       static public int drawText(GC gc, String text, int x, int y, boolean transp) {\r
-               Point size = gc.stringExtent(text);\r
-               gc.drawText(text, x, y, transp);\r
-               return size.x;\r
-       }\r
-\r
-       /**\r
+    }\r
+\r
+    static Rectangle clone(Rectangle source) {\r
+        return new Rectangle(source.x, source.y, source.width, source.height);\r
+    }\r
+\r
+    static public void init(Rectangle rect) {\r
+        rect.x = 0;\r
+        rect.y = 0;\r
+        rect.width = 0;\r
+        rect.height = 0;\r
+    }\r
+\r
+    static public void init(Rectangle rect, int x, int y, int width, int height) {\r
+        rect.x = x;\r
+        rect.y = y;\r
+        rect.width = width;\r
+        rect.height = height;\r
+    }\r
+\r
+    static public void init(Rectangle rect, Rectangle source) {\r
+        rect.x = source.x;\r
+        rect.y = source.y;\r
+        rect.width = source.width;\r
+        rect.height = source.height;\r
+    }\r
+\r
+    static public void deflate(Rectangle rect, int x, int y) {\r
+        rect.x += x;\r
+        rect.y += y;\r
+        rect.width -= x + x;\r
+        rect.height -= y + y;\r
+    }\r
+\r
+    static public void inflate(Rectangle rect, int x, int y) {\r
+        rect.x -= x;\r
+        rect.y -= y;\r
+        rect.width += x + x;\r
+        rect.height += y + y;\r
+    }\r
+\r
+    static void dispose(Color col) {\r
+        if (null != col)\r
+            col.dispose();\r
+    }\r
+\r
+    static public Color mixColors(Device display, Color c1, Color c2, int w1,\r
+            int w2) {\r
+        return new Color(display, (w1 * c1.getRed() + w2 * c2.getRed())\r
+                / (w1 + w2), (w1 * c1.getGreen() + w2 * c2.getGreen())\r
+                / (w1 + w2), (w1 * c1.getBlue() + w2 * c2.getBlue())\r
+                / (w1 + w2));\r
+    }\r
+\r
+    static public Color getSysColor(int id) {\r
+        Color col = Display.getCurrent().getSystemColor(id);\r
+        return new Color(col.getDevice(), col.getRGB());\r
+    }\r
+\r
+    static public Color mixColors(Color col1, Color col2, int w1, int w2) {\r
+        return mixColors(Display.getCurrent(), col1, col2, w1, w2);\r
+    }\r
+\r
+    static public int drawText(GC gc, String text, Rectangle rect, boolean transp) {\r
+        Point size = gc.stringExtent(text);\r
+        gc.drawText(text, rect.x, rect.y, transp);\r
+        return size.x;\r
+    }\r
+\r
+    static public int drawText(GC gc, String text, int x, int y, boolean transp) {\r
+        Point size = gc.stringExtent(text);\r
+        gc.drawText(text, x, y, transp);\r
+        return size.x;\r
+    }\r
+\r
+    /**\r
      * Formats time in format: MM:SS:NNN\r
      * \r
-        * @param time time\r
-        * @param format  0: MMMM:ss:nnnnnnnnn, 1: HH:MM:ss MMM.mmmm.nnn\r
-        * @param resolution the resolution\r
-        * @return the formatted time\r
-        */\r
-       static public String formatTime(long time, TimeFormat format, Resolution resolution) {\r
-               // if format is absolute (Calendar)\r
-               if (format == TimeFormat.ABSOLUTE) {\r
-                       return formatTimeAbs(time, resolution);\r
-               }\r
-\r
-               StringBuffer str = new StringBuffer();\r
-               boolean neg = time < 0;\r
-               if (neg) {\r
-                       time = -time;\r
-                       str.append('-');\r
-               }\r
-\r
-               long sec = (long) (time * 1E-9);\r
-               // TODO: Expand to make it possible to select the minute, second, nanosecond format\r
-               //printing minutes is suppressed just sec and ns\r
-               // if (sec / 60 < 10)\r
-               // str.append('0');\r
-               // str.append(sec / 60);\r
-               // str.append(':');\r
-               // sec %= 60;\r
-               // if (sec < 10)\r
-               // str.append('0');\r
-               str.append(sec);\r
-               String ns = formatNs(time, resolution);\r
-               if (!ns.equals("")) { //$NON-NLS-1$\r
-                       str.append(':');\r
-                       str.append(ns);\r
-               }\r
-\r
-               return str.toString();\r
-       }\r
-\r
-       /**\r
-        * From input time in nanoseconds, convert to Date format YYYY-MM-dd\r
-        * \r
-        * @param absTime\r
-        * @return the formatted date\r
-        */\r
-       public static String formatDate(long absTime) {\r
-               String sdate = sdateformat.format(new Date((long) (absTime * 1E-6)));\r
-               return sdate;\r
-       }\r
-\r
-       /**\r
-        * Formats time in ns to Calendar format: HH:MM:SS MMM.mmm.nnn\r
-        * \r
-        * @param time\r
-        * @return the formatted time\r
-        */\r
-       static public String formatTimeAbs(long time, Resolution res) {\r
-               StringBuffer str = new StringBuffer();\r
-\r
-               // format time from nanoseconds to calendar time HH:MM:SS\r
-               String stime = stimeformat.format(new Date((long) (time * 1E-6)));\r
-               str.append(stime + " "); //$NON-NLS-1$\r
-               // append the Milliseconds, MicroSeconds and NanoSeconds as specified in\r
-               // the Resolution\r
-               str.append(formatNs(time, res));\r
-               return str.toString();\r
-       }\r
-\r
-       /**\r
-        * Obtains the remainder fraction on unit Seconds of the entered value in\r
-        * nanoseconds. e.g. input: 1241207054171080214 ns The number of fraction\r
-        * seconds can be obtained by removing the last 9 digits: 1241207054 the\r
-        * fractional portion of seconds, expressed in ns is: 171080214\r
-        * \r
-        * @param time\r
-        * @param res\r
-        * @return the formatted nanosec\r
-        */\r
-       public static String formatNs(long time, Resolution res) {\r
-               StringBuffer temp = new StringBuffer();\r
-               boolean neg = time < 0;\r
-               if (neg) {\r
-                       time = -time;\r
-               }\r
-\r
-               // The following approach could be used although performance\r
-               // decreases in half.\r
-               // String strVal = String.format("%09d", time);\r
-               // String tmp = strVal.substring(strVal.length() - 9);\r
-\r
-               // number of segments to be included\r
-               int segments = 0;\r
-               switch (res) {\r
-               case MILLISEC:\r
-                       segments = 1;\r
-                       break;\r
-               case MICROSEC:\r
-                       segments = 2;\r
-                       break;\r
-               case NANOSEC:\r
-                       segments = 3;\r
-                       break;\r
-               default:\r
-                       break;\r
-               }\r
-\r
-               long ns = time;\r
-               ns %= 1000000000;\r
-               if (ns < 10) {\r
-                       temp.append("00000000"); //$NON-NLS-1$\r
-               } else if (ns < 100) {\r
-                       temp.append("0000000"); //$NON-NLS-1$\r
-               } else if (ns < 1000) {\r
-                       temp.append("000000"); //$NON-NLS-1$\r
-               } else if (ns < 10000) {\r
-                       temp.append("00000"); //$NON-NLS-1$\r
-               } else if (ns < 100000) {\r
-                       temp.append("0000"); //$NON-NLS-1$\r
-               } else if (ns < 1000000) {\r
-                       temp.append("000"); //$NON-NLS-1$\r
-               } else if (ns < 10000000) {\r
-                       temp.append("00"); //$NON-NLS-1$\r
-               } else if (ns < 100000000) {\r
-                       temp.append("0"); //$NON-NLS-1$\r
-               }\r
-               temp.append(ns);\r
-\r
-               StringBuffer str = new StringBuffer();\r
-               if (segments > 0) {\r
-                       // append ms\r
-                       str.append(temp.substring(0, 3));\r
-               }\r
-               if (segments > 1) {\r
-                       // append Micro secs\r
-                       str.append("."); //$NON-NLS-1$\r
-                       str.append(temp.substring(3, 6));\r
-               }\r
-               if (segments > 2) {\r
-                       // append Nano seconds\r
-                       str.append("."); //$NON-NLS-1$\r
-                       str.append(temp.substring(6));\r
-               }\r
-\r
-               return str.toString();\r
-       }\r
-\r
-       static public int loadIntOption(String opt, int def, int min, int max) {\r
-               // int val =\r
-               // TraceUIPlugin.getDefault().getPreferenceStore().getInt(opt);\r
-               // if (0 == val)\r
-               // val = def;\r
-               // if (val < min)\r
-               // val = min;\r
-               // if (val > max)\r
-               // val = max;\r
-               return def;\r
-       }\r
-\r
-       // static public int loadIntOption(String opt) {\r
-       // int val = TraceUIPlugin.getDefault().getPreferenceStore().getInt(opt);\r
-       // return val;\r
-       // }\r
-\r
-       static public void saveIntOption(String opt, int val) {\r
-               // TraceUIPlugin.getDefault().getPreferenceStore().setValue(opt, val);\r
-       }\r
-\r
-       static ITimeEvent getFirstEvent(ITmfTimeAnalysisEntry thread) {\r
-               if (null == thread)\r
-                       return null;\r
-               Iterator<ITimeEvent> iterator = thread.getTraceEventsIterator();\r
-               if (iterator.hasNext()) {\r
-                   return iterator.next();\r
-               } else {\r
-                   return null;\r
-               }\r
-       }\r
-\r
-       /**\r
-        * N means: <list> <li>-1: Previous Event</li> <li>0: Current Event</li> <li>\r
-        * 1: Next Event</li> <li>2: Previous Event when located in a non Event Area\r
-        * </list>\r
-        * \r
-        * @param thread\r
-        * @param time\r
-        * @param n\r
-        * @return\r
-        */\r
-    static ITimeEvent findEvent(ITmfTimeAnalysisEntry thread, long time, int n) {\r
+     * @param time time\r
+     * @param format  0: MMMM:ss:nnnnnnnnn, 1: HH:MM:ss MMM.mmmm.nnn\r
+     * @param resolution the resolution\r
+     * @return the formatted time\r
+     */\r
+    static public String formatTime(long time, TimeFormat format, Resolution resolution) {\r
+        // if format is absolute (Calendar)\r
+        if (format == TimeFormat.ABSOLUTE) {\r
+            return formatTimeAbs(time, resolution);\r
+        }\r
+\r
+        StringBuffer str = new StringBuffer();\r
+        boolean neg = time < 0;\r
+        if (neg) {\r
+            time = -time;\r
+            str.append('-');\r
+        }\r
+\r
+        long sec = (long) (time * 1E-9);\r
+        // TODO: Expand to make it possible to select the minute, second, nanosecond format\r
+        //printing minutes is suppressed just sec and ns\r
+        // if (sec / 60 < 10)\r
+        // str.append('0');\r
+        // str.append(sec / 60);\r
+        // str.append(':');\r
+        // sec %= 60;\r
+        // if (sec < 10)\r
+        // str.append('0');\r
+        str.append(sec);\r
+        String ns = formatNs(time, resolution);\r
+        if (!ns.equals("")) { //$NON-NLS-1$\r
+            str.append(':');\r
+            str.append(ns);\r
+        }\r
+\r
+        return str.toString();\r
+    }\r
+\r
+    /**\r
+     * From input time in nanoseconds, convert to Date format YYYY-MM-dd\r
+     * \r
+     * @param absTime\r
+     * @return the formatted date\r
+     */\r
+    public static String formatDate(long absTime) {\r
+        String sdate = sdateformat.format(new Date((long) (absTime * 1E-6)));\r
+        return sdate;\r
+    }\r
+\r
+    /**\r
+     * Formats time in ns to Calendar format: HH:MM:SS MMM.mmm.nnn\r
+     * \r
+     * @param time\r
+     * @return the formatted time\r
+     */\r
+    static public String formatTimeAbs(long time, Resolution res) {\r
+        StringBuffer str = new StringBuffer();\r
+\r
+        // format time from nanoseconds to calendar time HH:MM:SS\r
+        String stime = stimeformat.format(new Date((long) (time * 1E-6)));\r
+        str.append(stime + " "); //$NON-NLS-1$\r
+        // append the Milliseconds, MicroSeconds and NanoSeconds as specified in\r
+        // the Resolution\r
+        str.append(formatNs(time, res));\r
+        return str.toString();\r
+    }\r
+\r
+    /**\r
+     * Obtains the remainder fraction on unit Seconds of the entered value in\r
+     * nanoseconds. e.g. input: 1241207054171080214 ns The number of fraction\r
+     * seconds can be obtained by removing the last 9 digits: 1241207054 the\r
+     * fractional portion of seconds, expressed in ns is: 171080214\r
+     * \r
+     * @param time\r
+     * @param res\r
+     * @return the formatted nanosec\r
+     */\r
+    public static String formatNs(long time, Resolution res) {\r
+        StringBuffer temp = new StringBuffer();\r
+        boolean neg = time < 0;\r
+        if (neg) {\r
+            time = -time;\r
+        }\r
+\r
+        // The following approach could be used although performance\r
+        // decreases in half.\r
+        // String strVal = String.format("%09d", time);\r
+        // String tmp = strVal.substring(strVal.length() - 9);\r
+\r
+        // number of segments to be included\r
+        int segments = 0;\r
+        switch (res) {\r
+        case MILLISEC:\r
+            segments = 1;\r
+            break;\r
+        case MICROSEC:\r
+            segments = 2;\r
+            break;\r
+        case NANOSEC:\r
+            segments = 3;\r
+            break;\r
+        default:\r
+            break;\r
+        }\r
+\r
+        long ns = time;\r
+        ns %= 1000000000;\r
+        if (ns < 10) {\r
+            temp.append("00000000"); //$NON-NLS-1$\r
+        } else if (ns < 100) {\r
+            temp.append("0000000"); //$NON-NLS-1$\r
+        } else if (ns < 1000) {\r
+            temp.append("000000"); //$NON-NLS-1$\r
+        } else if (ns < 10000) {\r
+            temp.append("00000"); //$NON-NLS-1$\r
+        } else if (ns < 100000) {\r
+            temp.append("0000"); //$NON-NLS-1$\r
+        } else if (ns < 1000000) {\r
+            temp.append("000"); //$NON-NLS-1$\r
+        } else if (ns < 10000000) {\r
+            temp.append("00"); //$NON-NLS-1$\r
+        } else if (ns < 100000000) {\r
+            temp.append("0"); //$NON-NLS-1$\r
+        }\r
+        temp.append(ns);\r
+\r
+        StringBuffer str = new StringBuffer();\r
+        if (segments > 0) {\r
+            // append ms\r
+            str.append(temp.substring(0, 3));\r
+        }\r
+        if (segments > 1) {\r
+            // append Micro secs\r
+            str.append("."); //$NON-NLS-1$\r
+            str.append(temp.substring(3, 6));\r
+        }\r
+        if (segments > 2) {\r
+            // append Nano seconds\r
+            str.append("."); //$NON-NLS-1$\r
+            str.append(temp.substring(6));\r
+        }\r
+\r
+        return str.toString();\r
+    }\r
+\r
+    static public int loadIntOption(String opt, int def, int min, int max) {\r
+        // int val =\r
+        // TraceUIPlugin.getDefault().getPreferenceStore().getInt(opt);\r
+        // if (0 == val)\r
+        // val = def;\r
+        // if (val < min)\r
+        // val = min;\r
+        // if (val > max)\r
+        // val = max;\r
+        return def;\r
+    }\r
+\r
+    static public void saveIntOption(String opt, int val) {\r
+        // TraceUIPlugin.getDefault().getPreferenceStore().setValue(opt, val);\r
+    }\r
+\r
+    static ITimeEvent getFirstEvent(ITimeGraphEntry thread) {\r
+        if (null == thread)\r
+            return null;\r
+        Iterator<ITimeEvent> iterator = thread.getTimeEventsIterator();\r
+        if (iterator != null && iterator.hasNext()) {\r
+            return iterator.next();\r
+        } else {\r
+            return null;\r
+        }\r
+    }\r
+\r
+    /**\r
+     * N means: <list> <li>-1: Previous Event</li> <li>0: Current Event</li> <li>\r
+     * 1: Next Event</li> <li>2: Previous Event when located in a non Event Area\r
+     * </list>\r
+     * \r
+     * @param thread\r
+     * @param time\r
+     * @param n\r
+     * @return\r
+     */\r
+    static ITimeEvent findEvent(ITimeGraphEntry thread, long time, int n) {\r
         if (null == thread)\r
             return null;\r
-        Iterator<ITimeEvent> iterator = thread.getTraceEventsIterator();\r
+        Iterator<ITimeEvent> iterator = thread.getTimeEventsIterator();\r
+        if (iterator == null) {\r
+            return null;\r
+        }\r
         ITimeEvent nextEvent = null;\r
         ITimeEvent currEvent = null;\r
         ITimeEvent prevEvent = null;\r
@@ -349,17 +327,17 @@ public class Utils {
         while (iterator.hasNext()) {\r
             nextEvent = (ITimeEvent) iterator.next();\r
             long nextStartTime = nextEvent.getTime();\r
-            \r
+\r
             if (nextStartTime > time) {\r
                 break;\r
             }\r
-            \r
+\r
             if (currEvent == null || currEvent.getTime() != nextStartTime) {\r
                 prevEvent = currEvent;\r
                 currEvent = nextEvent;\r
             }\r
         }\r
-        \r
+\r
         if (n == -1) { //previous\r
             if (currEvent != null && currEvent.getTime() + currEvent.getDuration() >= time) {\r
                 return prevEvent;\r
@@ -377,159 +355,93 @@ public class Utils {
         } else if (n == 2) { //current or previous when in empty space\r
             return currEvent;\r
         }\r
-        \r
+\r
         return null;\r
     }\r
 \r
-       // static public TRCPackage getPackage(Object element) {\r
-       // if (element instanceof TRCPackage)\r
-       // return (TRCPackage) element;\r
-       // if (element instanceof TRCClass)\r
-       // return ((TRCClass) element).getPackage();\r
-       // return null;\r
-       // }\r
-\r
-       // static public TRCObjectAllocationAnnotation getAllocationAnnotation(\r
-       // TRCClass cls) {\r
-       // TRCObjectAllocationAnnotation aa = null;\r
-       // EList list = cls.getAnnotations();\r
-       // int len = list.size();\r
-       // for (int i = 0; i < len; i++) {\r
-       // TRCAnnotation annotation = (TRCAnnotation) list.get(i);\r
-       // if (annotation instanceof TRCObjectAllocationAnnotation)\r
-       // aa = (TRCObjectAllocationAnnotation) annotation;\r
-       // }\r
-       // return aa;\r
-       // }\r
-\r
-       static public String fixMethodSignature(String sig) {\r
-               int pos = sig.indexOf('(');\r
-               if (pos >= 0) {\r
-                       String ret = sig.substring(0, pos);\r
-                       sig = sig.substring(pos);\r
-                       sig = sig + " " + ret; //$NON-NLS-1$\r
-               }\r
-               return sig;\r
-       }\r
-\r
-       static public String restoreMethodSignature(String sig) {\r
-               String ret = ""; //$NON-NLS-1$\r
-               int pos = sig.indexOf('(');\r
-               if (pos >= 0) {\r
-                       ret = sig.substring(0, pos);\r
-                       sig = sig.substring(pos + 1);\r
-               }\r
-               pos = sig.indexOf(')');\r
-               if (pos >= 0) {\r
-                       sig = sig.substring(0, pos);\r
-               }\r
-               String args[] = sig.split(","); //$NON-NLS-1$\r
+    static public String fixMethodSignature(String sig) {\r
+        int pos = sig.indexOf('(');\r
+        if (pos >= 0) {\r
+            String ret = sig.substring(0, pos);\r
+            sig = sig.substring(pos);\r
+            sig = sig + " " + ret; //$NON-NLS-1$\r
+        }\r
+        return sig;\r
+    }\r
+\r
+    static public String restoreMethodSignature(String sig) {\r
+        String ret = ""; //$NON-NLS-1$\r
+        int pos = sig.indexOf('(');\r
+        if (pos >= 0) {\r
+            ret = sig.substring(0, pos);\r
+            sig = sig.substring(pos + 1);\r
+        }\r
+        pos = sig.indexOf(')');\r
+        if (pos >= 0) {\r
+            sig = sig.substring(0, pos);\r
+        }\r
+        String args[] = sig.split(","); //$NON-NLS-1$\r
         StringBuffer result = new StringBuffer("("); //$NON-NLS-1$\r
-               for (int i = 0; i < args.length; i++) {\r
-                       String arg = args[i].trim();\r
-                       if (arg.length() == 0 && args.length == 1)\r
-                               break;\r
-                       result.append(getTypeSignature(arg));\r
-               }\r
-               result.append(")").append(getTypeSignature(ret)); //$NON-NLS-1$\r
-               return result.toString();\r
-       }\r
-\r
-       static public String getTypeSignature(String type) {\r
-               int dim = 0;\r
-               for (int j = 0; j < type.length(); j++) {\r
-                       if (type.charAt(j) == '[')\r
-                               dim++;\r
-               }\r
-               int pos = type.indexOf('[');\r
-               if (pos >= 0)\r
-                       type = type.substring(0, pos);\r
-               StringBuffer sig = new StringBuffer(""); //$NON-NLS-1$\r
-               for (int j = 0; j < dim; j++)\r
-                       sig.append("[");                 //$NON-NLS-1$\r
-               if (type.equals("boolean"))     //$NON-NLS-1$\r
-                       sig.append("Z");                 //$NON-NLS-1$\r
-               else if (type.equals("byte"))   //$NON-NLS-1$\r
-                       sig.append("B");                 //$NON-NLS-1$\r
-               else if (type.equals("char"))   //$NON-NLS-1$\r
-                       sig.append("C");                 //$NON-NLS-1$\r
-               else if (type.equals("short"))  //$NON-NLS-1$\r
-                       sig.append("S");                 //$NON-NLS-1$\r
-               else if (type.equals("int"))    //$NON-NLS-1$\r
-                       sig.append("I");                 //$NON-NLS-1$\r
-               else if (type.equals("long"))   //$NON-NLS-1$\r
-                       sig.append("J");                 //$NON-NLS-1$\r
-               else if (type.equals("float"))  //$NON-NLS-1$\r
-                       sig.append("F");                 //$NON-NLS-1$\r
-               else if (type.equals("double")) //$NON-NLS-1$\r
-                       sig.append("D");                 //$NON-NLS-1$\r
-               else if (type.equals("void"))   //$NON-NLS-1$\r
-                       sig.append("V");                 //$NON-NLS-1$\r
-               else\r
-                       sig.append("L").append(type.replace('.', '/')).append(";"); //$NON-NLS-1$ //$NON-NLS-2$\r
-               return sig.toString();\r
-       }\r
-\r
-       // static public boolean openSource(Object element) {\r
-       // if (element instanceof String) {\r
-       // final String pattern = (String) element;\r
-       // final int javaType = IJavaSearchConstants.METHOD;\r
-       // BusyIndicator.showWhile(Display.getDefault(), new Runnable() {\r
-       // public void run() {\r
-       // if (!OpenJavaSource.openSource(pattern, javaType,\r
-       // SearchEngine.createWorkspaceScope(), true)) {\r
-       // MessageDialog.openInformation(UIPlugin.getDefault()\r
-       // .getWorkbench().getActiveWorkbenchWindow()\r
-       // .getShell(), TraceMessages.TRC_MSGT, NLS.bind(\r
-       // TraceUIMessages._68, pattern));\r
-       // }\r
-       // }\r
-       // });\r
-       // }\r
-       // OpenSource.openSource(element);\r
-       // return true;\r
-       // }\r
-\r
-       // static public int getObjAge(TRCFullTraceObject obj, EList listGC) {\r
-       // int age = 0;\r
-       // double t0 = obj.getCreateTime();\r
-       // double t1 = obj.getCollectTime();\r
-       // int len = listGC.size();\r
-       // for (int j = 0; j < len; j++) {\r
-       // TRCGCEvent gcEvent = (TRCGCEvent) listGC.get(j);\r
-       // if (gcEvent.getType().equals("finish")) {\r
-       // double time = gcEvent.getTime();\r
-       // if (time <= t0)\r
-       // continue;\r
-       // if (t1 > 0 && time >= t1)\r
-       // break;\r
-       // age++;\r
-       // }\r
-       // }\r
-       // return age;\r
-       // }\r
-\r
-       static public int compare(double d1, double d2) {\r
-               if (d1 > d2)\r
-                       return 1;\r
-               if (d1 < d2)\r
-                       return 1;\r
-               return 0;\r
-       }\r
-\r
-       static public int compare(String s1, String s2) {\r
-               if (s1 != null && s2 != null)\r
-                       return s1.compareToIgnoreCase(s2);\r
-               if (s1 != null)\r
-                       return 1;\r
-               if (s2 != null)\r
-                       return -1;\r
-               return 0;\r
-       }\r
-\r
-       // static public String formatPercent(int val, int max) {\r
-       // String s = max > 0 && max >= val ? TString\r
-       // .formatAsPercentage((double) val / (double) max) : "";\r
-       // return s;\r
-       // }\r
+        for (int i = 0; i < args.length; i++) {\r
+            String arg = args[i].trim();\r
+            if (arg.length() == 0 && args.length == 1)\r
+                break;\r
+            result.append(getTypeSignature(arg));\r
+        }\r
+        result.append(")").append(getTypeSignature(ret)); //$NON-NLS-1$\r
+        return result.toString();\r
+    }\r
+\r
+    static public String getTypeSignature(String type) {\r
+        int dim = 0;\r
+        for (int j = 0; j < type.length(); j++) {\r
+            if (type.charAt(j) == '[')\r
+                dim++;\r
+        }\r
+        int pos = type.indexOf('[');\r
+        if (pos >= 0)\r
+            type = type.substring(0, pos);\r
+        StringBuffer sig = new StringBuffer(""); //$NON-NLS-1$\r
+        for (int j = 0; j < dim; j++)\r
+            sig.append("[");                 //$NON-NLS-1$\r
+        if (type.equals("boolean"))     //$NON-NLS-1$\r
+            sig.append("Z");                 //$NON-NLS-1$\r
+        else if (type.equals("byte"))   //$NON-NLS-1$\r
+            sig.append("B");                 //$NON-NLS-1$\r
+        else if (type.equals("char"))   //$NON-NLS-1$\r
+            sig.append("C");                 //$NON-NLS-1$\r
+        else if (type.equals("short"))  //$NON-NLS-1$\r
+            sig.append("S");                 //$NON-NLS-1$\r
+        else if (type.equals("int"))    //$NON-NLS-1$\r
+            sig.append("I");                 //$NON-NLS-1$\r
+        else if (type.equals("long"))   //$NON-NLS-1$\r
+            sig.append("J");                 //$NON-NLS-1$\r
+        else if (type.equals("float"))  //$NON-NLS-1$\r
+            sig.append("F");                 //$NON-NLS-1$\r
+        else if (type.equals("double")) //$NON-NLS-1$\r
+            sig.append("D");                 //$NON-NLS-1$\r
+        else if (type.equals("void"))   //$NON-NLS-1$\r
+            sig.append("V");                 //$NON-NLS-1$\r
+        else\r
+            sig.append("L").append(type.replace('.', '/')).append(";"); //$NON-NLS-1$ //$NON-NLS-2$\r
+        return sig.toString();\r
+    }\r
+\r
+    static public int compare(double d1, double d2) {\r
+        if (d1 > d2)\r
+            return 1;\r
+        if (d1 < d2)\r
+            return 1;\r
+        return 0;\r
+    }\r
+\r
+    static public int compare(String s1, String s2) {\r
+        if (s1 != null && s2 != null)\r
+            return s1.compareToIgnoreCase(s2);\r
+        if (s1 != null)\r
+            return 1;\r
+        if (s2 != null)\r
+            return -1;\r
+        return 0;\r
+    }\r
 }\r
This page took 0.036901 seconds and 5 git commands to generate.