mirror of https://github.com/apache/lucene.git
Remove broken .toArray from IntObjectHashMap entirely (#13876)
This commit is contained in:
parent
d888f6d5a7
commit
af3200ae34
|
@ -562,15 +562,6 @@ public class IntObjectHashMap<VType>
|
|||
public int size() {
|
||||
return IntObjectHashMap.this.size();
|
||||
}
|
||||
|
||||
public VType[] toArray() {
|
||||
VType[] array = (VType[]) new Object[size()];
|
||||
int i = 0;
|
||||
for (ObjectCursor<VType> cursor : this) {
|
||||
array[i++] = cursor.value;
|
||||
}
|
||||
return array;
|
||||
}
|
||||
}
|
||||
|
||||
/** An iterator over the set of assigned values. */
|
||||
|
|
|
@ -18,12 +18,15 @@
|
|||
package org.apache.lucene.internal.hppc;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.RandomizedTest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.apache.lucene.tests.util.LuceneTestCase;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
|
@ -66,10 +69,8 @@ public class TestIntObjectHashMap extends LuceneTestCase {
|
|||
}
|
||||
|
||||
/** Check if the array's content is identical to a given sequence of elements. */
|
||||
private static void assertSortedListEquals(Object[] array, Object... elements) {
|
||||
assertEquals(elements.length, array.length);
|
||||
Arrays.sort(array);
|
||||
assertArrayEquals(elements, array);
|
||||
private static void assertSortedListEquals(List<Object> array, Object... elements) {
|
||||
Assert.assertEquals(Arrays.asList(elements), array.stream().sorted().toList());
|
||||
}
|
||||
|
||||
private final int value0 = vcast(0);
|
||||
|
@ -584,13 +585,21 @@ public class TestIntObjectHashMap extends LuceneTestCase {
|
|||
map.put(key1, value3);
|
||||
map.put(key2, value2);
|
||||
map.put(key3, value1);
|
||||
assertSortedListEquals(map.values().toArray(), value1, value2, value3);
|
||||
assertSortedListEquals(toList(map.values()), value1, value2, value3);
|
||||
|
||||
map.clear();
|
||||
map.put(key1, value1);
|
||||
map.put(key2, value2);
|
||||
map.put(key3, value2);
|
||||
assertSortedListEquals(map.values().toArray(), value1, value2, value2);
|
||||
assertSortedListEquals(toList(map.values()), value1, value2, value2);
|
||||
}
|
||||
|
||||
private static <T> List<T> toList(Iterable<ObjectCursor<T>> values) {
|
||||
ArrayList<T> list = new ArrayList<>();
|
||||
for (var c : values) {
|
||||
list.add(c.value);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/* */
|
||||
|
|
Loading…
Reference in New Issue