MatrixView extends AbstractMatrix { @Override public Matrix viewPart(int[] offset, int[] size) { if (offset[ROW] < ROW) { throw new IndexException(offset[ROW], ROW); } if (offset[ROW] + size[ROW] > rowSize()) { throw new IndexException(offset[ROW] + size[ROW], rowSize()); } if (offset[COL] < ROW) { throw new IndexException(offset[COL], ROW); } if (offset[COL] + size[COL] > columnSize()) { throw new IndexException(offset[COL] + size[COL], columnSize()); } int[] origin = offset.clone(); origin[ROW] += offset[ROW]; origin[COL] += offset[COL]; return new MatrixView(matrix, origin, size); } private  MatrixView();  MatrixView(Matrix matrix, int[] offset, int[] size); @Override Matrix clone(); @Override double getQuick(int row, int column); @Override Matrix like(); @Override Matrix like(int rows, int columns); @Override void setQuick(int row, int column, double value); @Override int[] getNumNondefaultElements(); @Override Matrix viewPart(int[] offset, int[] size); @Override Matrix assignColumn(int column, Vector other); @Override Matrix assignRow(int row, Vector other); @Override Vector getColumn(int column); @Override Vector getRow(int row);  }
@Test public void testViewPart() { int[] offset = {1, 1}; int[] size = {2, 1}; Matrix view = test.viewPart(offset, size); int[] c = view.size(); for (int row = 0; row < c[ROW]; row++) { for (int col = 0; col < c[COL]; col++) { assertEquals("value[" + row + "][" + col + ']', values[row + 2][col + 2], view.getQuick(row, col), EPSILON); } } }
@Test(expected = IndexException.class) public void testViewPartCardinality() { int[] offset = {1, 1}; int[] size = {3, 3}; test.viewPart(offset, size); }
@Test(expected = IndexException.class) public void testViewPartIndexOver() { int[] offset = {1, 1}; int[] size = {2, 2}; test.viewPart(offset, size); }
@Test(expected = IndexException.class) public void testViewPartIndexUnder() { int[] offset = {-1, -1}; int[] size = {2, 2}; test.viewPart(offset, size); }