code: public synchronized int addColumn(Vector 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();
  
          // Vector instances can take on the maximum possible array size when the
          // vector length isn't specified.  This ruins the matrix size
          // specification since the matrix shouldn't actually be that big.
          // However, because this is an implementation artifact, we can't check
          // for it explicitly with an exception.  Therefore, put in an assert to
          // indicate what is likely going on if asserts are enabled for debugging
          // they symptoms.
          assert row.length() != Integer.MAX_VALUE : "adding a column whose " +
              "length is Integer.MAX_VALUE (was likley left unspecified in the " +
              " constructor).";
  
          // Special case for sparse Vectors, for which we already know the
          // non-zero indices for the column
          if (row instanceof SparseVector) {
              SparseVector s = (SparseVector)row;
              int[] nonZero = s.getNonZeroIndices();
              nonZeroValues += nonZero.length;
              StringBuilder sb = new StringBuilder();
              for (int i : nonZero) {
                  sb.append(i+1).append(" ");
                  sb.append(row.getValue(i).doubleValue()).append(" ");
              }
              writer.println(sb.toString());
          }
          // For dense Vectors, find which values are non-zero and write only
          // those
          else {
              int nonZero = 0;
              StringBuilder sb = new StringBuilder();
              for (int i = 0; i < row.length(); ++i) {
                  double d = row.getValue(i).doubleValue();
                  if (d != 0d) {
                      sb.append(i+1).append(" ").append(d).append(" ");
                      nonZero++;                    
                  }
              }
              writer.println(sb.toString());
  
              // Update the matrix count
              nonZeroValues += nonZero;
          }
          return ++curRow;
      }
docs: {@inheritDoc}