@Test public void checkBoundsTest() { try { getMatrixFactory().create(-1, 1, 1); fail(); } catch (IllegalArgumentException ignored) { } try { getMatrixFactory().create(1, -1, 1); fail(); } catch (IllegalArgumentException ignored) { } Matrix a = getMatrixFactory().create(1, 1, 1); try { a.set(-1, 0, 0); fail(); } catch (IllegalArgumentException ignored) { } try { a.set(0, -1, 0); fail(); } catch (IllegalArgumentException ignored) { } try { a.set(2, 0, 0); fail(); } catch (IllegalArgumentException ignored) { } try { a.set(0, 1, 0); fail(); } catch (IllegalArgumentException ignored) { } try { a.add(2, 0, 0); fail(); } catch (IllegalArgumentException ignored) { } try { a.add(0, 1, 0); fail(); } catch (IllegalArgumentException ignored) { } }
protected void checkBounds(int i, int j) { if (i < 0 || i >= getRowCount()) { throw new IllegalArgumentException("Row index out of bound [0, " + (getRowCount() - 1) + "]"); } if (j < 0 || j >= getColumnCount()) { throw new IllegalArgumentException("Column index out of bound [0, " + (getColumnCount() - 1) + "]"); } }
AbstractMatrix implements Matrix { protected void checkBounds(int i, int j) { if (i < 0 || i >= getRowCount()) { throw new IllegalArgumentException("Row index out of bound [0, " + (getRowCount() - 1) + "]"); } if (j < 0 || j >= getColumnCount()) { throw new IllegalArgumentException("Column index out of bound [0, " + (getColumnCount() - 1) + "]"); } } }
AbstractMatrix implements Matrix { protected void checkBounds(int i, int j) { if (i < 0 || i >= getRowCount()) { throw new IllegalArgumentException("Row index out of bound [0, " + (getRowCount() - 1) + "]"); } if (j < 0 || j >= getColumnCount()) { throw new IllegalArgumentException("Column index out of bound [0, " + (getColumnCount() - 1) + "]"); } }  }
AbstractMatrix implements Matrix { protected void checkBounds(int i, int j) { if (i < 0 || i >= getRowCount()) { throw new IllegalArgumentException("Row index out of bound [0, " + (getRowCount() - 1) + "]"); } if (j < 0 || j >= getColumnCount()) { throw new IllegalArgumentException("Column index out of bound [0, " + (getColumnCount() - 1) + "]"); } }  @Override Matrix copy(MatrixFactory factory); }
AbstractMatrix implements Matrix { protected void checkBounds(int i, int j) { if (i < 0 || i >= getRowCount()) { throw new IllegalArgumentException("Row index out of bound [0, " + (getRowCount() - 1) + "]"); } if (j < 0 || j >= getColumnCount()) { throw new IllegalArgumentException("Column index out of bound [0, " + (getColumnCount() - 1) + "]"); } }  @Override Matrix copy(MatrixFactory factory);  }