Revision: 956
Author: allain.lalonde
Date: Tue Jan 26 07:04:07 2010
Log: Adding stragler Measurements class
http://code.google.com/p/piccolo2d/source/detail?r=956

Added:
/piccolo2d.java/branches/2.0-spike/core/src/test/java/org/piccolo2d/Measurements.java
Modified:
/piccolo2d.java/branches/2.0-spike/parent/.settings/org.eclipse.jdt.core.prefs /piccolo2d.java/branches/2.0-spike/swt/src/main/java/org/piccolo2d/swt/PSWTBoundsHandle.java /piccolo2d.java/branches/2.0-spike/swt/src/main/java/org/piccolo2d/swt/PSWTText.java /piccolo2d.java/branches/2.0-spike/swt/src/main/java/org/piccolo2d/swt/SWTShapeManager.java

=======================================
--- /dev/null
+++ /piccolo2d.java/branches/2.0-spike/core/src/test/java/org/piccolo2d/Measurements.java Tue Jan 26 07:04:07 2010
@@ -0,0 +1,103 @@
+package org.piccolo2d;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+public class Measurements {
+ private Map<String, List<Long>> measurements = new HashMap<String, List<Long>>();
+
+    public void time(String name, Runnable runnable) {
+        if (!measurements.containsKey(name)) {
+            measurements.put(name, new LinkedList<Long>());
+        }
+
+        long startTime = System.currentTimeMillis();
+        runnable.run();
+        long endTime = System.currentTimeMillis();
+
+        measurements.get(name).add(endTime - startTime);
+    }
+
+    public void memory(String name, Runnable runnable) {
+        if (!measurements.containsKey(name)) {
+            measurements.put(name, new LinkedList<Long>());
+        }
+
+        Runtime.getRuntime().gc();
+        final long startTotalMemory = Runtime.getRuntime().totalMemory();
+        final long startFree = Runtime.getRuntime().freeMemory();
+
+        runnable.run();
+
+        Runtime.getRuntime().gc();
+        final long endFree = Runtime.getRuntime().freeMemory();
+        final long endTotal = Runtime.getRuntime().totalMemory();
+
+ final long memoryUsed = ((endTotal - startTotalMemory + startFree - endFree) / 1024);
+        measurements.get(name).add(memoryUsed);
+    }
+
+    public void writeLog() {
+        System.out.println("name,average,min,max");
+        for (Entry<String, List<Long>> entry : measurements.entrySet()) {
+            System.out.print('"');
+            System.out.print(entry.getKey());
+            System.out.print('"');
+            System.out.print(", ");
+            System.out.print(calculateAverage(entry.getValue()));
+            System.out.print(", ");
+            System.out.print(calculateMinimum(entry.getValue()));
+            System.out.print(", ");
+            System.out.print(calculateMaximum(entry.getValue()));
+            System.out.println();
+        }
+
+        System.out.println();
+        System.out.println("Raw Data");
+        System.out.println("name, run, value");
+        for (Entry<String, List<Long>> entry : measurements.entrySet()) {
+            int runCount = 0;
+            for (long value : entry.getValue()) {
+                System.out.print('"');
+                System.out.print(entry.getKey());
+                System.out.print('"');
+                System.out.print(", ");
+                System.out.print(++runCount);
+                System.out.print(", ");
+                System.out.println(value);
+            }
+        }
+    }
+
+    private long calculateAverage(List<Long> measurements) {
+        long total = 0;
+
+        for (Long measurement : measurements)
+            total += measurement;
+
+        return total / measurements.size();
+    }
+
+    private long calculateMinimum(List<Long> measurements) {
+        long min = measurements.get(0);
+
+        for (Long measurement : measurements)
+            if (min > measurement)
+                min = measurement;
+
+        return min;
+    }
+
+    private long calculateMaximum(List<Long> measurements) {
+        long max = measurements.get(0);
+
+        for (Long measurement : measurements)
+            if (max < measurement)
+                max = measurement;
+
+        return max;
+    }
+}
=======================================
--- /piccolo2d.java/branches/2.0-spike/parent/.settings/org.eclipse.jdt.core.prefs Wed Oct 28 07:58:59 2009 +++ /piccolo2d.java/branches/2.0-spike/parent/.settings/org.eclipse.jdt.core.prefs Tue Jan 26 07:04:07 2010
@@ -1,5 +1,12 @@
-#Wed Oct 28 10:17:01 EDT 2009
+#Tue Jan 26 09:12:03 EST 2010
 eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.4
-org.eclipse.jdt.core.compiler.compliance=1.4
-org.eclipse.jdt.core.compiler.source=1.4
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
=======================================
--- /piccolo2d.java/branches/2.0-spike/swt/src/main/java/org/piccolo2d/swt/PSWTBoundsHandle.java Tue Jan 19 12:39:24 2010 +++ /piccolo2d.java/branches/2.0-spike/swt/src/main/java/org/piccolo2d/swt/PSWTBoundsHandle.java Tue Jan 26 07:04:07 2010
@@ -130,11 +130,9 @@
      * @param node node from which to remove bounds handles
      */
     public static void removeBoundsHandlesFrom(final PNode node) {
-        final ArrayList handles = new ArrayList();
-
-        final Iterator i = node.getChildrenIterator();
-        while (i.hasNext()) {
-            final PNode each = (PNode) i.next();
+        final ArrayList<PNode> handles = new ArrayList<PNode>();
+
+        for (PNode each : node.getChildrenReference()) {
             if (each instanceof PSWTBoundsHandle) {
                 handles.add(each);
             }
=======================================
--- /piccolo2d.java/branches/2.0-spike/swt/src/main/java/org/piccolo2d/swt/PSWTText.java Thu Jan 14 13:48:07 2010 +++ /piccolo2d.java/branches/2.0-spike/swt/src/main/java/org/piccolo2d/swt/PSWTText.java Tue Jan 26 07:04:07 2010
@@ -11,7 +11,7 @@
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Point2D;
 import java.util.ArrayList;
-import java.util.Iterator;
+import java.util.List;

 import org.eclipse.swt.graphics.FontMetrics;
 import org.eclipse.swt.graphics.GC;
@@ -80,7 +80,7 @@
     protected int padding = DEFAULT_PADDING;

     /** Each element is one line of text. */
-    protected ArrayList lines = new ArrayList();
+    protected List<String> lines = new ArrayList<String>();

     /** Translation offset X. */
     protected double translateX = 0.0;
@@ -231,9 +231,8 @@
     public String getText() {
         StringBuffer result = new StringBuffer();

-        final Iterator lineIterator = lines.iterator();
-        while (lineIterator.hasNext()) {
-            result.append(lineIterator.next());
+        for (String line : lines) {
+            result.append(line);
             result.append('\n');
         }

@@ -439,14 +438,11 @@
         sg2.setColor(penColor);
         sg2.setFont(font);

-        String line;
         double y = 0;

         final FontMetrics fontMetrics = sg2.getSWTFontMetrics();

-        final Iterator lineIterator = lines.iterator();
-        while (lineIterator.hasNext()) {
-            line = (String) lineIterator.next();
+        for (String line : lines) {
             if (line.length() != 0) {
                 sg2.drawString(line, 0, y, true);
             }
@@ -484,7 +480,7 @@
      * @return true if the text is the empty string
      */
     private boolean isTextEmpty() {
- return lines.isEmpty() || lines.size() == 1 && ((String) lines.get(0)).equals(""); + return lines.isEmpty() || lines.size() == 1 && "".equals(lines.get(0));
     }

     /**
@@ -502,9 +498,7 @@

         boolean firstLine = true;

-        final Iterator lineIterator = lines.iterator();
-        while (lineIterator.hasNext()) {
-            String line = (String) lineIterator.next();
+        for (String line : lines) {
             Point lineBounds = gc.stringExtent(line);
             if (firstLine) {
                 textBounds.x = lineBounds.x;
=======================================
--- /piccolo2d.java/branches/2.0-spike/swt/src/main/java/org/piccolo2d/swt/SWTShapeManager.java Tue Jan 19 13:09:08 2010 +++ /piccolo2d.java/branches/2.0-spike/swt/src/main/java/org/piccolo2d/swt/SWTShapeManager.java Tue Jan 26 07:04:07 2010
@@ -34,6 +34,7 @@
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
 import java.util.ArrayList;
+import java.util.List;

 import org.eclipse.swt.graphics.Rectangle;

@@ -45,7 +46,7 @@
 public class SWTShapeManager {
private static final AffineTransform IDENTITY_XFORM = new AffineTransform();
     private static final Point2D aPoint = new Point2D.Double();
-    private static final ArrayList segList = new ArrayList();
+    private static final List<Point2D> segList = new ArrayList<Point2D>();
     private static final double[] pts = new double[8];

     /**
@@ -137,7 +138,7 @@

         final double[] polyObj = new double[2 * segList.size()];
         for (int i = 0; i < segList.size(); i++) {
-            final Point2D p2 = (Point2D) segList.get(i);
+            final Point2D p2 = segList.get(i);
             polyObj[2 * i] = (int) (p2.getX() + 0.5);
             polyObj[2 * i + 1] = (int) (p2.getY() + 0.5);
         }

--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en

Reply via email to