Modified: 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/Descriptors.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/Descriptors.java?rev=1004046&r1=1004045&r2=1004046&view=diff
==============================================================================
--- 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/Descriptors.java
 (original)
+++ 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/Descriptors.java
 Sun Oct  3 20:53:07 2010
@@ -17,6 +17,8 @@
 
 package org.apache.mahout.ga.watchmaker.cd.tool;
 
+import com.google.common.base.Preconditions;
+
 /**
  * Used as a configuration Parameters for the mapper-combiner-reducer<br>
  * CDTOOL.ATTRIBUTES : char[] description of the attributes.<br>
@@ -34,18 +36,12 @@ public final class Descriptors {
   private final char[] descriptors;
   
   public Descriptors(char[] descriptors) {
-    if (!(descriptors != null && descriptors.length > 0)) {
-      throw new IllegalArgumentException();
-    }
-    
+    Preconditions.checkArgument(descriptors != null && descriptors.length > 0, 
"descriptors null or empty");
     this.descriptors = descriptors;
-    
     // check that all the descriptors are correct ('I', 'N' 'L' or 'C')
     for (int index = 0; index < descriptors.length; index++) {
-      if (!isIgnored(index) && !isNumerical(index) && !isNominal(index)) {
-        throw new IllegalArgumentException("Bad descriptor value : "
-          + descriptors[index]);
-      }
+      Preconditions.checkArgument(isIgnored(index) || isNumerical(index) || 
isNominal(index),
+          "Bad descriptor value", descriptors[index]);
     }
   }
   

Modified: 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombiner.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombiner.java?rev=1004046&r1=1004045&r2=1004046&view=diff
==============================================================================
--- 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombiner.java
 (original)
+++ 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolCombiner.java
 Sun Oct  3 20:53:07 2010
@@ -22,6 +22,7 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
 
+import com.google.common.base.Preconditions;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mapreduce.Reducer;
@@ -60,10 +61,7 @@ public class ToolCombiner extends Reduce
   }
 
   void configure(char[] descriptors) {
-    if (descriptors == null || descriptors.length == 0) {
-      throw new IllegalArgumentException("Descriptors's array not found or is 
empty");
-    }
-
+    Preconditions.checkArgument(descriptors != null && descriptors.length > 0, 
"descriptors null or empty");
     this.descriptors = new Descriptors(descriptors);
   }
 

Modified: 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolMapper.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolMapper.java?rev=1004046&r1=1004045&r2=1004046&view=diff
==============================================================================
--- 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolMapper.java
 (original)
+++ 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolMapper.java
 Sun Oct  3 20:53:07 2010
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.StringTokenizer;
 
+import com.google.common.base.Preconditions;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mapreduce.Mapper;
@@ -55,9 +56,8 @@ public class ToolMapper extends Mapper<L
   @Override
   protected void map(LongWritable key, Text value, Context context) throws 
IOException, InterruptedException {
     extractAttributes(value, attributes);
-    if (attributes.size() != descriptors.size()) {
-      throw new IllegalArgumentException("Attributes number should be equal to 
the descriptors's array length");
-    }
+    Preconditions.checkArgument(attributes.size() == descriptors.size(),
+        "Attributes number should be equal to the descriptors's array length");
 
     // output non ignored attributes
     for (int index = 0; index < attributes.size(); index++) {
@@ -80,10 +80,7 @@ public class ToolMapper extends Mapper<L
   }
 
   void configure(char[] descriptors) {
-    if (descriptors == null || descriptors.length == 0) {
-      throw new IllegalArgumentException("Descriptors's array not found or is 
empty");
-    }
-
+    Preconditions.checkArgument(descriptors != null && descriptors.length > 0, 
"descriptors null or empty");
     this.descriptors = new Descriptors(descriptors);
   }
 

Modified: 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducer.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducer.java?rev=1004046&r1=1004045&r2=1004046&view=diff
==============================================================================
--- 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducer.java
 (original)
+++ 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/cd/tool/ToolReducer.java
 Sun Oct  3 20:53:07 2010
@@ -22,6 +22,7 @@ import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
 
+import com.google.common.base.Preconditions;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
 import org.apache.hadoop.mapreduce.Reducer;
@@ -60,10 +61,7 @@ public class ToolReducer extends Reducer
   }
 
   void configure(char[] descriptors) {
-    if (descriptors == null || descriptors.length == 0) {
-      throw new IllegalArgumentException("Descriptors's array not found or is 
empty");
-    }
-
+    Preconditions.checkArgument(descriptors != null && descriptors.length > 0, 
"descriptors null or empty");
     this.descriptors = new Descriptors(descriptors);
   }
 

Modified: 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/travellingsalesman/EvolutionaryTravellingSalesman.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/travellingsalesman/EvolutionaryTravellingSalesman.java?rev=1004046&r1=1004045&r2=1004046&view=diff
==============================================================================
--- 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/travellingsalesman/EvolutionaryTravellingSalesman.java
 (original)
+++ 
mahout/trunk/examples/src/main/java/org/apache/mahout/ga/watchmaker/travellingsalesman/EvolutionaryTravellingSalesman.java
 Sun Oct  3 20:53:07 2010
@@ -23,6 +23,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Random;
 
+import com.google.common.base.Preconditions;
 import org.apache.mahout.common.RandomUtils;
 import org.apache.mahout.ga.watchmaker.MahoutFitnessEvaluator;
 import org.uncommons.maths.random.PoissonGenerator;
@@ -94,12 +95,9 @@ public class EvolutionaryTravellingSales
                                         boolean crossover,
                                         boolean mutation,
                                         boolean mahout) {
-    if (eliteCount < 0 || eliteCount >= populationSize) {
-      throw new IllegalArgumentException("Elite count must be non-zero and 
less than population size.");
-    }
-    if (!crossover && !mutation) {
-      throw new IllegalArgumentException("At least one of cross-over or 
mutation must be selected.");
-    }
+    Preconditions.checkArgument(eliteCount >= 0 && eliteCount < populationSize,
+        "Elite count must be non-zero and less than population size.");
+    Preconditions.checkArgument(crossover || mutation, "At least one of 
cross-over or mutation must be selected.");
     this.distances = distances;
     this.selectionStrategy = selectionStrategy;
     this.populationSize = populationSize;

Modified: 
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplitTest.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplitTest.java?rev=1004046&r1=1004045&r2=1004046&view=diff
==============================================================================
--- 
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplitTest.java
 (original)
+++ 
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/hadoop/DatasetSplitTest.java
 Sun Oct  3 20:53:07 2010
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.util.Collection;
 import java.util.HashSet;
 
+import com.google.common.base.Preconditions;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.io.LongWritable;
 import org.apache.hadoop.io.Text;
@@ -46,9 +47,7 @@ public final class DatasetSplitTest exte
     private final Text currentValue = new Text();
 
     MockReader(long size) {
-      if (size <= 0) {
-        throw new IllegalArgumentException("size must be positive");
-      }
+      Preconditions.checkArgument(size > 0, "Size must be positive", size);
       this.size = size;
     }
 

Modified: 
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/utils/MockDataSet.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/utils/MockDataSet.java?rev=1004046&r1=1004045&r2=1004046&view=diff
==============================================================================
--- 
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/utils/MockDataSet.java
 (original)
+++ 
mahout/trunk/examples/src/test/java/org/apache/mahout/ga/watchmaker/cd/utils/MockDataSet.java
 Sun Oct  3 20:53:07 2010
@@ -17,6 +17,7 @@
 
 package org.apache.mahout.ga.watchmaker.cd.utils;
 
+import com.google.common.base.Preconditions;
 import org.apache.mahout.ga.watchmaker.cd.DataSet;
 import org.easymock.classextension.EasyMock;
 
@@ -38,13 +39,9 @@ public final class MockDataSet {
    * @param maxnba max number of attributes
    */
   public MockDataSet(Random rng, int maxnba) {
-    if (maxnba <= 0) {
-      throw new IllegalArgumentException("maxnba must be greater than 0");
-    }
-
+    Preconditions.checkArgument(maxnba > 0, "maxnba must be positive");
     this.rng = rng;
     this.maxnba = maxnba;
-
     dataset = EasyMock.createMock(DataSet.class);
     DataSet.initialize(dataset);
   }

Modified: 
mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/lucene/LuceneIterable.java
URL: 
http://svn.apache.org/viewvc/mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/lucene/LuceneIterable.java?rev=1004046&r1=1004045&r2=1004046&view=diff
==============================================================================
--- 
mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/lucene/LuceneIterable.java
 (original)
+++ 
mahout/trunk/utils/src/main/java/org/apache/mahout/utils/vectors/lucene/LuceneIterable.java
 Sun Oct  3 20:53:07 2010
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.util.Collections;
 import java.util.Iterator;
 
+import com.google.common.base.Preconditions;
 import org.apache.lucene.document.FieldSelector;
 import org.apache.lucene.document.SetBasedFieldSelector;
 import org.apache.lucene.index.IndexReader;
@@ -68,9 +69,8 @@ public class LuceneIterable implements I
                         String field,
                         VectorMapper mapper,
                         double normPower) {
-    if (normPower != NO_NORMALIZING && normPower < 0) {
-      throw new IllegalArgumentException("normPower must either be -1 or >= 
0");
-    }
+    Preconditions.checkArgument(normPower == NO_NORMALIZING || normPower >= 0,
+        "If specified normPower must be nonnegative", normPower);
     idFieldSelector = new 
SetBasedFieldSelector(Collections.singleton(idField), 
Collections.<String>emptySet());
     this.indexReader = reader;
     this.idField = idField;


Reply via email to