1 11 package org.eclipse.test.internal.performance.db; 12 13 import java.io.PrintStream ; 14 import java.util.HashMap ; 15 16 public class Report { 17 18 private static final String LEFT= "l"; private static final String RIGHT= "r"; 21 private int fGap; 22 private int fColumn; 23 private int fRow; 24 private int fRows; 25 private HashMap fContent= new HashMap (); 26 private HashMap fWidths= new HashMap (); 27 private HashMap fAlignment= new HashMap (); 28 29 public Report(int gap) { 30 fGap= gap; 31 } 32 33 public void addCell(String value) { 34 setCell(fColumn, fRow, value, LEFT); 35 fColumn++; 36 } 37 38 public void addCellRight(String value) { 39 setCell(fColumn, fRow, value, RIGHT); 40 fColumn++; 41 } 42 43 public void nextRow() { 44 fRow++; 45 fColumn= 0; 46 } 47 48 private void setCell(int x, int y, String value, String align) { 49 fContent.put(x + "/" + y, value); fAlignment.put(x + "/" + y, align); Integer w= (Integer ) fWidths.get(Integer.toString(x)); 52 if (w == null) 53 w= new Integer (value.length()); 54 else 55 w= new Integer (Math.max(w.intValue(), value.length())); 56 fWidths.put(Integer.toString(x), w); 57 fRows= Math.max(fRows, y+1); 58 } 59 60 private String getCell(int x, int y) { 61 return (String ) fContent.get(x + "/" + y); } 63 64 public void print(PrintStream ps) { 65 int n= fWidths.size(); 66 for (int y= 0; y < fRows; y++) { 67 for (int x= 0; x < n; x++) { 68 Integer w= (Integer ) fWidths.get(Integer.toString(x)); 69 int ww= w.intValue(); 70 String s= getCell(x, y); 71 if (s == null) 72 s= ""; 74 if (x > 0) 75 for (int g= 0; g < fGap; g++) 76 ps.print(' '); 77 78 int www= ww-s.length(); 79 String align= (String ) fAlignment.get(x + "/" + y); if (LEFT.equalsIgnoreCase(align)) 81 ps.print(s); 82 for (int l= 0; l < www; l++) 83 ps.print(' '); 84 if (RIGHT.equalsIgnoreCase(align)) 85 ps.print(s); 86 } 87 ps.println(); 88 } 89 } 90 } 91 | Popular Tags |