Apache Lucene open-source search software
LUCENE-8174: Fixed toString method of (Double|Float|Int|Long)Range classes.
Oliver Kaleskec4c6b2a7962b
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 7e0033a1e32..425f97f4464 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -174,6 +174,9 @@ Bug Fixes* LUCENE-8163: BaseDirectoryTestCase could produce random filenames that failon 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.diff --git a/lucene/core/src/java/org/apache/lucene/document/DoubleRange.java b/lucene/core/src/java/org/apache/lucene/document/DoubleRange.javaindex c1d2dc50aac..cf308c37a6f 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('>');diff --git a/lucene/core/src/java/org/apache/lucene/document/FloatRange.java b/lucene/core/src/java/org/apache/lucene/document/FloatRange.javaindex facf23b660f..9b555d68f7a 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('>');diff --git a/lucene/core/src/java/org/apache/lucene/document/IntRange.java b/lucene/core/src/java/org/apache/lucene/document/IntRange.javaindex b4266133bfe..e67b94f31d6 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('>');diff --git a/lucene/core/src/java/org/apache/lucene/document/LongRange.java b/lucene/core/src/java/org/apache/lucene/document/LongRange.javaindex 5c1c7632c69..1a1b19a5a8e 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('>');diff --git a/lucene/core/src/test/org/apache/lucene/document/TestDoubleRange.java b/lucene/core/src/test/org/apache/lucene/document/TestDoubleRange.javanew file mode 100644index 00000000000..8e27831f29d--- /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());+ }+}diff --git a/lucene/core/src/test/org/apache/lucene/document/TestFloatRange.java b/lucene/core/src/test/org/apache/lucene/document/TestFloatRange.javanew file mode 100644index 00000000000..e36c85acff1--- /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());+ }+}diff --git a/lucene/core/src/test/org/apache/lucene/document/TestIntRange.java b/lucene/core/src/test/org/apache/lucene/document/TestIntRange.javanew file mode 100644index 00000000000..0ee39d4d371--- /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());+ }+}diff --git a/lucene/core/src/test/org/apache/lucene/document/TestLongRange.java b/lucene/core/src/test/org/apache/lucene/document/TestLongRange.javanew file mode 100644index 00000000000..b0ddd46d919--- /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());+ }+}