From 12d8de86f179ff887e2907d07a2d517d5d961681 Mon Sep 17 00:00:00 2001 From: Adrien Grand Date: Tue, 28 Mar 2017 15:21:35 +0200 Subject: [PATCH] LUCENE-7751: Avoid boxing primitives only to call compareTo. --- lucene/CHANGES.txt | 3 +++ .../core/src/java/org/apache/lucene/util/VirtualMethod.java | 2 +- .../java/org/apache/solr/spelling/SpellCheckCollation.java | 2 +- .../handler/component/DistributedFacetPivotSmallTest.java | 5 ++--- .../src/java/org/apache/solr/common/cloud/DocRouter.java | 4 ++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index e6da58639d3..a8f24c73ff2 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -87,6 +87,9 @@ Other * LUCENE-7754: Inner classes should be static whenever possible. (Daniel Jelinski via Adrien Grand) +* LUCENE-7751: Avoid boxing primitives only to call compareTo. + (Daniel Jelinski via Adrien Grand) + ======================= Lucene 6.5.0 ======================= API Changes diff --git a/lucene/core/src/java/org/apache/lucene/util/VirtualMethod.java b/lucene/core/src/java/org/apache/lucene/util/VirtualMethod.java index f21c16bbda2..ea56862a21c 100644 --- a/lucene/core/src/java/org/apache/lucene/util/VirtualMethod.java +++ b/lucene/core/src/java/org/apache/lucene/util/VirtualMethod.java @@ -143,7 +143,7 @@ public final class VirtualMethod { public static int compareImplementationDistance(final Class clazz, final VirtualMethod m1, final VirtualMethod m2) { - return Integer.valueOf(m1.getImplementationDistance(clazz)).compareTo(m2.getImplementationDistance(clazz)); + return Integer.compare(m1.getImplementationDistance(clazz), m2.getImplementationDistance(clazz)); } } diff --git a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollation.java b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollation.java index bef3ec689f7..7f3bd95080f 100644 --- a/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollation.java +++ b/solr/core/src/java/org/apache/solr/spelling/SpellCheckCollation.java @@ -26,7 +26,7 @@ public class SpellCheckCollation implements Comparable { @Override public int compareTo(SpellCheckCollation scc) { - int c = new Integer(internalRank).compareTo(scc.internalRank); + int c = Integer.compare(internalRank, scc.internalRank); if (c == 0) { return collationQuery.compareTo(scc.collationQuery); } diff --git a/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotSmallTest.java b/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotSmallTest.java index fc7af80dd60..d293e69af25 100644 --- a/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotSmallTest.java +++ b/solr/core/src/test/org/apache/solr/handler/component/DistributedFacetPivotSmallTest.java @@ -1636,8 +1636,7 @@ public class DistributedFacetPivotSmallTest extends BaseDistributedSearchTestCas @Override public int compare(PivotField o1, PivotField o2) { - Integer compare = (Integer.valueOf(o2.getCount())).compareTo(Integer - .valueOf(o1.getCount())); + int compare = Integer.compare(o2.getCount(), o1.getCount()); if (compare == 0) { compare = ((String) o2.getValue()).compareTo((String) o1.getValue()); } @@ -1650,7 +1649,7 @@ public class DistributedFacetPivotSmallTest extends BaseDistributedSearchTestCas } } if (compare == 0) { - compare = Integer.valueOf(o1.getFacetQuery().size()).compareTo( + compare = Integer.compare(o1.getFacetQuery().size(), o2.getFacetQuery().size()); } } diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/DocRouter.java b/solr/solrj/src/java/org/apache/solr/common/cloud/DocRouter.java index 6fffb3a5a79..846c25e7c5c 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/DocRouter.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/DocRouter.java @@ -134,8 +134,8 @@ public abstract class DocRouter { @Override public int compareTo(Range that) { - int mincomp = Integer.valueOf(this.min).compareTo(that.min); - return mincomp == 0 ? Integer.valueOf(this.max).compareTo(that.max) : mincomp; + int mincomp = Integer.compare(this.min, that.min); + return mincomp == 0 ? Integer.compare(this.max, that.max) : mincomp; } }