SparseMatrix extends AbstractMatrix { @Override public void add(int i, int j, double value) { checkBounds(i, j); boolean startNewColumn = false; if (j == currentColumn) { } else if (j > currentColumn) { columnStart[j] = values.size(); currentColumn = j; startNewColumn = true; } else { throw new PowsyblException("Columns have to be filled in the right order"); } if (!startNewColumn && i == rowIndices.get(rowIndices.size() - 1)) { int vi = values.size() - 1; values.setQuick(vi, values.getQuick(vi) + value); } else { values.add(value); rowIndices.add(i); columnStart[columnStart.length - 1] = values.size(); columnValueCount[j]++; } } SparseMatrix(int rowCount, int columnCount, int[] columnStart, int[] rowIndices, double[] values);   SparseMatrix(int rowCount, int columnCount, int estimatedNonZeroValueCount); @Override int getRowCount(); @Override int getColumnCount(); @Override void set(int i, int j, double value); @Override void add(int i, int j, double value); @Override Element addAndGetElement(int i, int j, double value); @Override void reset(); @Override LUDecomposition decomposeLU(); @Override Matrix times(Matrix other); @Override void iterateNonZeroValue(ElementHandler handler); @Override void iterateNonZeroValueOfColumn(int j, ElementHandler handler); @Override DenseMatrix toDense(); @Override SparseMatrix toSparse(); @Override Matrix to(MatrixFactory factory); @Override void print(PrintStream out); @Override void print(PrintStream out, List<String> rowNames, List<String> columnNames); @Override int hashCode(); @Override boolean equals(Object obj);  }
@Test(expected = PowsyblException.class) public void testWrongColumnOrderWithAdd() { Matrix a = matrixFactory.create(2, 2, 2); a.add(0, 0, 1d); a.add(1, 0, 1d); a.add(0, 1, 1d); a.add(1, 0, 1d); }