Index: lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedTermFreqIteratorWrapper.java
===================================================================
--- lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedTermFreqIteratorWrapper.java	(révision 1457767)
+++ lucene/suggest/src/java/org/apache/lucene/search/suggest/SortedTermFreqIteratorWrapper.java	(copie de travail)
@@ -120,13 +120,7 @@
       if (cmp != 0) {
         return cmp;
       }
-      if (leftCost < rightCost) {
-        return -1;
-      } else if (rightCost < leftCost) {
-        return 1;
-      } else {
-        return 0;
-      }
+      return Long.compare(leftCost, rightCost);
     }
   };
   
Index: lucene/core/src/test/org/apache/lucene/util/TestSorterTemplate.java
===================================================================
--- lucene/core/src/test/org/apache/lucene/util/TestSorterTemplate.java	(révision 1457767)
+++ lucene/core/src/test/org/apache/lucene/util/TestSorterTemplate.java	(copie de travail)
@@ -44,7 +44,7 @@
       // only compare the last 32 bits
       final long a = i & 0xFFFFFFFFL;
       final long b = j & 0xFFFFFFFFL;
-      return a < b ? -1 : a == b ? 0 : 1;
+      return Long.compare(a, b);
     }
 
     @Override
Index: lucene/core/src/java/org/apache/lucene/search/SearcherLifetimeManager.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/search/SearcherLifetimeManager.java	(révision 1457767)
+++ lucene/core/src/java/org/apache/lucene/search/SearcherLifetimeManager.java	(copie de travail)
@@ -119,16 +119,7 @@
     // Newer searchers are sort before older ones:
     @Override
     public int compareTo(SearcherTracker other) {
-      // Be defensive: cannot subtract since it could
-      // technically overflow long, though, we'd never hit
-      // that in practice:
-      if (recordTimeSec < other.recordTimeSec) {
-        return 1;
-      } else if (other.recordTimeSec < recordTimeSec) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Double.compare(other.recordTimeSec, recordTimeSec);
     }
 
     @Override
Index: lucene/core/src/java/org/apache/lucene/search/FieldComparator.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/search/FieldComparator.java	(révision 1457767)
+++ lucene/core/src/java/org/apache/lucene/search/FieldComparator.java	(copie de travail)
@@ -19,7 +19,6 @@
 
 import java.io.IOException;
 
-import org.apache.lucene.index.AtomicReader; // javadocs
 import org.apache.lucene.index.AtomicReaderContext;
 import org.apache.lucene.index.BinaryDocValues;
 import org.apache.lucene.index.SortedDocValues;
@@ -235,7 +234,7 @@
 
     @Override
     public int compare(int slot1, int slot2) {
-      return values[slot1] - values[slot2];
+      return Byte.compare(values[slot1], values[slot2]);
     }
 
     @Override
@@ -247,7 +246,7 @@
         v2 = missingValue;
       }
 
-      return bottom - v2;
+      return Byte.compare(bottom, v2);
     }
 
     @Override
@@ -287,7 +286,7 @@
       if (docsWithField != null && docValue == 0 && !docsWithField.get(doc)) {
         docValue = missingValue;
       }
-      return docValue - value.byteValue();
+      return Byte.compare(docValue, value.byteValue());
     }
   }
 
@@ -307,15 +306,7 @@
 
     @Override
     public int compare(int slot1, int slot2) {
-      final double v1 = values[slot1];
-      final double v2 = values[slot2];
-      if (v1 > v2) {
-        return 1;
-      } else if (v1 < v2) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Double.compare(values[slot1], values[slot2]);
     }
 
     @Override
@@ -327,13 +318,7 @@
         v2 = missingValue;
       }
 
-      if (bottom > v2) {
-        return 1;
-      } else if (bottom < v2) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Double.compare(bottom, v2);
     }
 
     @Override
@@ -375,13 +360,7 @@
       if (docsWithField != null && docValue == 0 && !docsWithField.get(doc)) {
         docValue = missingValue;
       }
-      if (docValue < value) {
-        return -1;
-      } else if (docValue > value) {
-        return 1;
-      } else {
-        return 0;
-      }
+      return Double.compare(docValue, value);
     }
   }
 
@@ -401,17 +380,7 @@
     
     @Override
     public int compare(int slot1, int slot2) {
-      // TODO: are there sneaky non-branch ways to compute
-      // sign of float?
-      final float v1 = values[slot1];
-      final float v2 = values[slot2];
-      if (v1 > v2) {
-        return 1;
-      } else if (v1 < v2) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Float.compare(values[slot1], values[slot2]);
     }
 
     @Override
@@ -423,14 +392,8 @@
       if (docsWithField != null && v2 == 0 && !docsWithField.get(doc)) {
         v2 = missingValue;
       }
-      
-      if (bottom > v2) {
-        return 1;
-      } else if (bottom < v2) {
-        return -1;
-      } else {
-        return 0;
-      }
+
+      return Float.compare(bottom, v2);
     }
 
     @Override
@@ -472,13 +435,7 @@
       if (docsWithField != null && docValue == 0 && !docsWithField.get(doc)) {
         docValue = missingValue;
       }
-      if (docValue < value) {
-        return -1;
-      } else if (docValue > value) {
-        return 1;
-      } else {
-        return 0;
-      }
+      return Float.compare(docValue, value);
     }
   }
 
@@ -498,7 +455,7 @@
 
     @Override
     public int compare(int slot1, int slot2) {
-      return values[slot1] - values[slot2];
+      return Short.compare(values[slot1], values[slot2]);
     }
 
     @Override
@@ -510,7 +467,7 @@
         v2 = missingValue;
       }
 
-      return bottom - v2;
+      return Short.compare(bottom, v2);
     }
 
     @Override
@@ -552,7 +509,7 @@
       if (docsWithField != null && docValue == 0 && !docsWithField.get(doc)) {
         docValue = missingValue;
       }
-      return docValue - value;
+      return Short.compare(docValue, value);
     }
   }
 
@@ -572,27 +529,11 @@
         
     @Override
     public int compare(int slot1, int slot2) {
-      // TODO: there are sneaky non-branch ways to compute
-      // -1/+1/0 sign
-      // Cannot return values[slot1] - values[slot2] because that
-      // may overflow
-      final int v1 = values[slot1];
-      final int v2 = values[slot2];
-      if (v1 > v2) {
-        return 1;
-      } else if (v1 < v2) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Integer.compare(values[slot1], values[slot2]);
     }
 
     @Override
     public int compareBottom(int doc) {
-      // TODO: there are sneaky non-branch ways to compute
-      // -1/+1/0 sign
-      // Cannot return bottom - values[slot2] because that
-      // may overflow
       int v2 = currentReaderValues.get(doc);
       // Test for v2 == 0 to save Bits.get method call for
       // the common case (doc has value and value is non-zero):
@@ -600,13 +541,7 @@
         v2 = missingValue;
       }
 
-      if (bottom > v2) {
-        return 1;
-      } else if (bottom < v2) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Integer.compare(bottom, v2);
     }
 
     @Override
@@ -648,13 +583,7 @@
       if (docsWithField != null && docValue == 0 && !docsWithField.get(doc)) {
         docValue = missingValue;
       }
-      if (docValue < value) {
-        return -1;
-      } else if (docValue > value) {
-        return 1;
-      } else {
-        return 0;
-      }
+      return Integer.compare(docValue, value);
     }
   }
 
@@ -674,17 +603,7 @@
 
     @Override
     public int compare(int slot1, int slot2) {
-      // TODO: there are sneaky non-branch ways to compute
-      // -1/+1/0 sign
-      final long v1 = values[slot1];
-      final long v2 = values[slot2];
-      if (v1 > v2) {
-        return 1;
-      } else if (v1 < v2) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Long.compare(values[slot1], values[slot2]);
     }
 
     @Override
@@ -698,13 +617,7 @@
         v2 = missingValue;
       }
 
-      if (bottom > v2) {
-        return 1;
-      } else if (bottom < v2) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Long.compare(bottom, v2);
     }
 
     @Override
@@ -746,13 +659,7 @@
       if (docsWithField != null && docValue == 0 && !docsWithField.get(doc)) {
         docValue = missingValue;
       }
-      if (docValue < value) {
-        return -1;
-      } else if (docValue > value) {
-        return 1;
-      } else {
-        return 0;
-      }
+      return Long.compare(docValue, value);
     }
   }
 
@@ -773,16 +680,14 @@
 
     @Override
     public int compare(int slot1, int slot2) {
-      final float score1 = scores[slot1];
-      final float score2 = scores[slot2];
-      return score1 > score2 ? -1 : (score1 < score2 ? 1 : 0);
+      return Float.compare(scores[slot2], scores[slot1]);
     }
 
     @Override
     public int compareBottom(int doc) throws IOException {
       float score = scorer.score();
       assert !Float.isNaN(score);
-      return bottom > score ? -1 : (bottom < score ? 1 : 0);
+      return Float.compare(score, bottom);
     }
 
     @Override
@@ -831,15 +736,7 @@
       final float value = valueObj.floatValue();
       float docValue = scorer.score();
       assert !Float.isNaN(docValue);
-      if (docValue < value) {
-        // reverse of FloatComparator
-        return 1;
-      } else if (docValue > value) {
-        // reverse of FloatComparator
-        return -1;
-      } else {
-        return 0;
-      }
+      return Float.compare(value, docValue);
     }
   }
 
@@ -893,13 +790,7 @@
     public int compareDocToValue(int doc, Integer valueObj) {
       final int value = valueObj.intValue();
       int docValue = docBase + doc;
-      if (docValue < value) {
-        return -1;
-      } else if (docValue > value) {
-        return 1;
-      } else {
-        return 0;
-      }
+      return Integer.compare(docValue, value);
     }
   }
   
Index: lucene/core/src/java/org/apache/lucene/index/LogMergePolicy.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/index/LogMergePolicy.java	(révision 1457767)
+++ lucene/core/src/java/org/apache/lucene/index/LogMergePolicy.java	(copie de travail)
@@ -545,13 +545,7 @@
     // Sorts largest to smallest
     @Override
     public int compareTo(SegmentInfoAndLevel other) {
-      if (level < other.level) {
-        return 1;
-      } else if (level > other.level) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Float.compare(other.level, level);
     }
   }
 
Index: lucene/core/src/java/org/apache/lucene/index/IndexCommit.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/index/IndexCommit.java	(révision 1457767)
+++ lucene/core/src/java/org/apache/lucene/index/IndexCommit.java	(copie de travail)
@@ -119,12 +119,6 @@
 
     long gen = getGeneration();
     long comgen = commit.getGeneration();
-    if (gen < comgen) {
-      return -1;
-    } else if (gen > comgen) {
-      return 1;
-    } else {
-      return 0;
-    }
+    return Long.compare(gen, comgen);
   }
 }
Index: lucene/core/src/java/org/apache/lucene/index/BufferedDeletesStream.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/index/BufferedDeletesStream.java	(révision 1457767)
+++ lucene/core/src/java/org/apache/lucene/index/BufferedDeletesStream.java	(copie de travail)
@@ -134,14 +134,7 @@
   private static final Comparator<SegmentInfoPerCommit> sortSegInfoByDelGen = new Comparator<SegmentInfoPerCommit>() {
     @Override
     public int compare(SegmentInfoPerCommit si1, SegmentInfoPerCommit si2) {
-      final long cmp = si1.getBufferedDeletesGen() - si2.getBufferedDeletesGen();
-      if (cmp > 0) {
-        return 1;
-      } else if (cmp < 0) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Long.compare(si1.getBufferedDeletesGen(), si2.getBufferedDeletesGen());
     }
   };
   
Index: lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java
===================================================================
--- lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java	(révision 1457767)
+++ lucene/highlighter/src/java/org/apache/lucene/search/postingshighlight/Passage.java	(copie de travail)
@@ -76,8 +76,7 @@
 
       @Override
       protected int compare(int i, int j) {
-        // TODO: java7 use Integer.compare(starts[i], starts[j])
-        return Long.signum(((long)starts[i]) - starts[j]);
+        return Integer.compare(starts[i], starts[j]);
       }
 
       @Override
@@ -87,8 +86,7 @@
 
       @Override
       protected int comparePivot(int j) {
-        // TODO: java7 use Integer.compare(pivot, starts[j])
-        return Long.signum(((long)pivot) - starts[j]);
+        return Integer.compare(pivot, starts[j]);
       }
       
       int pivot;
Index: lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java
===================================================================
--- lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java	(révision 1457767)
+++ lucene/queries/src/java/org/apache/lucene/queries/function/ValueSource.java	(copie de travail)
@@ -139,28 +139,12 @@
 
     @Override
     public int compare(int slot1, int slot2) {
-      final double v1 = values[slot1];
-      final double v2 = values[slot2];
-      if (v1 > v2) {
-        return 1;
-      } else if (v1 < v2) {
-        return -1;
-      } else {
-        return 0;
-      }
-
+      return Double.compare(values[slot1], values[slot2]);
     }
 
     @Override
     public int compareBottom(int doc) {
-      final double v2 = docVals.doubleVal(doc);
-      if (bottom > v2) {
-        return 1;
-      } else if (bottom < v2) {
-        return -1;
-      } else {
-        return 0;
-      }
+      return Double.compare(bottom, docVals.doubleVal(doc));
     }
 
     @Override
@@ -188,13 +172,7 @@
     public int compareDocToValue(int doc, Double valueObj) {
       final double value = valueObj;
       final double docValue = docVals.doubleVal(doc);
-      if (docValue < value) {
-        return -1;
-      } else if (docValue > value) {
-        return 1;
-      } else {
-        return 0;
-      }
+      return Double.compare(docValue, value);
     }
   }
 }
Index: lucene/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java
===================================================================
--- lucene/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java	(révision 1457767)
+++ lucene/misc/src/java/org/apache/lucene/misc/HighFreqTerms.java	(copie de travail)
@@ -211,13 +211,7 @@
   
   @Override
   public int compare(TermStats a, TermStats b) {
-    if (a.totalTermFreq < b.totalTermFreq) {
-      return 1;
-    } else if (a.totalTermFreq > b.totalTermFreq) {
-      return -1;
-    } else {
-      return 0;
-    }
+    return Long.compare(b.totalTermFreq, a.totalTermFreq);
   }
 }
 
