code: public synchronized int addColumn(double[] row) {
          if (isFinished)
              throw new IllegalStateException(
                  "Cannot add columns to a MatrixBuilder that is finished");
  
          // Update the size of the matrix based on the size of the array
          if (row.length > numCols)
              numCols = row.length;
  
          // Write the row to file
          int nonZero = 0;
          StringBuilder sb = new StringBuilder();
          for (int i = 0; i < row.length; ++i) {
              if (row[i] != 0d) {
                  sb.append(i+1).append(" ").append(row[i]).append(" ");
                  nonZero++;
              }
          }
          writer.println(sb.toString());
  
          // Update the total number of non-zero values for the entire matrix
          nonZeroValues += nonZero;
  
          return ++curRow;
      }
docs: {@inheritDoc}