mahout-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From isa...@apache.org
Subject svn commit: r816588 - /lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java
Date Fri, 18 Sep 2009 11:37:10 GMT
Author: isabel
Date: Fri Sep 18 11:37:10 2009
New Revision: 816588

URL: http://svn.apache.org/viewvc?rev=816588&view=rev
Log:
MAHOUT-134 - consistant cluster decode error handling.

Modified:
    lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java

Modified: lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java
URL: http://svn.apache.org/viewvc/lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java?rev=816588&r1=816587&r2=816588&view=diff
==============================================================================
--- lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java
(original)
+++ lucene/mahout/trunk/core/src/main/java/org/apache/mahout/clustering/kmeans/Cluster.java
Fri Sep 18 11:37:10 2009
@@ -33,8 +33,8 @@
 
 public class Cluster extends ClusterBase implements Writable {
 
-  private static final String ERROR_UNKNOWN_CLUSTER_FORMAT = "Unknown cluster format:\n";
-
+  private static final String ERROR_UNKNOWN_CLUSTER_FORMAT="Unknown cluster format:\n";
+    
   public static final String DISTANCE_MEASURE_KEY = "org.apache.mahout.clustering.kmeans.measure";
 
   public static final String CLUSTER_PATH_KEY = "org.apache.mahout.clustering.kmeans.path";
@@ -85,22 +85,26 @@
    * @throws IllegalArgumentException when the string is wrongly formatted
    */
   public static Cluster decodeCluster(String formattedString) {
-    int beginIndex = formattedString.indexOf('{');
-    String id = formattedString.substring(0, beginIndex);
-    String center = formattedString.substring(beginIndex);
-    char firstChar = id.charAt(0);
-    boolean startsWithV = firstChar == 'V';
-    if (firstChar == 'C' || startsWithV) {
-      int clusterId = Integer.parseInt(formattedString.substring(1,
-          beginIndex - 2));
-      Vector clusterCenter = AbstractVector.decodeVector(center);
-      Cluster cluster = new Cluster(clusterCenter, clusterId);
-      cluster.converged = startsWithV;
-      return cluster;
+    final int beginIndex = formattedString.indexOf('{');
+    final Cluster cluster;
+    if (beginIndex <= 0) {
+      throw new IllegalArgumentException(ERROR_UNKNOWN_CLUSTER_FORMAT + formattedString);
     } else {
-      throw new IllegalArgumentException(ERROR_UNKNOWN_CLUSTER_FORMAT
-          + formattedString);
+      final String id = formattedString.substring(0, beginIndex);
+      final String center = formattedString.substring(beginIndex);
+      final char firstChar = id.charAt(0);
+      final boolean startsWithV = firstChar == 'V';
+      if (firstChar == 'C' || startsWithV) {
+        final int clusterId = Integer.parseInt(formattedString.substring(1,
+          beginIndex - 2));
+        final Vector clusterCenter = AbstractVector.decodeVector(center);
+        cluster = new Cluster(clusterCenter, clusterId);
+        cluster.converged = startsWithV;
+      } else {
+       throw new IllegalArgumentException(ERROR_UNKNOWN_CLUSTER_FORMAT + formattedString);
+      }
     }
+    return cluster;
   }
 
 



Mime
View raw message