1 package com.calipso.reportgenerator.reportcalculator; 2 3 import java.util.*; 4 import java.io.Serializable ; 5 6 import com.calipso.reportgenerator.common.InfoException; 7 8 11 public class CollectionMatrix implements Matrix, Serializable { 12 13 private List rows; 14 Vector columnNames; 15 16 public CollectionMatrix() { 17 rows = new LinkedList(); 18 } 19 20 24 private List getRows() { 25 return rows; 26 } 27 28 public void add(Object [] row) throws InfoException { 29 getRows().add(row); 30 } 31 32 public Iterator iterator() throws InfoException { 33 return getRows().iterator(); 34 } 35 36 public boolean isEmpty() { 37 return rows.isEmpty(); 38 } 39 40 public int size() { 41 return getRows().size(); 42 } 43 44 public void setColumNames(Vector columnNames) { 45 this.columnNames = columnNames; 46 } 47 48 public void addAll(Matrix sourceMatrix) throws InfoException{ 49 Iterator iterator = sourceMatrix.iterator(); 50 while(iterator.hasNext()){ 51 Object [] objects = (Object []) iterator.next(); 52 add(objects); 53 } 54 } 55 56 public int getRowCount() { 57 return rows.size(); 58 } 59 60 public int getColumCount() { 61 return columnNames.size(); 62 } 63 64 public String getColumName(int i) throws IndexOutOfBoundsException { 65 return (String )columnNames.get(i); 66 } 67 68 public void setColumName(int i, String string) throws IndexOutOfBoundsException , InfoException { 69 columnNames.set(i, string); 70 } 71 72 public Object getValueAt(int i, int i1) throws IndexOutOfBoundsException { 73 return ((Object [])rows.get(i))[i1]; 75 } 76 77 public Collection getColumValues(int i) throws IndexOutOfBoundsException { 78 throw new NoSuchMethodError (); 80 } 81 82 public Collection getRowValues(int i) throws IndexOutOfBoundsException { 83 return Arrays.asList((Object [])rows.get(i)); 85 } 86 87 public void updateValueAt(int i, int i1, Object object) throws IndexOutOfBoundsException { 88 ((Object [])rows.get(i))[i1] = object; 90 } 91 92 public void addRow(Collection collection) throws InfoException { 93 add(collection.toArray()); 94 } 95 } 96 | Popular Tags |