1 17 18 package org.objectweb.jac.util; 19 20 import java.util.Vector ; 21 import org.apache.log4j.Logger; 22 import java.util.List ; 23 24 29 public class Matrix { 30 Logger logger = Logger.getLogger("matrix"); 31 32 public Matrix() { 33 rowCount = 0; 34 columnCount = 0; 35 } 36 37 public Matrix(int cCount, int rCount) { 38 allocate(cCount,rCount); 39 } 40 41 48 public void allocate(int cCount, int rCount) { 49 logger.debug("allocate("+cCount+","+rCount+")"); 50 this.columnCount = cCount; 51 this.rowCount = rCount; 52 Vector cols = new Vector (cCount); 53 cols.setSize(cCount); 54 for (int i=0; i<cCount; i++) { 55 Vector col = new Vector (rCount); 56 col.setSize(rCount); 57 cols.set(i, col); 58 } 59 this.cols = cols; 60 } 61 62 69 public void set(int i, int j, Object value) 70 throws IndexOutOfBoundsException 71 { 72 checkBounds(i, j); 73 ((Vector )cols.get(i)).set(j,value); 74 } 75 76 83 public Object get(int i, int j) throws IndexOutOfBoundsException { 84 checkBounds(i, j); 85 return ((Vector ) cols.get(i)).get(j); 86 } 87 88 void checkBounds(int i, int j) throws IndexOutOfBoundsException { 89 if (i >= columnCount) { 90 throw new IndexOutOfBoundsException ( 91 "Column index out of bound for "+this+": "+ 92 i + " >= " + columnCount); 93 } 94 if (j >= rowCount) { 95 throw new IndexOutOfBoundsException ( 96 "Row index out of bound for "+this+": "+ 97 j + " >= " + rowCount); 98 } 99 } 100 101 List cols; 102 103 int rowCount; 104 105 108 public int getRowCount() { 109 return rowCount; 110 } 111 112 int columnCount; 113 114 117 public int getColumnCount() { 118 return columnCount; 119 } 120 } 121 | Popular Tags |