1 package org.apache.poi.util; 2 3 import java.util.List ; 4 import java.util.ArrayList ; 5 6 15 public class IntList2d 16 { 17 List rows = new ArrayList (); 19 20 public int get(int col, int row) 21 { 22 if (row >= rows.size()) 23 { 24 return 0; 25 } 26 else 27 { 28 IntList cols = (IntList) rows.get(row); 29 if (col >= cols.size()) 30 return 0; 31 else 32 return cols.get( col ); 33 } 34 } 35 36 public void set(int col, int row, int value) 37 { 38 resizeRows(row); 39 resizeCols(row,col); 40 IntList cols = (IntList) rows.get( row ); 41 cols.set( col, value ); 42 } 43 44 private void resizeRows( int row ) 45 { 46 while (rows.size() <= row) 47 rows.add( new IntList() ); 48 } 49 50 private void resizeCols( int row, int col ) 51 { 52 IntList cols = (IntList) rows.get( row ); 53 while (cols.size() <= col) 54 cols.add(0); 55 } 56 57 public boolean isAllocated( int col, int row ) 58 { 59 if (row < rows.size()) 60 { 61 IntList cols = (IntList) rows.get( row ); 62 return ( col < cols.size() ); 63 } 64 else 65 { 66 return false; 67 } 68 } 69 70 71 72 } 73 | Popular Tags |