You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mahout.apache.org by ss...@apache.org on 2013/04/01 11:18:13 UTC

svn commit: r1463115 [1/2] - in /mahout/trunk: ./ core/src/main/java/org/apache/mahout/cf/taste/hadoop/ core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/ core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/ core/src/main/java/org/ap...

Author: ssc
Date: Mon Apr  1 09:18:12 2013
New Revision: 1463115

URL: http://svn.apache.org/r1463115
Log:
MAHOUT-1184 Another take at pmd, findbugs and checkstyle

Added:
    mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/BiasedItemBasedRecommenderTest.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/BinarySearch.java
Removed:
    mahout/trunk/core/src/test/java/org/apache/mahout/common/DummyCounter.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/random/SyntheticVariable.java
Modified:
    mahout/trunk/CHANGELOG
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/AggregateAndRecommendReducer.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/BiasedItemBasedRecommender.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/precompute/FileSimilarItemsWriter.java
    mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/precompute/MultithreadedBatchItemSimilarities.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/IntPairWritable.java
    mahout/trunk/core/src/main/java/org/apache/mahout/common/MemoryUtil.java
    mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SplitPartitionedWritable.java
    mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/collocations/llr/GramKeyGroupComparator.java
    mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/TopItemsQueueTest.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunLogistic.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SGDHelper.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SimpleCsvExamples.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
    mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/ValidateAdaptiveLogistic.java
    mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java
    mahout/trunk/examples/src/test/java/org/apache/mahout/clustering/display/ClustersFilterTest.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/hbase/HBaseDataModel.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/SQL92BooleanPrefJDBCDataModel.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/SQL92JDBCDataModel.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/classifier/ConfusionMatrixDumper.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/MatrixDumper.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInputJob.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java
    mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/TermInfoClusterInOut.java
    mahout/trunk/integration/src/test/java/org/apache/mahout/text/MailArchivesClusteringAnalyzerTest.java
    mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t
    mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t
    mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/AbstractKeyTypeValueTypeMap.java.t
    mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/AbstractKeyTypeSet.java.t
    mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedSparseBinaryMatrix.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/Sorting.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/WeightedVectorComparator.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/decomposer/hebbian/HebbianUpdater.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/random/WeightedThing.java
    mahout/trunk/math/src/main/java/org/apache/mahout/math/solver/EigenDecomposition.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/FileBasedSparseBinaryMatrixTest.java
    mahout/trunk/math/src/test/java/org/apache/mahout/math/decomposer/lanczos/TestLanczosSolver.java

Modified: mahout/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/mahout/trunk/CHANGELOG?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/CHANGELOG (original)
+++ mahout/trunk/CHANGELOG Mon Apr  1 09:18:12 2013
@@ -2,6 +2,8 @@ Mahout Change Log
 
 Release 0.8 - unreleased
 
+  MAHOUT-1184 Another take at pmd, findbugs and checkstyle (ssc)
+
   MAHOUT-1182: Remove useless append (Dave Brosius via tdunning)
 
   MAHOUT-1176: Introduce a changelog file to raise contributors attribution (ssc)

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/EntityPrefWritable.java Mon Apr  1 09:18:12 2013
@@ -25,7 +25,7 @@ import org.apache.mahout.common.RandomUt
 import org.apache.mahout.math.VarLongWritable;
 
 /** A {@link org.apache.hadoop.io.Writable} encapsulating an item ID and a preference value. */
-public final class EntityPrefWritable extends VarLongWritable {
+public final class EntityPrefWritable extends VarLongWritable implements Cloneable {
   
   private float prefValue;
   

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/AggregateAndRecommendReducer.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/AggregateAndRecommendReducer.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/AggregateAndRecommendReducer.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/hadoop/item/AggregateAndRecommendReducer.java Mon Apr  1 09:18:12 2013
@@ -17,7 +17,6 @@
 
 package org.apache.mahout.cf.taste.hadoop.item;
 
-import com.google.common.primitives.Floats;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.mapreduce.Reducer;
@@ -36,7 +35,6 @@ import org.apache.mahout.math.function.F
 import org.apache.mahout.math.map.OpenIntLongHashMap;
 
 import java.io.IOException;
-import java.util.Comparator;
 import java.util.Iterator;
 import java.util.List;
 
@@ -71,13 +69,6 @@ public final class AggregateAndRecommend
   private OpenIntLongHashMap indexItemIDMap;
 
   private static final float BOOLEAN_PREF_VALUE = 1.0f;
-  private static final Comparator<RecommendedItem> BY_PREFERENCE_VALUE =
-      new Comparator<RecommendedItem>() {
-        @Override
-        public int compare(RecommendedItem one, RecommendedItem two) {
-          return Floats.compare(one.getValue(), two.getValue());
-        }
-      };
 
   @Override
   protected void setup(Context context) throws IOException {

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/BiasedItemBasedRecommender.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/BiasedItemBasedRecommender.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/BiasedItemBasedRecommender.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/recommender/BiasedItemBasedRecommender.java Mon Apr  1 09:18:12 2013
@@ -17,6 +17,7 @@
 
 package org.apache.mahout.cf.taste.impl.recommender;
 
+import com.google.common.primitives.Doubles;
 import org.apache.mahout.cf.taste.common.TasteException;
 import org.apache.mahout.cf.taste.impl.common.FullRunningAverage;
 import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator;
@@ -25,6 +26,9 @@ import org.apache.mahout.cf.taste.model.
 import org.apache.mahout.cf.taste.model.Preference;
 import org.apache.mahout.cf.taste.model.PreferenceArray;
 import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
+import org.apache.mahout.math.Sorting;
+import org.apache.mahout.math.Swapper;
+import org.apache.mahout.math.function.IntComparator;
 import org.apache.mahout.math.map.OpenLongDoubleHashMap;
 
 /**
@@ -138,14 +142,16 @@ public class BiasedItemBasedRecommender 
     float[] ratings = new float[userIDs.length];
     long[] itemIDs = new long[userIDs.length];
             
-    double[] similarities = similarity.itemSimilarities(itemID, userIDs);
+    final double[] similarities = similarity.itemSimilarities(itemID, userIDs);
 
     for (int n = 0; n < preferencesFromUser.length(); n++) {
       ratings[n] = preferencesFromUser.get(n).getValue();
       itemIDs[n] = preferencesFromUser.get(n).getItemID();
     }
 
-    quickSort(similarities, ratings, itemIDs, 0, similarities.length - 1);
+    // sort, so that we can only use the top similarities
+    Sorting.quickSort(0, similarities.length, new SimilaritiesComparator(similarities),
+        new SimilaritiesRatingsItemIDsSwapper(similarities, ratings, itemIDs));
 
     double preference = 0.0;
     double totalSimilarity = 0.0;
@@ -153,9 +159,6 @@ public class BiasedItemBasedRecommender 
     for (int i = 0; i < Math.min(numSimilarItems, similarities.length); i++) {
       double theSimilarity = similarities[i];
       if (!Double.isNaN(theSimilarity)) {
-        if (Double.isInfinite(theSimilarity)) {
-          throw new IllegalStateException();
-        }
         preference += theSimilarity * (ratings[i] - baselineEstimate(userID, itemIDs[i]));
         totalSimilarity += Math.abs(theSimilarity);
         count++;
@@ -167,32 +170,48 @@ public class BiasedItemBasedRecommender 
     }
 
     return (float) (baselineEstimate(userID, itemID) + (preference / totalSimilarity));
-  }  
+  }
 
-  //TODO is it possible to do this without recursion?
-  protected static void quickSort(double[] similarities, float[] values, long[] otherValues, int start, int end) {
-    if (start < end) {
-      double pivot = similarities[end];
-      float pivotValue = values[end];
-      int i = start;
-      int j = end;
-      while (i != j) {
-        if (similarities[i] > pivot) {
-          i++;
-        } else {
-          similarities[j] = similarities[i];
-          values[j] = values[i];
-          otherValues[j] = otherValues[i];
-          similarities[i] = similarities[j - 1];
-          values[i] = values[j - 1];
-          otherValues[i] = otherValues[j - 1];
-          j--;
-        }
-      }
-      similarities[j] = pivot;
-      values[j] = pivotValue;
-      quickSort(similarities, values, otherValues, start, j - 1);
-      quickSort(similarities, values, otherValues, j + 1, end);
+  static class SimilaritiesComparator implements IntComparator {
+
+    private final double[] similarities;
+
+    SimilaritiesComparator(double[] similarities) {
+      this.similarities = similarities;
     }
-  }  
+
+    @Override
+    public int compare(int pos1, int pos2) {
+      return -1 * Doubles.compare(similarities[pos1], similarities[pos2]);
+    }
+  }
+
+  static class SimilaritiesRatingsItemIDsSwapper implements Swapper {
+
+    private final double[] similarities;
+    private final float[] ratings;
+    private final long[] itemIDs;
+
+    SimilaritiesRatingsItemIDsSwapper(double[] similarities, float[] ratings, long[] itemIDs) {
+      this.similarities = similarities;
+      this.ratings = ratings;
+      this.itemIDs = itemIDs;
+    }
+
+    @Override
+    public void swap(int a, int b) {
+      double tempDouble = similarities[b];
+      similarities[b] = similarities[a];
+      similarities[a] = tempDouble;
+
+      float tempFloat = ratings[b];
+      ratings[b] = ratings[a];
+      ratings[a] = tempFloat;
+
+      long tempLong = itemIDs[b];
+      itemIDs[b] = itemIDs[a];
+      itemIDs[a] = tempLong;
+    }
+  }
+
 }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/precompute/FileSimilarItemsWriter.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/precompute/FileSimilarItemsWriter.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/precompute/FileSimilarItemsWriter.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/precompute/FileSimilarItemsWriter.java Mon Apr  1 09:18:12 2013
@@ -17,6 +17,7 @@
 
 package org.apache.mahout.cf.taste.impl.similarity.precompute;
 
+import com.google.common.base.Charsets;
 import com.google.common.io.Closeables;
 import org.apache.mahout.cf.taste.similarity.precompute.SimilarItem;
 import org.apache.mahout.cf.taste.similarity.precompute.SimilarItems;
@@ -24,8 +25,9 @@ import org.apache.mahout.cf.taste.simila
 
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStreamWriter;
 
 /**
  * Persist the precomputed item similarities to a file that can later be used
@@ -42,7 +44,7 @@ public class FileSimilarItemsWriter impl
 
   @Override
   public void open() throws IOException {
-    writer = new BufferedWriter(new FileWriter(file));
+    writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8));
   }
 
   @Override

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/precompute/MultithreadedBatchItemSimilarities.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/precompute/MultithreadedBatchItemSimilarities.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/precompute/MultithreadedBatchItemSimilarities.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/cf/taste/impl/similarity/precompute/MultithreadedBatchItemSimilarities.java Mon Apr  1 09:18:12 2013
@@ -142,7 +142,7 @@ public class MultithreadedBatchItemSimil
   }
 
 
-  private class Output implements Runnable {
+  private static class Output implements Runnable {
 
     private final BlockingQueue<List<SimilarItems>> results;
     private final SimilarItemsWriter writer;

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/IntPairWritable.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/IntPairWritable.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/IntPairWritable.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/IntPairWritable.java Mon Apr  1 09:18:12 2013
@@ -145,7 +145,7 @@ public final class IntPairWritable exten
     WritableComparator.define(IntPairWritable.class, new Comparator());
   }
 
-  public static final class Comparator extends WritableComparator {
+  public static final class Comparator extends WritableComparator implements Serializable {
     public Comparator() {
       super(IntPairWritable.class);
     }

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/common/MemoryUtil.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/common/MemoryUtil.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/common/MemoryUtil.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/common/MemoryUtil.java Mon Apr  1 09:18:12 2013
@@ -49,7 +49,7 @@ public final class MemoryUtil {
              maxBytes);
   }
 
-  private static ScheduledExecutorService scheduler;
+  private static volatile ScheduledExecutorService scheduler;
 
   /**
    * Constructs and starts a memory logger thread.

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SplitPartitionedWritable.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SplitPartitionedWritable.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SplitPartitionedWritable.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/math/hadoop/stochasticsvd/SplitPartitionedWritable.java Mon Apr  1 09:18:12 2013
@@ -19,6 +19,7 @@ package org.apache.mahout.math.hadoop.st
 import java.io.DataInput;
 import java.io.DataOutput;
 import java.io.IOException;
+import java.io.Serializable;
 
 import org.apache.hadoop.io.WritableComparable;
 import org.apache.hadoop.io.WritableComparator;
@@ -125,7 +126,7 @@ public class SplitPartitionedWritable im
     return 0;
   }
 
-  public static final class SplitGroupingComparator extends WritableComparator {
+  public static final class SplitGroupingComparator extends WritableComparator implements Serializable {
 
     public SplitGroupingComparator() {
       super(SplitPartitionedWritable.class, true);

Modified: mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/collocations/llr/GramKeyGroupComparator.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/collocations/llr/GramKeyGroupComparator.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/collocations/llr/GramKeyGroupComparator.java (original)
+++ mahout/trunk/core/src/main/java/org/apache/mahout/vectorizer/collocations/llr/GramKeyGroupComparator.java Mon Apr  1 09:18:12 2013
@@ -20,10 +20,12 @@ package org.apache.mahout.vectorizer.col
 import org.apache.hadoop.io.WritableComparable;
 import org.apache.hadoop.io.WritableComparator;
 
+import java.io.Serializable;
+
 /** Group GramKeys based on their Gram, ignoring the secondary sort key, so that all keys with the same Gram are sent
  *  to the same call of the reduce method, sorted in natural order (for GramKeys).
  */
-class GramKeyGroupComparator extends WritableComparator {
+class GramKeyGroupComparator extends WritableComparator implements Serializable {
 
   GramKeyGroupComparator() {
     super(GramKey.class, true);

Modified: mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/TopItemsQueueTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/TopItemsQueueTest.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/TopItemsQueueTest.java (original)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/hadoop/TopItemsQueueTest.java Mon Apr  1 09:18:12 2013
@@ -17,8 +17,6 @@
 
 package org.apache.mahout.cf.taste.hadoop;
 
-import org.apache.mahout.cf.taste.hadoop.MutableRecommendedItem;
-import org.apache.mahout.cf.taste.hadoop.TopItemsQueue;
 import org.apache.mahout.cf.taste.impl.TasteTestCase;
 import org.apache.mahout.cf.taste.recommender.RecommendedItem;
 import org.apache.mahout.common.MahoutTestCase;

Added: mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/BiasedItemBasedRecommenderTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/BiasedItemBasedRecommenderTest.java?rev=1463115&view=auto
==============================================================================
--- mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/BiasedItemBasedRecommenderTest.java (added)
+++ mahout/trunk/core/src/test/java/org/apache/mahout/cf/taste/impl/recommender/BiasedItemBasedRecommenderTest.java Mon Apr  1 09:18:12 2013
@@ -0,0 +1,50 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.cf.taste.impl.recommender;
+
+import org.apache.mahout.math.Sorting;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class BiasedItemBasedRecommenderTest {
+
+  @Test
+  public void sorting() {
+
+    double[] similarities = new double[] { 0.1, 1.0, 0.5 };
+    float[] ratings = new float[] { 3, 1, 2 };
+    long[] itemIDs = new long[] { 3, 1, 2 };
+
+    Sorting.quickSort(0, similarities.length, new BiasedItemBasedRecommender.SimilaritiesComparator(similarities),
+        new BiasedItemBasedRecommender.SimilaritiesRatingsItemIDsSwapper(similarities, ratings, itemIDs));
+
+    assertEquals(1d, similarities[0], 0d);
+    assertEquals(0.5d, similarities[1], 0d);
+    assertEquals(0.1d, similarities[2], 0d);
+
+    assertEquals(1f, ratings[0], 0f);
+    assertEquals(2f, ratings[1], 0f);
+    assertEquals(3f, ratings[2], 0f);
+
+    assertEquals(1l, itemIDs[0]);
+    assertEquals(2l, itemIDs[1]);
+    assertEquals(3l, itemIDs[2]);
+  }
+
+}

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunLogistic.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunLogistic.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/RunLogistic.java Mon Apr  1 09:18:12 2013
@@ -77,21 +77,21 @@ public final class RunLogistic {
 
         double score = lr.classifyScalar(v);
         if (showScores) {
-          output.printf(Locale.ENGLISH, "%d,%.3f,%.6f\n", target, score, lr.logLikelihood(target, v));
+          output.printf(Locale.ENGLISH, "%d,%.3f,%.6f%n", target, score, lr.logLikelihood(target, v));
         }
         collector.add(target, score);
         line = in.readLine();
       }
 
       if (showAuc) {
-        output.printf(Locale.ENGLISH, "AUC = %.2f\n", collector.auc());
+        output.printf(Locale.ENGLISH, "AUC = %.2f%n", collector.auc());
       }
       if (showConfusion) {
         Matrix m = collector.confusion();
-        output.printf(Locale.ENGLISH, "confusion: [[%.1f, %.1f], [%.1f, %.1f]]\n",
+        output.printf(Locale.ENGLISH, "confusion: [[%.1f, %.1f], [%.1f, %.1f]]%n",
           m.get(0, 0), m.get(1, 0), m.get(0, 1), m.get(1, 1));
         m = collector.entropy();
-        output.printf(Locale.ENGLISH, "entropy: [[%.1f, %.1f], [%.1f, %.1f]]\n",
+        output.printf(Locale.ENGLISH, "entropy: [[%.1f, %.1f], [%.1f, %.1f]]%n",
           m.get(0, 0), m.get(1, 0), m.get(0, 1), m.get(1, 1));
       }
     }

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SGDHelper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SGDHelper.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SGDHelper.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SGDHelper.java Mon Apr  1 09:18:12 2013
@@ -71,7 +71,7 @@ public final class SGDHelper {
     System.out.println("============");
     System.out.println("Model Dissection");
     for (ModelDissector.Weight w : weights) {
-      System.out.printf("%s\t%.1f\t%s\t%.1f\t%s\t%.1f\t%s\n",
+      System.out.printf("%s\t%.1f\t%s\t%.1f\t%s\t%.1f\t%s%n",
                         w.getFeature(), w.getWeight(), ngNames.get(w.getMaxImpact() + 1),
                         w.getCategory(1), w.getWeight(1), w.getCategory(2), w.getWeight(2));
     }
@@ -144,7 +144,7 @@ public final class SGDHelper {
 
       info.setStep(info.getStep() + 0.25);
       System.out.printf("%.2f\t%.2f\t%.2f\t%.2f\t%.8g\t%.8g\t", maxBeta, nonZeros, positive, norm, lambda, mu);
-      System.out.printf("%d\t%.3f\t%.2f\t%s\n",
+      System.out.printf("%d\t%.3f\t%.2f\t%s%n",
         k, info.getAverageLL(), info.getAverageCorrect() * 100, LEAK_LABELS[leakType % 3]);
     }
   }

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SimpleCsvExamples.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SimpleCsvExamples.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SimpleCsvExamples.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/SimpleCsvExamples.java Mon Apr  1 09:18:12 2013
@@ -134,7 +134,7 @@ public final class SimpleCsvExamples {
         separator = ",";
       }
     }
-    System.out.printf("\nElapsed time = %.3f\n", (System.currentTimeMillis() - t0) / 1000.0);
+    System.out.printf("\nElapsed time = %.3f%n", (System.currentTimeMillis() - t0) / 1000.0);
   }
 
 

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainAdaptiveLogistic.java Mon Apr  1 09:18:12 2013
@@ -80,7 +80,6 @@ public final class TrainAdaptiveLogistic
         csv.firstLine(in.readLine());
 
         String line = in.readLine();
-        int lineCount = 2;
         while (line != null) {
           // for each new line, get target and predictors
           Vector input = new RandomAccessSparseVector(lmp.getNumFeatures());
@@ -99,16 +98,15 @@ public final class TrainAdaptiveLogistic
             if (learner != null) {
               double averageCorrect = learner.percentCorrect();
               double averageLL = learner.logLikelihood();
-              output.printf("%d\t%.3f\t%.2f\n",
+              output.printf("%d\t%.3f\t%.2f%n",
                             k, averageLL, averageCorrect * 100);
             } else {
               output.printf(Locale.ENGLISH,
-                            "%10d %2d %s\n", k, targetValue,
+                            "%10d %2d %s%n", k, targetValue,
                             "AdaptiveLogisticRegression has not found a good model ......");
             }
           }
           line = in.readLine();
-          lineCount++;
         }
         in.close();
       }
@@ -141,13 +139,13 @@ public final class TrainAdaptiveLogistic
           sep = " + ";
         }
       }
-      output.printf("\n");
+      output.printf("%n");
 
       for (int row = 0; row < lr.getBeta().numRows(); row++) {
         for (String key : csv.getTraceDictionary().keySet()) {
           double weight = predictorWeight(lr, row, csv, key);
           if (weight != 0) {
-            output.printf(Locale.ENGLISH, "%20s %.5f\n", key, weight);
+            output.printf(Locale.ENGLISH, "%20s %.5f%n", key, weight);
           }
         }
         for (int column = 0; column < lr.getBeta().numCols(); column++) {

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/TrainLogistic.java Mon Apr  1 09:18:12 2013
@@ -96,7 +96,7 @@ public final class TrainLogistic {
             }
             double p = lr.classifyScalar(input);
             if (scores) {
-              output.printf(Locale.ENGLISH, "%10d %2d %10.2f %2.4f %10.4f %10.4f\n",
+              output.printf(Locale.ENGLISH, "%10d %2d %10.2f %2.4f %10.4f %10.4f%n",
                 samples, targetValue, lr.currentLearningRate(), p, logP, logPEstimate);
             }
 
@@ -127,13 +127,13 @@ public final class TrainLogistic {
           sep = " + ";
         }
       }
-      output.printf("\n");
+      output.printf("%n");
       model = lr;
       for (int row = 0; row < lr.getBeta().numRows(); row++) {
         for (String key : csv.getTraceDictionary().keySet()) {
           double weight = predictorWeight(lr, row, csv, key);
           if (weight != 0) {
-            output.printf(Locale.ENGLISH, "%20s %.5f\n", key, weight);
+            output.printf(Locale.ENGLISH, "%20s %.5f%n", key, weight);
           }
         }
         for (int column = 0; column < lr.getBeta().numCols(); column++) {

Modified: mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/ValidateAdaptiveLogistic.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/ValidateAdaptiveLogistic.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/ValidateAdaptiveLogistic.java (original)
+++ mahout/trunk/examples/src/main/java/org/apache/mahout/classifier/sgd/ValidateAdaptiveLogistic.java Mon Apr  1 09:18:12 2013
@@ -108,7 +108,7 @@ public final class ValidateAdaptiveLogis
         cm.addInstance(csv.getTargetString(line), csv.getTargetLabel(target));        
 
         if (showScores) {
-          output.printf(Locale.ENGLISH, "%8d, %.12f, %.13f, %.13f\n", target,
+          output.printf(Locale.ENGLISH, "%8d, %.12f, %.13f, %.13f%n", target,
               score, learner.logLikelihood(target, v), slh.getMean());
         }
         if (collector != null) {
@@ -118,20 +118,20 @@ public final class ValidateAdaptiveLogis
       }
 
       output.printf(Locale.ENGLISH,"\nLog-likelihood:");
-      output.printf(Locale.ENGLISH, "Min=%.2f, Max=%.2f, Mean=%.2f, Median=%.2f\n", 
+      output.printf(Locale.ENGLISH, "Min=%.2f, Max=%.2f, Mean=%.2f, Median=%.2f%n",
           slh.getMin(), slh.getMax(), slh.getMean(), slh.getMedian());
 
       if (collector != null) {        
-        output.printf(Locale.ENGLISH, "\nAUC = %.2f\n", collector.auc());        
+        output.printf(Locale.ENGLISH, "%nAUC = %.2f%n", collector.auc());
       }
 
       if (showConfusion) {
-        output.printf(Locale.ENGLISH, "\n%s\n\n", cm.toString());
+        output.printf(Locale.ENGLISH, "%n%s%n%n", cm.toString());
 
         if (collector != null) {
           Matrix m = collector.entropy();
           output.printf(Locale.ENGLISH,
-              "Entropy Matrix: [[%.1f, %.1f], [%.1f, %.1f]]\n", m.get(0, 0),
+              "Entropy Matrix: [[%.1f, %.1f], [%.1f, %.1f]]%n", m.get(0, 0),
               m.get(1, 0), m.get(0, 1), m.get(1, 1));
         }        
       }

Modified: mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java (original)
+++ mahout/trunk/examples/src/test/java/org/apache/mahout/classifier/sgd/TrainLogisticTest.java Mon Apr  1 09:18:12 2013
@@ -40,7 +40,7 @@ import java.util.Set;
 public class TrainLogisticTest extends MahoutTestCase {
 
   @Test
-  public void example13_1() throws Exception {
+  public void example131() throws Exception {
     String outputFile = getTestTempFile("model").getAbsolutePath();
 
     StringWriter sw = new StringWriter();
@@ -100,7 +100,7 @@ public class TrainLogisticTest extends M
   }
 
   @Test
-  public void example13_2() throws Exception {
+  public void example132() throws Exception {
     String outputFile = getTestTempFile("model").getAbsolutePath();
 
     StringWriter sw = new StringWriter();

Modified: mahout/trunk/examples/src/test/java/org/apache/mahout/clustering/display/ClustersFilterTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/examples/src/test/java/org/apache/mahout/clustering/display/ClustersFilterTest.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/examples/src/test/java/org/apache/mahout/clustering/display/ClustersFilterTest.java (original)
+++ mahout/trunk/examples/src/test/java/org/apache/mahout/clustering/display/ClustersFilterTest.java Mon Apr  1 09:18:12 2013
@@ -40,7 +40,7 @@ public class ClustersFilterTest extends 
   }
 
   @Test
-  public void testAccept_notFinal() throws Exception {
+  public void testAcceptNotFinal() throws Exception {
     Path path0 = new Path(output, "clusters-0");
     Path path1 = new Path(output, "clusters-1");
 
@@ -54,7 +54,7 @@ public class ClustersFilterTest extends 
   }
 
   @Test
-  public void testAccept_finalPath() throws IOException {
+  public void testAcceptFinalPath() throws IOException {
     Path path0 = new Path(output, "clusters-0");
     Path path1 = new Path(output, "clusters-1");
     Path path2 = new Path(output, "clusters-2");

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/hbase/HBaseDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/hbase/HBaseDataModel.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/hbase/HBaseDataModel.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/hbase/HBaseDataModel.java Mon Apr  1 09:18:12 2013
@@ -95,7 +95,6 @@ public final class HBaseDataModel implem
 
   private final HTablePool pool;
   private final String tableName;
-  private final boolean tableWasCreated;
 
   // Cache of user and item ids
   private volatile FastIDSet itemIDs;
@@ -112,7 +111,8 @@ public final class HBaseDataModel implem
     HTableFactory tableFactory = new HTableFactory();
     this.pool = new HTablePool(conf, 8, tableFactory);
     this.tableName = tableName;
-    this.tableWasCreated = bootstrap(conf);
+
+    bootstrap(conf);
     // Warm the cache
     refresh(null);
   }
@@ -121,7 +121,8 @@ public final class HBaseDataModel implem
     log.info("Using HBase table {}", tableName);
     this.pool = pool;
     this.tableName = tableName;
-    this.tableWasCreated = bootstrap(conf);
+
+    bootstrap(conf);
 
     // Warm the cache
     refresh(null);
@@ -134,7 +135,7 @@ public final class HBaseDataModel implem
   /**
    * Create the table if it doesn't exist
    */
-  private boolean bootstrap(Configuration conf) throws IOException {
+  private void bootstrap(Configuration conf) throws IOException {
     HBaseAdmin admin = new HBaseAdmin(conf);
     HTableDescriptor tDesc = new HTableDescriptor(Bytes.toBytes(tableName));
     tDesc.addFamily(new HColumnDescriptor(USERS_CF));
@@ -142,10 +143,8 @@ public final class HBaseDataModel implem
     try {
       admin.createTable(tDesc);
       log.info("Created table {}", tableName);
-      return true;
     } catch (TableExistsException e) {
       log.info("Table {} alreay exists", tableName);
-      return false;
     } finally {
       admin.close();
     }

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/SQL92BooleanPrefJDBCDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/SQL92BooleanPrefJDBCDataModel.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/SQL92BooleanPrefJDBCDataModel.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/SQL92BooleanPrefJDBCDataModel.java Mon Apr  1 09:18:12 2013
@@ -188,13 +188,14 @@ public class SQL92BooleanPrefJDBCDataMod
     Connection conn = null;
     PreparedStatement stmt1 = null;
     PreparedStatement stmt2 = null;
+    ResultSet rs = null;
     try {
       conn = getDataSource().getConnection();
 
       stmt1 = conn.prepareStatement(verifyPreferenceSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
       setLongParameter(stmt1, 1, userID);
       setLongParameter(stmt1, 2, itemID);
-      ResultSet rs = stmt1.executeQuery();
+      rs = stmt1.executeQuery();
 
       // test if the record exists already.
       if (!rs.first()) {
@@ -210,6 +211,7 @@ public class SQL92BooleanPrefJDBCDataMod
       log.warn("Exception while setting preference", sqle);
       throw new TasteException(sqle);
     } finally {
+      IOUtils.quietClose(rs);
       IOUtils.quietClose(stmt1);
       IOUtils.quietClose(stmt2);
       IOUtils.quietClose(conn);

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/SQL92JDBCDataModel.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/SQL92JDBCDataModel.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/SQL92JDBCDataModel.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/cf/taste/impl/model/jdbc/SQL92JDBCDataModel.java Mon Apr  1 09:18:12 2013
@@ -203,13 +203,14 @@ public class SQL92JDBCDataModel extends 
     PreparedStatement stmt1 = null;
     PreparedStatement stmt2 = null;
     PreparedStatement stmt3 = null;
+    ResultSet rs = null;
     try {
       conn = getDataSource().getConnection();
 
       stmt1 = conn.prepareStatement(verifyPreferenceSQL, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
       setLongParameter(stmt1, 1, userID);
       setLongParameter(stmt1, 2, itemID);
-      ResultSet rs = stmt1.executeQuery();
+      rs = stmt1.executeQuery();
 
       // test if the record exists already.
       if (rs.first()) {
@@ -236,6 +237,7 @@ public class SQL92JDBCDataModel extends 
       log.warn("Exception while setting preference", sqle);
       throw new TasteException(sqle);
     } finally {
+      IOUtils.quietClose(rs);
       IOUtils.quietClose(stmt1);
       IOUtils.quietClose(stmt2);
       IOUtils.quietClose(stmt3);

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/classifier/ConfusionMatrixDumper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/classifier/ConfusionMatrixDumper.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/classifier/ConfusionMatrixDumper.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/classifier/ConfusionMatrixDumper.java Mon Apr  1 09:18:12 2013
@@ -26,6 +26,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import com.google.common.base.Charsets;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -243,7 +244,7 @@ public final class ConfusionMatrixDumper
       }
       outputFile.createNewFile();
       OutputStream os = new FileOutputStream(outputFile);
-      return new PrintStream(os);
+      return new PrintStream(os, false, Charsets.UTF_8.displayName());
     } else {
       return System.out;
     }
@@ -386,14 +387,14 @@ public final class ConfusionMatrixDumper
     int longest = getLongestHeader(labels);
     if (vertical) {
       // do vertical - rotation is a bitch
-      out.format("<tr class='%s' style='height:%dem'><th>&nbsp;</th>\n", CSS_TALL_HEADER, longest / 2);
+      out.format("<tr class='%s' style='height:%dem'><th>&nbsp;</th>%n", CSS_TALL_HEADER, longest / 2);
       for (String label : labels) {
         out.format("<th><div class='%s'>%s</div></th>", CSS_VERTICAL, label);
       }
       out.println("</tr>");
     } else {
       // header - empty cell in upper left
-      out.format("<tr class='%s'><td class='%s'></td>\n", CSS_TABLE, CSS_LABEL);
+      out.format("<tr class='%s'><td class='%s'></td>%n", CSS_TABLE, CSS_LABEL);
       for (String label : labels) {
         out.format("<td>%s</td>", label);
       }

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/MatrixDumper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/MatrixDumper.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/MatrixDumper.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/MatrixDumper.java Mon Apr  1 09:18:12 2013
@@ -25,6 +25,7 @@ import java.io.PrintStream;
 import java.util.List;
 import java.util.Map;
 
+import com.google.common.base.Charsets;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.Path;
 import org.apache.hadoop.util.ToolRunner;
@@ -107,7 +108,7 @@ public final class MatrixDumper extends 
     }
     outputFile.createNewFile();
     OutputStream os = new FileOutputStream(outputFile);
-    return new PrintStream(os);
+    return new PrintStream(os, false, Charsets.UTF_8.displayName());
   }
   
   /**

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SequenceFileDumper.java Mon Apr  1 09:18:12 2013
@@ -79,7 +79,7 @@ public final class SequenceFileDumper ex
       writer = Files.newWriter(new File(getOption("output")), Charsets.UTF_8);
     } else {
       shouldClose = false;
-      writer = new OutputStreamWriter(System.out);
+      writer = new OutputStreamWriter(System.out, Charsets.UTF_8);
     }
     try {
       for (Path path : pathArr) {

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInputJob.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInputJob.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInputJob.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/SplitInputJob.java Mon Apr  1 09:18:12 2013
@@ -18,6 +18,7 @@
 package org.apache.mahout.utils;
 
 import java.io.IOException;
+import java.io.Serializable;
 import java.util.Random;
 
 import org.apache.hadoop.conf.Configuration;
@@ -215,7 +216,7 @@ public final class SplitInputJob {
   /**
    * Randomly permute key value pairs
    */
-  public static class SplitInputComparator extends WritableComparator {
+  public static class SplitInputComparator extends WritableComparator implements Serializable {
 
     private final Random rnd = RandomUtils.getRandom();
 

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/clustering/ClusterDumper.java Mon Apr  1 09:18:12 2013
@@ -174,7 +174,7 @@ public final class ClusterDumper extends
     boolean shouldClose;
     if (this.outputFile == null) {
       shouldClose = false;
-      writer = new OutputStreamWriter(System.out);
+      writer = new OutputStreamWriter(System.out, Charsets.UTF_8);
     } else {
       shouldClose = true;
       if (outputFile.getName().startsWith("s3n://")) {

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/VectorDumper.java Mon Apr  1 09:18:12 2013
@@ -153,7 +153,7 @@ public final class VectorDumper extends 
       writer = Files.newWriter(output, Charsets.UTF_8);
     } else {
       shouldClose = false;
-      writer = new OutputStreamWriter(System.out);
+      writer = new OutputStreamWriter(System.out, Charsets.UTF_8);
     }
     try {
       boolean printKey = hasOption("printKey");

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/ClusterLabels.java Mon Apr  1 09:18:12 2013
@@ -109,7 +109,7 @@ public class ClusterLabels {
 
     Writer writer;
     if (this.output == null) {
-      writer = new OutputStreamWriter(System.out);
+      writer = new OutputStreamWriter(System.out, Charsets.UTF_8);
     } else {
       writer = Files.newWriter(new File(this.output), Charsets.UTF_8);
     }

Modified: mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/TermInfoClusterInOut.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/TermInfoClusterInOut.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/TermInfoClusterInOut.java (original)
+++ mahout/trunk/integration/src/main/java/org/apache/mahout/utils/vectors/lucene/TermInfoClusterInOut.java Mon Apr  1 09:18:12 2013
@@ -52,7 +52,7 @@ class TermInfoClusterInOut implements Co
 
   @Override
   public int compareTo(TermInfoClusterInOut that) {
-    int res = -Double.compare(logLikelihoodRatio, that.logLikelihoodRatio);
+    int res = Double.compare(that.logLikelihoodRatio, logLikelihoodRatio);
     if (res == 0) {
       res = term.compareTo(that.term);
     }

Modified: mahout/trunk/integration/src/test/java/org/apache/mahout/text/MailArchivesClusteringAnalyzerTest.java
URL: http://svn.apache.org/viewvc/mahout/trunk/integration/src/test/java/org/apache/mahout/text/MailArchivesClusteringAnalyzerTest.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/integration/src/test/java/org/apache/mahout/text/MailArchivesClusteringAnalyzerTest.java (original)
+++ mahout/trunk/integration/src/test/java/org/apache/mahout/text/MailArchivesClusteringAnalyzerTest.java Mon Apr  1 09:18:12 2013
@@ -36,13 +36,13 @@ public class MailArchivesClusteringAnaly
   public void testAnalysis() throws Exception {
     Analyzer analyzer = new MailArchivesClusteringAnalyzer();
     
-    String text = "A test message\n";
-    text += "atokenthatistoolongtobeusefulforclustertextanalysis\n";
-    text += "Mahout is a scalable, machine-learning LIBRARY\n";
-    text += "we've added some additional stopwords such as html, mailto, regards\t";
-    text += "apache_hadoop provides the foundation for scalability\n";
-    text += "www.nabble.com general-help@incubator.apache.org\n";
-    text += "public void int protected package";
+    String text = "A test message\n"
+                  + "atokenthatistoolongtobeusefulforclustertextanalysis\n"
+                  + "Mahout is a scalable, machine-learning LIBRARY\n"
+                  + "we've added some additional stopwords such as html, mailto, regards\t"
+                  + "apache_hadoop provides the foundation for scalability\n"
+                  + "www.nabble.com general-help@incubator.apache.org\n"
+                  + "public void int protected package";
     Reader reader = new StringReader(text);
     
     // if you change the text above, then you may need to change this as well

Modified: mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t (original)
+++ mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/AbstractValueTypeList.java.t Mon Apr  1 09:18:12 2013
@@ -85,7 +85,7 @@ public abstract class Abstract${valueTyp
    **/
   @Override
   public void addAllOf(${valueTypeCap}ArrayList other) {
-	addAllOfFromTo(other, 0, other.size() - 1);
+    addAllOfFromTo(other, 0, other.size() - 1);
   }
 
   /**
@@ -140,6 +140,7 @@ public abstract class Abstract${valueTyp
       replaceFromToWithFrom(index + length, size - 1, this, index);
     }
   }
+
   /**
    * Searches the receiver for the specified value using the binary search algorithm.  The receiver must
    * <strong>must</strong> be sorted (as by the sort method) prior to making this call.  If it is not sorted, the

Modified: mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t (original)
+++ mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/list/ValueTypeArrayList.java.t Mon Apr  1 09:18:12 2013
@@ -119,14 +119,14 @@ public class ${valueTypeCap}ArrayList ex
    *         the receiver: the index of the first element greater than the key, or <tt>receiver.size()</tt>, if all
    *         elements in the receiver are less than the specified key.  Note that this guarantees that the return value
    *         will be &gt;= 0 if and only if the key is found.
-   * @see org.apache.mahout.math.Sorting
+   * @see org.apache.mahout.math.BinarySearch
    * @see java.util.Arrays
    */
   @Override
   public int binarySearchFromTo(${valueType} key, int from, int to) {
-    return org.apache.mahout.math.Sorting.binarySearchFromTo(elements, key, from, to);
+    return org.apache.mahout.math.BinarySearch.binarySearchFromTo(elements, key, from, to);
   }
-  
+
   /**
    * Returns a deep copy of the receiver.
    *

Modified: mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/AbstractKeyTypeValueTypeMap.java.t
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/AbstractKeyTypeValueTypeMap.java.t?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/AbstractKeyTypeValueTypeMap.java.t (original)
+++ mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/map/AbstractKeyTypeValueTypeMap.java.t Mon Apr  1 09:18:12 2013
@@ -58,7 +58,7 @@ public abstract class Abstract${keyTypeC
         new ${keyTypeCap}Procedure() {
           @Override
           public boolean apply(${keyType} iterKey) {
-            return (key != iterKey);
+            return key != iterKey;
           }
         }
     );

Modified: mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/AbstractKeyTypeSet.java.t
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/AbstractKeyTypeSet.java.t?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/AbstractKeyTypeSet.java.t (original)
+++ mahout/trunk/math/src/main/java-templates/org/apache/mahout/math/set/AbstractKeyTypeSet.java.t Mon Apr  1 09:18:12 2013
@@ -23,7 +23,6 @@ import org.apache.mahout.math.function.$
 import org.apache.mahout.math.list.${keyTypeCap}ArrayList;
 import java.util.Arrays;
 import java.nio.IntBuffer;
-import org.apache.mahout.math.set.HashUtils;
 
 public abstract class Abstract${keyTypeCap}Set extends AbstractSet {
 

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/AbstractMatrix.java Mon Apr  1 09:18:12 2013
@@ -597,7 +597,7 @@ public abstract class AbstractMatrix imp
     return new int[]{rowSize(), columnSize()};
   }
 
-  protected class TransposeViewVector extends AbstractVector {
+  protected static class TransposeViewVector extends AbstractVector {
 
     private final Matrix matrix;
     private final int transposeOffset;

Added: mahout/trunk/math/src/main/java/org/apache/mahout/math/BinarySearch.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/BinarySearch.java?rev=1463115&view=auto
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/BinarySearch.java (added)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/BinarySearch.java Mon Apr  1 09:18:12 2013
@@ -0,0 +1,403 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mahout.math;
+
+import java.util.Comparator;
+
+public class BinarySearch {
+
+  private BinarySearch() {}
+
+  /**
+   * Performs a binary search for the specified element in the specified
+   * ascending sorted array. Searching in an unsorted array has an undefined
+   * result. It's also undefined which element is found if there are multiple
+   * occurrences of the same element.
+   *
+   * @param array
+   *          the sorted {@code byte} array to search.
+   * @param value
+   *          the {@code byte} element to find.
+   * @param from
+   *          the first index to sort, inclusive.
+   * @param to
+   *          the last index to sort, inclusive.
+   * @return the non-negative index of the element, or a negative index which is
+   *         {@code -index - 1} where the element would be inserted.
+   */
+  public static int binarySearchFromTo(byte[] array, byte value, int from, int to) {
+    int mid = -1;
+    while (from <= to) {
+      mid = (from + to) >>> 1;
+      if (value > array[mid]) {
+        from = mid + 1;
+      } else if (value == array[mid]) {
+        return mid;
+      } else {
+        to = mid - 1;
+      }
+    }
+    if (mid < 0) {
+      return -1;
+    }
+
+    return -mid - (value < array[mid] ? 1 : 2);
+  }
+
+  /**
+   * Performs a binary search for the specified element in the specified
+   * ascending sorted array. Searching in an unsorted array has an undefined
+   * result. It's also undefined which element is found if there are multiple
+   * occurrences of the same element.
+   *
+   * @param array
+   *          the sorted {@code char} array to search.
+   * @param value
+   *          the {@code char} element to find.
+   * @param from
+   *          the first index to sort, inclusive.
+   * @param to
+   *          the last index to sort, inclusive.
+   * @return the non-negative index of the element, or a negative index which is
+   *         {@code -index - 1} where the element would be inserted.
+   */
+  public static int binarySearchFromTo(char[] array, char value, int from, int to) {
+    int mid = -1;
+    while (from <= to) {
+      mid = (from + to) >>> 1;
+      if (value > array[mid]) {
+        from = mid + 1;
+      } else if (value == array[mid]) {
+        return mid;
+      } else {
+        to = mid - 1;
+      }
+    }
+    if (mid < 0) {
+      return -1;
+    }
+    return -mid - (value < array[mid] ? 1 : 2);
+  }
+
+  /**
+   * Performs a binary search for the specified element in the specified
+   * ascending sorted array. Searching in an unsorted array has an undefined
+   * result. It's also undefined which element is found if there are multiple
+   * occurrences of the same element.
+   *
+   * @param array
+   *          the sorted {@code double} array to search.
+   * @param value
+   *          the {@code double} element to find.
+   * @param from
+   *          the first index to sort, inclusive.
+   * @param to
+   *          the last index to sort, inclusive.
+   * @return the non-negative index of the element, or a negative index which is
+   *         {@code -index - 1} where the element would be inserted.
+   */
+  public static int binarySearchFromTo(double[] array, double value, int from, int to) {
+    long longBits = Double.doubleToLongBits(value);
+    int mid = -1;
+    while (from <= to) {
+      mid = (from + to) >>> 1;
+      if (lessThan(array[mid], value)) {
+        from = mid + 1;
+      } else if (longBits == Double.doubleToLongBits(array[mid])) {
+        return mid;
+      } else {
+        to = mid - 1;
+      }
+    }
+    if (mid < 0) {
+      return -1;
+    }
+    return -mid - (lessThan(value, array[mid]) ? 1 : 2);
+  }
+
+  /**
+   * Performs a binary search for the specified element in the specified
+   * ascending sorted array. Searching in an unsorted array has an undefined
+   * result. It's also undefined which element is found if there are multiple
+   * occurrences of the same element.
+   *
+   * @param array
+   *          the sorted {@code float} array to search.
+   * @param value
+   *          the {@code float} element to find.
+   * @param from
+   *          the first index to sort, inclusive.
+   * @param to
+   *          the last index to sort, inclusive.
+   * @return the non-negative index of the element, or a negative index which is
+   *         {@code -index - 1} where the element would be inserted.
+   */
+  public static int binarySearchFromTo(float[] array, float value, int from, int to) {
+    int intBits = Float.floatToIntBits(value);
+    int mid = -1;
+    while (from <= to) {
+      mid = (from + to) >>> 1;
+      if (lessThan(array[mid], value)) {
+        from = mid + 1;
+      } else if (intBits == Float.floatToIntBits(array[mid])) {
+        return mid;
+      } else {
+        to = mid - 1;
+      }
+    }
+    if (mid < 0) {
+      return -1;
+    }
+    return -mid - (lessThan(value, array[mid]) ? 1 : 2);
+  }
+
+  /**
+   * Performs a binary search for the specified element in the specified
+   * ascending sorted array. Searching in an unsorted array has an undefined
+   * result. It's also undefined which element is found if there are multiple
+   * occurrences of the same element.
+   *
+   * @param array
+   *          the sorted {@code int} array to search.
+   * @param value
+   *          the {@code int} element to find.
+   * @param from
+   *          the first index to sort, inclusive.
+   * @param to
+   *          the last index to sort, inclusive.
+   * @return the non-negative index of the element, or a negative index which is
+   *         {@code -index - 1} where the element would be inserted.
+   */
+  public static int binarySearchFromTo(int[] array, int value, int from, int to) {
+    int mid = -1;
+    while (from <= to) {
+      mid = (from + to) >>> 1;
+      if (value > array[mid]) {
+        from = mid + 1;
+      } else if (value == array[mid]) {
+        return mid;
+      } else {
+        to = mid - 1;
+      }
+    }
+    if (mid < 0) {
+      return -1;
+    }
+    return -mid - (value < array[mid] ? 1 : 2);
+  }
+
+  /**
+   * Performs a binary search for the specified element in the specified
+   * ascending sorted array. Searching in an unsorted array has an undefined
+   * result. It's also undefined which element is found if there are multiple
+   * occurrences of the same element.
+   *
+   * @param array
+   *          the sorted {@code long} array to search.
+   * @param value
+   *          the {@code long} element to find.
+   * @param from
+   *          the first index to sort, inclusive.
+   * @param to
+   *          the last index to sort, inclusive.
+   * @return the non-negative index of the element, or a negative index which is
+   *         {@code -index - 1} where the element would be inserted.
+   */
+  public static int binarySearchFromTo(long[] array, long value, int from, int to) {
+    int mid = -1;
+    while (from <= to) {
+      mid = (from + to) >>> 1;
+      if (value > array[mid]) {
+        from = mid + 1;
+      } else if (value == array[mid]) {
+        return mid;
+      } else {
+        to = mid - 1;
+      }
+    }
+    if (mid < 0) {
+      return -1;
+    }
+    return -mid - (value < array[mid] ? 1 : 2);
+  }
+
+  /**
+   * Performs a binary search for the specified element in the specified
+   * ascending sorted array. Searching in an unsorted array has an undefined
+   * result. It's also undefined which element is found if there are multiple
+   * occurrences of the same element.
+   *
+   * @param array
+   *          the sorted {@code Object} array to search.
+   * @param object
+   *          the {@code Object} element to find
+   * @param from
+   *          the first index to sort, inclusive.
+   * @param to
+   *          the last index to sort, inclusive.
+   * @return the non-negative index of the element, or a negative index which is
+   *         {@code -index - 1} where the element would be inserted.
+   *
+   */
+  public static <T extends Comparable<T>> int binarySearchFromTo(T[] array, T object, int from, int to) {
+    if (array.length == 0) {
+      return -1;
+    }
+
+    int mid = 0;
+    int result = 0;
+    while (from <= to) {
+      mid = (from + to) >>> 1;
+      if ((result = array[mid].compareTo(object)) < 0) {
+        from = mid + 1;
+      } else if (result == 0) {
+        return mid;
+      } else {
+        to = mid - 1;
+      }
+    }
+    return -mid - (result >= 0 ? 1 : 2);
+  }
+
+  /**
+   * Performs a binary search for the specified element in the specified
+   * ascending sorted array using the {@code Comparator} to compare elements.
+   * Searching in an unsorted array has an undefined result. It's also undefined
+   * which element is found if there are multiple occurrences of the same
+   * element.
+   *
+   * @param array
+   *          the sorted array to search
+   * @param object
+   *          the element to find
+   * @param from
+   *          the first index to sort, inclusive.
+   * @param to
+   *          the last index to sort, inclusive.
+   * @param comparator
+   *          the {@code Comparator} used to compare the elements.
+   * @return the non-negative index of the element, or a negative index which
+   */
+  public static <T> int binarySearchFromTo(T[] array, T object, int from, int to, Comparator<? super T> comparator) {
+    int mid = 0;
+    int result = 0;
+    while (from <= to) {
+      mid = (from + to) >>> 1;
+      if ((result = comparator.compare(array[mid], object)) < 0) {
+        from = mid + 1;
+      } else if (result == 0) {
+        return mid;
+      } else {
+        to = mid - 1;
+      }
+    }
+    return -mid - (result >= 0 ? 1 : 2);
+  }
+
+  /**
+   * Performs a binary search for the specified element in the specified
+   * ascending sorted array. Searching in an unsorted array has an undefined
+   * result. It's also undefined which element is found if there are multiple
+   * occurrences of the same element.
+   *
+   * @param array
+   *          the sorted {@code short} array to search.
+   * @param value
+   *          the {@code short} element to find.
+   * @param from
+   *          the first index to sort, inclusive.
+   * @param to
+   *          the last index to sort, inclusive.
+   * @return the non-negative index of the element, or a negative index which is
+   *         {@code -index - 1} where the element would be inserted.
+   */
+  public static int binarySearchFromTo(short[] array, short value, int from, int to) {
+    int mid = -1;
+    while (from <= to) {
+      mid = (from + to) >>> 1;
+      if (value > array[mid]) {
+        from = mid + 1;
+      } else if (value == array[mid]) {
+        return mid;
+      } else {
+        to = mid - 1;
+      }
+    }
+    if (mid < 0) {
+      return -1;
+    }
+    return -mid - (value < array[mid] ? 1 : 2);
+  }
+
+  private static boolean lessThan(double double1, double double2) {
+    // A slightly specialized version of
+    // Double.compare(double1, double2) < 0.
+
+    // Non-zero and non-NaN checking.
+    if (double1 < double2) {
+      return true;
+    }
+    if (double1 > double2) {
+      return false;
+    }
+    if (double1 == double2 && double1 != 0.0) {
+      return false;
+    }
+
+    // NaNs are equal to other NaNs and larger than any other double.
+    if (Double.isNaN(double1)) {
+      return false;
+    }
+    if (Double.isNaN(double2)) {
+      return true;
+    }
+
+    // Deal with +0.0 and -0.0.
+    long d1 = Double.doubleToRawLongBits(double1);
+    long d2 = Double.doubleToRawLongBits(double2);
+    return d1 < d2;
+  }
+
+  private static boolean lessThan(float float1, float float2) {
+    // A slightly specialized version of Float.compare(float1, float2) < 0.
+
+    // Non-zero and non-NaN checking.
+    if (float1 < float2) {
+      return true;
+    }
+    if (float1 > float2) {
+      return false;
+    }
+    if (float1 == float2 && float1 != 0.0f) {
+      return false;
+    }
+
+    // NaNs are equal to other NaNs and larger than any other float
+    if (Float.isNaN(float1)) {
+      return false;
+    }
+    if (Float.isNaN(float2)) {
+      return true;
+    }
+
+    // Deal with +0.0 and -0.0
+    int f1 = Float.floatToRawIntBits(float1);
+    int f2 = Float.floatToRawIntBits(float2);
+    return f1 < f2;
+  }
+}

Modified: mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedSparseBinaryMatrix.java
URL: http://svn.apache.org/viewvc/mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedSparseBinaryMatrix.java?rev=1463115&r1=1463114&r2=1463115&view=diff
==============================================================================
--- mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedSparseBinaryMatrix.java (original)
+++ mahout/trunk/math/src/main/java/org/apache/mahout/math/FileBasedSparseBinaryMatrix.java Mon Apr  1 09:18:12 2013
@@ -70,7 +70,7 @@ public final class FileBasedSparseBinary
     super(rows, columns);
   }
 
-  public void setData(File f, boolean loadNow) throws IOException {
+  public void setData(File f) throws IOException {
     List<ByteBuffer> buffers = Lists.newArrayList();
     FileChannel input = new FileInputStream(f).getChannel();
 
@@ -277,14 +277,14 @@ public final class FileBasedSparseBinary
     tmp.position(rowOffset[rowIndex]);
     tmp.limit(rowOffset[rowIndex] + rowSize[rowIndex]);
     tmp = tmp.slice();
-    return new SparseBinaryVector(rowSize[rowIndex], tmp, columnSize());
+    return new SparseBinaryVector(tmp, columnSize());
   }
 
   private static class SparseBinaryVector extends AbstractVector {
     private final IntBuffer buffer;
     private final int maxIndex;
 
-    private SparseBinaryVector(int size, IntBuffer buffer, int maxIndex) {
+    private SparseBinaryVector(IntBuffer buffer, int maxIndex) {
       super(maxIndex);
       this.buffer = buffer;
       this.maxIndex = maxIndex;
@@ -344,7 +344,6 @@ public final class FileBasedSparseBinary
     public Iterator<Element> iterator() {
       return new AbstractIterator<Element>() {
         int i = 0;
-        int index = 0;
 
         @Override
         protected Element computeNext() {