private static void addElement(ArrayList<ArrayList<Integer>> rowIndexes, ArrayList<ArrayList<String>> colIndexes, ArrayList<Double> values,
	    ArrayList<Double> diag, int row, int col, double value) throws NumberFormatException {
	boolean positionOcupied = false;
	if (row == col) {
	    Double diagElem = diag.get(col);
	    if (diagElem != 0.0) {
		diagElem += value;
	    } else {
		diagElem = value;
	    }
	    diag.set(row, diagElem);
	} else {
	    ArrayList<Integer> rowInRowIndexes = rowIndexes.get(row);
	    if (rowInRowIndexes.contains(col)) {
		positionOcupied = true;
	    } else {
		rowInRowIndexes.add(col);
	    }
	    if (!positionOcupied) {
		colIndexes.get(col).add(values.size() + "|" + row);
		values.add(value);
	    } else {
		ArrayList<String> rowInColIndexes = colIndexes.get(col);
		for (String line : rowInColIndexes) {
		    if (line.endsWith("|" + row)) {
			String[] splitLine = line.split("\\|");
			int indexOfElemInValues = Integer.parseInt(splitLine[0]);
			double newValue = values.get(indexOfElemInValues);
			newValue += value;
			values.set(indexOfElemInValues, newValue);
		    }
		}
	    }
	}
    }