You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2016/02/14 00:50:20 UTC

lucene-solr git commit: LUCENE-7028: Remove duplicate method in LegacyNumericUtils

Repository: lucene-solr
Updated Branches:
  refs/heads/master 42ae21cb9 -> 74421d729


LUCENE-7028: Remove duplicate method in LegacyNumericUtils


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/74421d72
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/74421d72
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/74421d72

Branch: refs/heads/master
Commit: 74421d729b5a04f9342a90ef950e7ece4c113de6
Parents: 42ae21c
Author: Uwe Schindler <us...@apache.org>
Authored: Sun Feb 14 00:49:21 2016 +0100
Committer: Uwe Schindler <us...@apache.org>
Committed: Sun Feb 14 00:49:21 2016 +0100

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  3 ++
 .../apache/lucene/util/LegacyNumericUtils.java  | 45 +++++---------------
 .../lucene/search/TestNumericRangeQuery32.java  |  4 +-
 .../lucene/search/TestNumericRangeQuery64.java  |  4 +-
 .../lucene/util/TestLegacyNumericUtils.java     | 12 +++---
 .../lucene/search/join/TestBlockJoin.java       |  2 +-
 .../lucene/spatial/bbox/BBoxStrategy.java       |  2 +-
 .../java/org/apache/solr/schema/TrieField.java  | 26 +++++------
 8 files changed, 38 insertions(+), 60 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/74421d72/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index aa603ba..8a34d07 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -90,6 +90,9 @@ API Changes
 * LUCENE-6947: SortField.missingValue is now protected. You can read its value
   using the new SortField.getMissingValue getter. (Adrien Grand)
 
+* LUCENE-7028: Remove duplicate method in LegacyNumericUtils.
+  (Uwe Schindler)
+
 Optimizations
 
 * LUCENE-6891: Use prefix coding when writing points in 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/74421d72/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java b/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java
index 3cada71..b41b5f0 100644
--- a/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java
+++ b/lucene/core/src/java/org/apache/lucene/util/LegacyNumericUtils.java
@@ -91,7 +91,7 @@ public final class LegacyNumericUtils {
   /**
    * The maximum term length (used for <code>byte[]</code> buffer size)
    * for encoding <code>long</code> values.
-   * @see #longToPrefixCodedBytes
+   * @see #longToPrefixCoded
    */
   public static final int BUF_SIZE_LONG = 63/7 + 2;
 
@@ -104,7 +104,7 @@ public final class LegacyNumericUtils {
   /**
    * The maximum term length (used for <code>byte[]</code> buffer size)
    * for encoding <code>int</code> values.
-   * @see #intToPrefixCodedBytes
+   * @see #intToPrefixCoded
    */
   public static final int BUF_SIZE_INT = 31/7 + 2;
 
@@ -117,30 +117,6 @@ public final class LegacyNumericUtils {
    * @param bytes will contain the encoded value
    */
   public static void longToPrefixCoded(final long val, final int shift, final BytesRefBuilder bytes) {
-    longToPrefixCodedBytes(val, shift, bytes);
-  }
-
-  /**
-   * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.
-   * This is method is used by {@link org.apache.lucene.analysis.LegacyNumericTokenStream}.
-   * After encoding, {@code bytes.offset} will always be 0.
-   * @param val the numeric value
-   * @param shift how many bits to strip from the right
-   * @param bytes will contain the encoded value
-   */
-  public static void intToPrefixCoded(final int val, final int shift, final BytesRefBuilder bytes) {
-    intToPrefixCodedBytes(val, shift, bytes);
-  }
-
-  /**
-   * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.
-   * This is method is used by {@link org.apache.lucene.analysis.LegacyNumericTokenStream}.
-   * After encoding, {@code bytes.offset} will always be 0.
-   * @param val the numeric value
-   * @param shift how many bits to strip from the right
-   * @param bytes will contain the encoded value
-   */
-  public static void longToPrefixCodedBytes(final long val, final int shift, final BytesRefBuilder bytes) {
     // ensure shift is 0..63
     if ((shift & ~0x3f) != 0) {
       throw new IllegalArgumentException("Illegal shift value, must be 0..63; got shift=" + shift);
@@ -159,16 +135,15 @@ public final class LegacyNumericUtils {
     }
   }
 
-
   /**
    * Returns prefix coded bits after reducing the precision by <code>shift</code> bits.
    * This is method is used by {@link org.apache.lucene.analysis.LegacyNumericTokenStream}.
-   * After encoding, {@code bytes.offset} will always be 0. 
+   * After encoding, {@code bytes.offset} will always be 0.
    * @param val the numeric value
    * @param shift how many bits to strip from the right
    * @param bytes will contain the encoded value
    */
-  public static void intToPrefixCodedBytes(final int val, final int shift, final BytesRefBuilder bytes) {
+  public static void intToPrefixCoded(final int val, final int shift, final BytesRefBuilder bytes) {
     // ensure shift is 0..31
     if ((shift & ~0x1f) != 0) {
       throw new IllegalArgumentException("Illegal shift value, must be 0..31; got shift=" + shift);
@@ -218,7 +193,7 @@ public final class LegacyNumericUtils {
    * This method can be used to decode a term's value.
    * @throws NumberFormatException if the supplied {@link BytesRef} is
    * not correctly prefix encoded.
-   * @see #longToPrefixCodedBytes
+   * @see #longToPrefixCoded
    */
   public static long prefixCodedToLong(final BytesRef val) {
     long sortableBits = 0L;
@@ -242,7 +217,7 @@ public final class LegacyNumericUtils {
    * This method can be used to decode a term's value.
    * @throws NumberFormatException if the supplied {@link BytesRef} is
    * not correctly prefix encoded.
-   * @see #intToPrefixCodedBytes
+   * @see #intToPrefixCoded
    */
   public static int prefixCodedToInt(final BytesRef val) {
     int sortableBits = 0;
@@ -427,8 +402,8 @@ public final class LegacyNumericUtils {
      */
     public void addRange(final long min, final long max, final int shift) {
       final BytesRefBuilder minBytes = new BytesRefBuilder(), maxBytes = new BytesRefBuilder();
-      longToPrefixCodedBytes(min, shift, minBytes);
-      longToPrefixCodedBytes(max, shift, maxBytes);
+      longToPrefixCoded(min, shift, minBytes);
+      longToPrefixCoded(max, shift, maxBytes);
       addRange(minBytes.get(), maxBytes.get());
     }
   
@@ -456,8 +431,8 @@ public final class LegacyNumericUtils {
      */
     public void addRange(final int min, final int max, final int shift) {
       final BytesRefBuilder minBytes = new BytesRefBuilder(), maxBytes = new BytesRefBuilder();
-      intToPrefixCodedBytes(min, shift, minBytes);
-      intToPrefixCodedBytes(max, shift, maxBytes);
+      intToPrefixCoded(min, shift, minBytes);
+      intToPrefixCoded(max, shift, maxBytes);
       addRange(minBytes.get(), maxBytes.get());
     }
   

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/74421d72/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
index 3ddff3a..b9d5197 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
@@ -361,9 +361,9 @@ public class TestNumericRangeQuery32 extends LuceneTestCase {
       }
       final BytesRef lowerBytes, upperBytes;
       BytesRefBuilder b = new BytesRefBuilder();
-      LegacyNumericUtils.intToPrefixCodedBytes(lower, 0, b);
+      LegacyNumericUtils.intToPrefixCoded(lower, 0, b);
       lowerBytes = b.toBytesRef();
-      LegacyNumericUtils.intToPrefixCodedBytes(upper, 0, b);
+      LegacyNumericUtils.intToPrefixCoded(upper, 0, b);
       upperBytes = b.toBytesRef();
 
       // test inclusive range

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/74421d72/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
index 19ff240..7d03fae 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
@@ -385,9 +385,9 @@ public class TestNumericRangeQuery64 extends LuceneTestCase {
       }
       final BytesRef lowerBytes, upperBytes;
       BytesRefBuilder b = new BytesRefBuilder();
-      LegacyNumericUtils.longToPrefixCodedBytes(lower, 0, b);
+      LegacyNumericUtils.longToPrefixCoded(lower, 0, b);
       lowerBytes = b.toBytesRef();
-      LegacyNumericUtils.longToPrefixCodedBytes(upper, 0, b);
+      LegacyNumericUtils.longToPrefixCoded(upper, 0, b);
       upperBytes = b.toBytesRef();
       
       // test inclusive range

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/74421d72/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java b/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java
index ce32352..1d9c41e 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestLegacyNumericUtils.java
@@ -29,7 +29,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {
     BytesRefBuilder last = new BytesRefBuilder();
     BytesRefBuilder act = new BytesRefBuilder();
     for (long l=-100000L; l<100000L; l++) {
-      LegacyNumericUtils.longToPrefixCodedBytes(l, 0, act);
+      LegacyNumericUtils.longToPrefixCoded(l, 0, act);
       if (last!=null) {
         // test if smaller
         assertTrue("actual bigger than last (BytesRef)", last.get().compareTo(act.get()) < 0 );
@@ -47,7 +47,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {
     BytesRefBuilder act = new BytesRefBuilder();
     BytesRefBuilder last = new BytesRefBuilder();
     for (int i=-100000; i<100000; i++) {
-      LegacyNumericUtils.intToPrefixCodedBytes(i, 0, act);
+      LegacyNumericUtils.intToPrefixCoded(i, 0, act);
       if (last!=null) {
         // test if smaller
         assertTrue("actual bigger than last (BytesRef)", last.get().compareTo(act.get()) < 0 );
@@ -69,7 +69,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {
     
     for (int i=0; i<vals.length; i++) {
       prefixVals[i] = new BytesRefBuilder();
-      LegacyNumericUtils.longToPrefixCodedBytes(vals[i], 0, prefixVals[i]);
+      LegacyNumericUtils.longToPrefixCoded(vals[i], 0, prefixVals[i]);
       
       // check forward and back conversion
       assertEquals( "forward and back conversion should generate same long", vals[i], LegacyNumericUtils.prefixCodedToLong(prefixVals[i].get()) );
@@ -92,7 +92,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {
     final BytesRefBuilder ref = new BytesRefBuilder();
     for (int i=0; i<vals.length; i++) {
       for (int j=0; j<64; j++) {
-        LegacyNumericUtils.longToPrefixCodedBytes(vals[i], j, ref);
+        LegacyNumericUtils.longToPrefixCoded(vals[i], j, ref);
         long prefixVal= LegacyNumericUtils.prefixCodedToLong(ref.get());
         long mask=(1L << j) - 1L;
         assertEquals( "difference between prefix val and original value for "+vals[i]+" with shift="+j, vals[i] & mask, vals[i]-prefixVal );
@@ -109,7 +109,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {
     
     for (int i=0; i<vals.length; i++) {
       prefixVals[i] = new BytesRefBuilder();
-      LegacyNumericUtils.intToPrefixCodedBytes(vals[i], 0, prefixVals[i]);
+      LegacyNumericUtils.intToPrefixCoded(vals[i], 0, prefixVals[i]);
       
       // check forward and back conversion
       assertEquals( "forward and back conversion should generate same int", vals[i], LegacyNumericUtils.prefixCodedToInt(prefixVals[i].get()) );
@@ -132,7 +132,7 @@ public class TestLegacyNumericUtils extends LuceneTestCase {
     final BytesRefBuilder ref = new BytesRefBuilder();
     for (int i=0; i<vals.length; i++) {
       for (int j=0; j<32; j++) {
-        LegacyNumericUtils.intToPrefixCodedBytes(vals[i], j, ref);
+        LegacyNumericUtils.intToPrefixCoded(vals[i], j, ref);
         int prefixVal= LegacyNumericUtils.prefixCodedToInt(ref.get());
         int mask=(1 << j) - 1;
         assertEquals( "difference between prefix val and original value for "+vals[i]+" with shift="+j, vals[i] & mask, vals[i]-prefixVal );

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/74421d72/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
----------------------------------------------------------------------
diff --git a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
index 35b75a6..e331c8a 100644
--- a/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
+++ b/lucene/join/src/test/org/apache/lucene/search/join/TestBlockJoin.java
@@ -616,7 +616,7 @@ public class TestBlockJoin extends LuceneTestCase {
       if (VERBOSE) {
         System.out.println("DELETE parentID=" + deleteID);
       }
-      LegacyNumericUtils.intToPrefixCodedBytes(deleteID, 0, term);
+      LegacyNumericUtils.intToPrefixCoded(deleteID, 0, term);
       w.deleteDocuments(new Term("blockID", term.toBytesRef()));
       joinW.deleteDocuments(new Term("blockID", term.toBytesRef()));
     }

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/74421d72/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
----------------------------------------------------------------------
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
index 9bae0dc..869aa31 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
@@ -581,7 +581,7 @@ public class BBoxStrategy extends SpatialStrategy {
 
   private Query makeNumberTermQuery(String field, double number) {
     BytesRefBuilder bytes = new BytesRefBuilder();
-    LegacyNumericUtils.longToPrefixCodedBytes(LegacyNumericUtils.doubleToSortableLong(number), 0, bytes);
+    LegacyNumericUtils.longToPrefixCoded(LegacyNumericUtils.doubleToSortableLong(number), 0, bytes);
     return new TermQuery(new Term(field, bytes.get()));
   }
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/74421d72/solr/core/src/java/org/apache/solr/schema/TrieField.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/schema/TrieField.java b/solr/core/src/java/org/apache/solr/schema/TrieField.java
index 862d58f..b369e99 100644
--- a/solr/core/src/java/org/apache/solr/schema/TrieField.java
+++ b/solr/core/src/java/org/apache/solr/schema/TrieField.java
@@ -463,19 +463,19 @@ public class TrieField extends PrimitiveFieldType {
     try {
       switch (type) {
         case INTEGER:
-          LegacyNumericUtils.intToPrefixCodedBytes(Integer.parseInt(s), 0, result);
+          LegacyNumericUtils.intToPrefixCoded(Integer.parseInt(s), 0, result);
           break;
         case FLOAT:
-          LegacyNumericUtils.intToPrefixCodedBytes(LegacyNumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, result);
+          LegacyNumericUtils.intToPrefixCoded(LegacyNumericUtils.floatToSortableInt(Float.parseFloat(s)), 0, result);
           break;
         case LONG:
-          LegacyNumericUtils.longToPrefixCodedBytes(Long.parseLong(s), 0, result);
+          LegacyNumericUtils.longToPrefixCoded(Long.parseLong(s), 0, result);
           break;
         case DOUBLE:
-          LegacyNumericUtils.longToPrefixCodedBytes(LegacyNumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result);
+          LegacyNumericUtils.longToPrefixCoded(LegacyNumericUtils.doubleToSortableLong(Double.parseDouble(s)), 0, result);
           break;
         case DATE:
-          LegacyNumericUtils.longToPrefixCodedBytes(DateFormatUtil.parseMath(null, s).getTime(), 0, result);
+          LegacyNumericUtils.longToPrefixCoded(DateFormatUtil.parseMath(null, s).getTime(), 0, result);
           break;
         default:
           throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + type);
@@ -580,17 +580,17 @@ public class TrieField extends PrimitiveFieldType {
     if (val != null) {
       switch (type) {
         case INTEGER:
-          LegacyNumericUtils.intToPrefixCodedBytes(val.intValue(), 0, bytes);
+          LegacyNumericUtils.intToPrefixCoded(val.intValue(), 0, bytes);
           break;
         case FLOAT:
-          LegacyNumericUtils.intToPrefixCodedBytes(LegacyNumericUtils.floatToSortableInt(val.floatValue()), 0, bytes);
+          LegacyNumericUtils.intToPrefixCoded(LegacyNumericUtils.floatToSortableInt(val.floatValue()), 0, bytes);
           break;
         case LONG: //fallthrough!
         case DATE:
-          LegacyNumericUtils.longToPrefixCodedBytes(val.longValue(), 0, bytes);
+          LegacyNumericUtils.longToPrefixCoded(val.longValue(), 0, bytes);
           break;
         case DOUBLE:
-          LegacyNumericUtils.longToPrefixCodedBytes(LegacyNumericUtils.doubleToSortableLong(val.doubleValue()), 0, bytes);
+          LegacyNumericUtils.longToPrefixCoded(LegacyNumericUtils.doubleToSortableLong(val.doubleValue()), 0, bytes);
           break;
         default:
           throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Unknown type for trie field: " + f.name());
@@ -602,7 +602,7 @@ public class TrieField extends PrimitiveFieldType {
         throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Invalid field contents: "+f.name());
       switch (type) {
         case INTEGER:
-          LegacyNumericUtils.intToPrefixCodedBytes(toInt(bytesRef.bytes, bytesRef.offset), 0, bytes);
+          LegacyNumericUtils.intToPrefixCoded(toInt(bytesRef.bytes, bytesRef.offset), 0, bytes);
           break;
         case FLOAT: {
           // WARNING: Code Duplication! Keep in sync with o.a.l.util.LegacyNumericUtils!
@@ -610,12 +610,12 @@ public class TrieField extends PrimitiveFieldType {
           // code in next 2 lines is identical to: int v = LegacyNumericUtils.floatToSortableInt(Float.intBitsToFloat(toInt(arr)));
           int v = toInt(bytesRef.bytes, bytesRef.offset);
           if (v<0) v ^= 0x7fffffff;
-          LegacyNumericUtils.intToPrefixCodedBytes(v, 0, bytes);
+          LegacyNumericUtils.intToPrefixCoded(v, 0, bytes);
           break;
         }
         case LONG: //fallthrough!
         case DATE:
-          LegacyNumericUtils.longToPrefixCodedBytes(toLong(bytesRef.bytes, bytesRef.offset), 0, bytes);
+          LegacyNumericUtils.longToPrefixCoded(toLong(bytesRef.bytes, bytesRef.offset), 0, bytes);
           break;
         case DOUBLE: {
           // WARNING: Code Duplication! Keep in sync with o.a.l.util.LegacyNumericUtils!
@@ -623,7 +623,7 @@ public class TrieField extends PrimitiveFieldType {
           // code in next 2 lines is identical to: long v = LegacyNumericUtils.doubleToSortableLong(Double.longBitsToDouble(toLong(arr)));
           long v = toLong(bytesRef.bytes, bytesRef.offset);
           if (v<0) v ^= 0x7fffffffffffffffL;
-          LegacyNumericUtils.longToPrefixCodedBytes(v, 0, bytes);
+          LegacyNumericUtils.longToPrefixCoded(v, 0, bytes);
           break;
         }
         default: