lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jpou...@apache.org
Subject lucene-solr:branch_7x: LUCENE-8174: Fixed toString method of (Double|Float|Int|Long)Range classes.
Date Thu, 15 Feb 2018 14:22:46 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/branch_7x 08b9de997 -> 1b62572b5


LUCENE-8174: Fixed toString method of (Double|Float|Int|Long)Range classes.

The previous implementation produced an ArrayOutOfBoundsException because of an incorrect
calculation of the dimension index.
Also, the ranges for each dimension were never appended to the StringBuilder at all (which,
however, could not actually be observed due to the exception).

Signed-off-by: Adrien Grand <jpountz@gmail.com>


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

Branch: refs/heads/branch_7x
Commit: 1b62572b585675f25fc62c2dfd2d6d5bcf82a19b
Parents: 08b9de9
Author: Oliver Kaleske <oliver.kaleske@ptvgroup.com>
Authored: Thu Feb 15 11:30:02 2018 +0100
Committer: Adrien Grand <jpountz@gmail.com>
Committed: Thu Feb 15 15:20:19 2018 +0100

----------------------------------------------------------------------
 lucene/CHANGES.txt                              |  3 +++
 .../org/apache/lucene/document/DoubleRange.java |  4 +--
 .../org/apache/lucene/document/FloatRange.java  |  4 +--
 .../org/apache/lucene/document/IntRange.java    |  4 +--
 .../org/apache/lucene/document/LongRange.java   |  4 +--
 .../apache/lucene/document/TestDoubleRange.java | 26 +++++++++++++++++++
 .../apache/lucene/document/TestFloatRange.java  | 27 ++++++++++++++++++++
 .../apache/lucene/document/TestIntRange.java    | 26 +++++++++++++++++++
 .../apache/lucene/document/TestLongRange.java   | 26 +++++++++++++++++++
 9 files changed, 116 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1b62572b/lucene/CHANGES.txt
----------------------------------------------------------------------
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 550805b..bfa7969 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -93,6 +93,9 @@ Bug Fixes
 * LUCENE-8163: BaseDirectoryTestCase could produce random filenames that fail
   on Windows (Alan Woodward)
 
+* LUCENE-8174: Fixed {Float,Double,Int,Long}Range.toString(). (Oliver Kaleske
+  via Adrien Grand)
+
 Other
 
 * LUCENE-8111: IndexOrDocValuesQuery Javadoc references outdated method name.

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1b62572b/lucene/core/src/java/org/apache/lucene/document/DoubleRange.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/DoubleRange.java b/lucene/core/src/java/org/apache/lucene/document/DoubleRange.java
index c1d2dc5..cf308c3 100644
--- a/lucene/core/src/java/org/apache/lucene/document/DoubleRange.java
+++ b/lucene/core/src/java/org/apache/lucene/document/DoubleRange.java
@@ -244,9 +244,9 @@ public class DoubleRange extends Field {
     sb.append(':');
     byte[] b = ((BytesRef)fieldsData).bytes;
     toString(b, 0);
-    for (int d=1; d<type.pointDimensionCount(); ++d) {
+    for (int d = 0; d < type.pointDimensionCount() / 2; ++d) {
       sb.append(' ');
-      toString(b, d);
+      sb.append(toString(b, d));
     }
     sb.append('>');
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1b62572b/lucene/core/src/java/org/apache/lucene/document/FloatRange.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/FloatRange.java b/lucene/core/src/java/org/apache/lucene/document/FloatRange.java
index facf23b..9b555d6 100644
--- a/lucene/core/src/java/org/apache/lucene/document/FloatRange.java
+++ b/lucene/core/src/java/org/apache/lucene/document/FloatRange.java
@@ -244,9 +244,9 @@ public class FloatRange extends Field {
     sb.append(':');
     byte[] b = ((BytesRef)fieldsData).bytes;
     toString(b, 0);
-    for (int d=1; d<type.pointDimensionCount(); ++d) {
+    for (int d = 0; d < type.pointDimensionCount() / 2; ++d) {
       sb.append(' ');
-      toString(b, d);
+      sb.append(toString(b, d));
     }
     sb.append('>');
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1b62572b/lucene/core/src/java/org/apache/lucene/document/IntRange.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/IntRange.java b/lucene/core/src/java/org/apache/lucene/document/IntRange.java
index b426613..e67b94f 100644
--- a/lucene/core/src/java/org/apache/lucene/document/IntRange.java
+++ b/lucene/core/src/java/org/apache/lucene/document/IntRange.java
@@ -244,9 +244,9 @@ public class IntRange extends Field {
     sb.append(':');
     byte[] b = ((BytesRef)fieldsData).bytes;
     toString(b, 0);
-    for (int d=1; d<type.pointDimensionCount(); ++d) {
+    for (int d = 0; d < type.pointDimensionCount() / 2; ++d) {
       sb.append(' ');
-      toString(b, d);
+      sb.append(toString(b, d));
     }
     sb.append('>');
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1b62572b/lucene/core/src/java/org/apache/lucene/document/LongRange.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/LongRange.java b/lucene/core/src/java/org/apache/lucene/document/LongRange.java
index 5c1c763..1a1b19a 100644
--- a/lucene/core/src/java/org/apache/lucene/document/LongRange.java
+++ b/lucene/core/src/java/org/apache/lucene/document/LongRange.java
@@ -242,9 +242,9 @@ public class LongRange extends Field {
     sb.append(':');
     byte[] b = ((BytesRef)fieldsData).bytes;
     toString(b, 0);
-    for (int d=1; d<type.pointDimensionCount(); ++d) {
+    for (int d = 0; d < type.pointDimensionCount() / 2; ++d) {
       sb.append(' ');
-      toString(b, d);
+      sb.append(toString(b, d));
     }
     sb.append('>');
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1b62572b/lucene/core/src/test/org/apache/lucene/document/TestDoubleRange.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestDoubleRange.java b/lucene/core/src/test/org/apache/lucene/document/TestDoubleRange.java
new file mode 100644
index 0000000..8e27831
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/document/TestDoubleRange.java
@@ -0,0 +1,26 @@
+/*
+ * 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.lucene.document;
+
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestDoubleRange extends LuceneTestCase {
+  public void testToString() {
+    DoubleRange range = new DoubleRange("foo", new double[] { 0.1, 1.1, 2.1, 3.1 }, new double[]
{ .2, 1.2, 2.2, 3.2 });
+    assertEquals("DoubleRange <foo: [0.1 : 0.2] [1.1 : 1.2] [2.1 : 2.2] [3.1 : 3.2]>",
range.toString());
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1b62572b/lucene/core/src/test/org/apache/lucene/document/TestFloatRange.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestFloatRange.java b/lucene/core/src/test/org/apache/lucene/document/TestFloatRange.java
new file mode 100644
index 0000000..e36c85a
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/document/TestFloatRange.java
@@ -0,0 +1,27 @@
+/*
+ * 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.lucene.document;
+
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestFloatRange extends LuceneTestCase {
+  public void testToString() {
+    FloatRange range = new FloatRange("foo", new float[] { 0.1f, 1.1f, 2.1f, 3.1f },
+        new float[] { 0.2f, 1.2f, 2.2f, 3.2f });
+    assertEquals("FloatRange <foo: [0.1 : 0.2] [1.1 : 1.2] [2.1 : 2.2] [3.1 : 3.2]>",
range.toString());
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1b62572b/lucene/core/src/test/org/apache/lucene/document/TestIntRange.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestIntRange.java b/lucene/core/src/test/org/apache/lucene/document/TestIntRange.java
new file mode 100644
index 0000000..0ee39d4
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/document/TestIntRange.java
@@ -0,0 +1,26 @@
+/*
+ * 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.lucene.document;
+
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestIntRange extends LuceneTestCase {
+  public void testToString() {
+    IntRange range = new IntRange("foo", new int[] { 1, 11, 21, 31 }, new int[] { 2, 12,
22, 32 });
+    assertEquals("IntRange <foo: [1 : 2] [11 : 12] [21 : 22] [31 : 32]>", range.toString());
+  }
+}

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/1b62572b/lucene/core/src/test/org/apache/lucene/document/TestLongRange.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLongRange.java b/lucene/core/src/test/org/apache/lucene/document/TestLongRange.java
new file mode 100644
index 0000000..b0ddd46
--- /dev/null
+++ b/lucene/core/src/test/org/apache/lucene/document/TestLongRange.java
@@ -0,0 +1,26 @@
+/*
+ * 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.lucene.document;
+
+import org.apache.lucene.util.LuceneTestCase;
+
+public class TestLongRange extends LuceneTestCase {
+  public void testToString() {
+    LongRange range = new LongRange("foo", new long[] { 1, 11, 21, 31 }, new long[] { 2,
12, 22, 32 });
+    assertEquals("LongRange <foo: [1 : 2] [11 : 12] [21 : 22] [31 : 32]>", range.toString());
+  }
+}


Mime
View raw message