Skip to content

Commit fa77d97

Browse files
Remove broken .toArray from Long/CharObjectHashMap entirely (#13884)
1 parent 5f0d1fb commit fa77d97

File tree

6 files changed

+18
-37
lines changed

6 files changed

+18
-37
lines changed

lucene/CHANGES.txt

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Bug Fixes
5353
---------------------
5454
* GITHUB#13832: Fixed an issue where the DefaultPassageFormatter.format method did not format passages as intended
5555
when they were not sorted by startOffset. (Seunghan Jung)
56+
* GITHUB#13884: Remove broken .toArray from Long/CharObjectHashMap entirely. (Pan Guixin)
5657

5758
Build
5859
---------------------

lucene/core/src/java/org/apache/lucene/internal/hppc/CharObjectHashMap.java

-9
Original file line numberDiff line numberDiff line change
@@ -574,15 +574,6 @@ public Iterator<ObjectCursor<VType>> iterator() {
574574
public int size() {
575575
return CharObjectHashMap.this.size();
576576
}
577-
578-
public VType[] toArray() {
579-
VType[] array = (VType[]) new Object[size()];
580-
int i = 0;
581-
for (ObjectCursor<VType> cursor : this) {
582-
array[i++] = cursor.value;
583-
}
584-
return array;
585-
}
586577
}
587578

588579
/** An iterator over the set of assigned values. */

lucene/core/src/java/org/apache/lucene/internal/hppc/LongObjectHashMap.java

-9
Original file line numberDiff line numberDiff line change
@@ -562,15 +562,6 @@ public Iterator<ObjectCursor<VType>> iterator() {
562562
public int size() {
563563
return LongObjectHashMap.this.size();
564564
}
565-
566-
public VType[] toArray() {
567-
VType[] array = (VType[]) new Object[size()];
568-
int i = 0;
569-
for (ObjectCursor<VType> cursor : this) {
570-
array[i++] = cursor.value;
571-
}
572-
return array;
573-
}
574565
}
575566

576567
/** An iterator over the set of assigned values. */

lucene/core/src/test/org/apache/lucene/internal/hppc/TestCharObjectHashMap.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
package org.apache.lucene.internal.hppc;
1919

20+
import static org.apache.lucene.internal.hppc.TestIntObjectHashMap.toList;
21+
2022
import com.carrotsearch.randomizedtesting.RandomizedTest;
2123
import java.util.Arrays;
2224
import java.util.HashMap;
2325
import java.util.HashSet;
2426
import java.util.Random;
2527
import java.util.concurrent.atomic.AtomicInteger;
2628
import org.apache.lucene.tests.util.LuceneTestCase;
29+
import org.hamcrest.MatcherAssert;
30+
import org.hamcrest.Matchers;
2731
import org.junit.After;
2832
import org.junit.Test;
2933

@@ -66,13 +70,6 @@ private static void assertSortedListEquals(char[] array, char... elements) {
6670
assertArrayEquals(elements, array);
6771
}
6872

69-
/** Check if the array's content is identical to a given sequence of elements. */
70-
private static void assertSortedListEquals(Object[] array, Object... elements) {
71-
assertEquals(elements.length, array.length);
72-
Arrays.sort(array);
73-
assertArrayEquals(elements, array);
74-
}
75-
7673
private final int value0 = vcast(0);
7774
private final int value1 = vcast(1);
7875
private final int value2 = vcast(2);
@@ -603,13 +600,15 @@ public void testMapValues() {
603600
map.put(key1, value3);
604601
map.put(key2, value2);
605602
map.put(key3, value1);
606-
assertSortedListEquals(map.values().toArray(), value1, value2, value3);
603+
MatcherAssert.assertThat(
604+
toList(map.values()), Matchers.containsInAnyOrder(value1, value2, value3));
607605

608606
map.clear();
609607
map.put(key1, value1);
610608
map.put(key2, value2);
611609
map.put(key3, value2);
612-
assertSortedListEquals(map.values().toArray(), value1, value2, value2);
610+
MatcherAssert.assertThat(
611+
toList(map.values()), Matchers.containsInAnyOrder(value1, value2, value2));
613612
}
614613

615614
/* */

lucene/core/src/test/org/apache/lucene/internal/hppc/TestIntObjectHashMap.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public void testMapValues() {
594594
assertSortedListEquals(toList(map.values()), value1, value2, value2);
595595
}
596596

597-
private static <T> List<T> toList(Iterable<ObjectCursor<T>> values) {
597+
static <T> List<T> toList(Iterable<ObjectCursor<T>> values) {
598598
ArrayList<T> list = new ArrayList<>();
599599
for (var c : values) {
600600
list.add(c.value);

lucene/core/src/test/org/apache/lucene/internal/hppc/TestLongObjectHashMap.java

+8-9
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,17 @@
1717

1818
package org.apache.lucene.internal.hppc;
1919

20+
import static org.apache.lucene.internal.hppc.TestIntObjectHashMap.toList;
21+
2022
import com.carrotsearch.randomizedtesting.RandomizedTest;
2123
import java.util.Arrays;
2224
import java.util.HashMap;
2325
import java.util.HashSet;
2426
import java.util.Random;
2527
import java.util.concurrent.atomic.AtomicInteger;
2628
import org.apache.lucene.tests.util.LuceneTestCase;
29+
import org.hamcrest.MatcherAssert;
30+
import org.hamcrest.Matchers;
2731
import org.junit.Test;
2832

2933
/**
@@ -65,13 +69,6 @@ private static void assertSortedListEquals(long[] array, long... elements) {
6569
assertArrayEquals(elements, array);
6670
}
6771

68-
/** Check if the array's content is identical to a given sequence of elements. */
69-
private static void assertSortedListEquals(Object[] array, Object... elements) {
70-
assertEquals(elements.length, array.length);
71-
Arrays.sort(array);
72-
assertArrayEquals(elements, array);
73-
}
74-
7572
private final int value0 = vcast(0);
7673
private final int value1 = vcast(1);
7774
private final int value2 = vcast(2);
@@ -585,13 +582,15 @@ public void testMapValues() {
585582
map.put(key1, value3);
586583
map.put(key2, value2);
587584
map.put(key3, value1);
588-
assertSortedListEquals(map.values().toArray(), value1, value2, value3);
585+
MatcherAssert.assertThat(
586+
toList(map.values()), Matchers.containsInAnyOrder(value1, value2, value3));
589587

590588
map.clear();
591589
map.put(key1, value1);
592590
map.put(key2, value2);
593591
map.put(key3, value2);
594-
assertSortedListEquals(map.values().toArray(), value1, value2, value2);
592+
MatcherAssert.assertThat(
593+
toList(map.values()), Matchers.containsInAnyOrder(value1, value2, value2));
595594
}
596595

597596
/* */

0 commit comments

Comments
 (0)