mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sro...@apache.org
Subject svn commit: r1149115 - /mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java
Date Thu, 21 Jul 2011 11:07:10 GMT
Author: srowen
Date: Thu Jul 21 11:07:10 2011
New Revision: 1149115

URL: http://svn.apache.org/viewvc?rev=1149115&view=rev
Log:
Fix toString() for empty vector

Modified:
    mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java?rev=1149115&r1=1149114&r2=1149115&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/RandomAccessSparseVector.java Thu
Jul 21 11:07:10 2011
@@ -81,16 +81,19 @@ public class RandomAccessSparseVector ex
     StringBuilder result = new StringBuilder();
     result.append('{');
     Iterator<Element> it = iterateNonZero();
+    boolean first = true;
     while (it.hasNext()) {
+      if (first) {
+        first = false;
+      } else {
+        result.append(',');
+      }
       Element e = it.next();
       result.append(e.index());
       result.append(':');
       result.append(e.get());
-      result.append(',');
-    }
-    if (result.length() > 1) {
-      result.setCharAt(result.length() - 1, '}');
     }
+    result.append('}');
     return result.toString();
   }
 



Mime
View raw message