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>
This commit is contained in:
Oliver Kaleske 2018-02-15 11:30:02 +01:00 committed by Adrien Grand
parent a07493d508
commit c4c6b2a796
9 changed files with 116 additions and 8 deletions

View File

@ -174,6 +174,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.

View File

@ -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('>');

View File

@ -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('>');

View File

@ -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('>');

View File

@ -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('>');

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}

View File

@ -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());
}
}