1 package hudson.util; 2 3 import org.jfree.data.category.CategoryDataset; 4 import org.jfree.data.category.DefaultCategoryDataset; 5 6 import java.util.ArrayList ; 7 import java.util.List ; 8 import java.util.TreeSet ; 9 10 17 public final class DataSetBuilder<Row extends Comparable ,Column extends Comparable > { 18 19 private List <Number > values = new ArrayList <Number >(); 20 private List <Row> rows = new ArrayList <Row>(); 21 private List <Column> columns = new ArrayList <Column>(); 22 23 public void add( Number value, Row rowKey, Column columnKey ) { 24 values.add(value); 25 rows.add(rowKey); 26 columns.add(columnKey); 27 } 28 29 public CategoryDataset build() { 30 DefaultCategoryDataset ds = new DefaultCategoryDataset(); 31 32 TreeSet <Row> rowSet = new TreeSet <Row>(rows); 33 TreeSet <Column> colSet = new TreeSet <Column>(columns); 34 35 Comparable [] _rows = rowSet.toArray(new Comparable [rowSet.size()]); 36 Comparable [] _cols = colSet.toArray(new Comparable [colSet.size()]); 37 38 for (Comparable r : _rows) 40 ds.setValue(null, r, _cols[0]); 41 for (Comparable c : _cols) 42 ds.setValue(null, _rows[0], c); 43 44 for( int i=0; i<values.size(); i++ ) 45 ds.addValue( values.get(i), rows.get(i), columns.get(i) ); 46 return ds; 47 } 48 } 49 | Popular Tags |