For POI internal use only @author Josh Micich
| 32 | * @author Josh Micich |
| 33 | */ |
| 34 | @Internal |
| 35 | public final class SSCellRange<K extends Cell> implements CellRange<K> { |
| 36 | |
| 37 | private final int _height; |
| 38 | private final int _width; |
| 39 | private final K[] _flattenedArray; |
| 40 | private final int _firstRow; |
| 41 | private final int _firstColumn; |
| 42 | |
| 43 | private SSCellRange(int firstRow, int firstColumn, int height, int width, K[] flattenedArray) { |
| 44 | _firstRow = firstRow; |
| 45 | _firstColumn = firstColumn; |
| 46 | _height = height; |
| 47 | _width = width; |
| 48 | _flattenedArray = flattenedArray; |
| 49 | } |
| 50 | |
| 51 | public static <B extends Cell> SSCellRange<B> create(int firstRow, int firstColumn, int height, int width, List<B> flattenedList, Class<B> cellClass) { |
| 52 | int nItems = flattenedList.size(); |
| 53 | if (height * width != nItems) { |
| 54 | throw new IllegalArgumentException("Array size mismatch."); |
| 55 | } |
| 56 | |
| 57 | @SuppressWarnings("unchecked") |
| 58 | B[] flattenedArray = (B[]) Array.newInstance(cellClass, nItems); |
| 59 | flattenedList.toArray(flattenedArray); |
| 60 | return new SSCellRange<B>(firstRow, firstColumn, height, width, flattenedArray); |
| 61 | } |
| 62 | |
| 63 | public int getHeight() { |
| 64 | return _height; |
| 65 | } |
| 66 | public int getWidth() { |
| 67 | return _width; |
| 68 | } |
| 69 | public int size() { |
| 70 | return _height*_width; |
| 71 | } |
| 72 | |
| 73 | public String getReferenceText() { |
| 74 | CellRangeAddress cra = new CellRangeAddress(_firstRow, _firstRow+_height-1, _firstColumn, _firstColumn+_width-1); |
| 75 | return cra.formatAsString(); |
| 76 | } |
| 77 | |
| 78 | public K getTopLeftCell() { |
| 79 | return _flattenedArray[0]; |
| 80 | } |
| 81 | |
| 82 | public K getCell(int relativeRowIndex, int relativeColumnIndex) { |
| 83 | if (relativeRowIndex < 0 || relativeRowIndex >= _height) { |
| 84 | throw new ArrayIndexOutOfBoundsException("Specified row " + relativeRowIndex |
| 85 | + " is outside the allowable range (0.." + (_height-1) + ")."); |
| 86 | } |
| 87 | if (relativeColumnIndex < 0 || relativeColumnIndex >= _width) { |
| 88 | throw new ArrayIndexOutOfBoundsException("Specified colummn " + relativeColumnIndex |
| 89 | + " is outside the allowable range (0.." + (_width-1) + ")."); |
| 90 | } |
| 91 | int flatIndex = _width * relativeRowIndex + relativeColumnIndex; |
nothing calls this directly
no outgoing calls
no test coverage detected