From af3200ae340d27590dca4b119d7615de89df910e Mon Sep 17 00:00:00 2001 From: Dawid Weiss Date: Wed, 9 Oct 2024 21:48:08 +0200 Subject: [PATCH] Remove broken .toArray from IntObjectHashMap entirely (#13876) --- .../internal/hppc/IntObjectHashMap.java | 9 -------- .../internal/hppc/TestIntObjectHashMap.java | 21 +++++++++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/internal/hppc/IntObjectHashMap.java b/lucene/core/src/java/org/apache/lucene/internal/hppc/IntObjectHashMap.java index 180bb3249f3..732b0ecb71c 100644 --- a/lucene/core/src/java/org/apache/lucene/internal/hppc/IntObjectHashMap.java +++ b/lucene/core/src/java/org/apache/lucene/internal/hppc/IntObjectHashMap.java @@ -562,15 +562,6 @@ public class IntObjectHashMap public int size() { return IntObjectHashMap.this.size(); } - - public VType[] toArray() { - VType[] array = (VType[]) new Object[size()]; - int i = 0; - for (ObjectCursor cursor : this) { - array[i++] = cursor.value; - } - return array; - } } /** An iterator over the set of assigned values. */ diff --git a/lucene/core/src/test/org/apache/lucene/internal/hppc/TestIntObjectHashMap.java b/lucene/core/src/test/org/apache/lucene/internal/hppc/TestIntObjectHashMap.java index 6c6c0872ede..cc6ac700b54 100644 --- a/lucene/core/src/test/org/apache/lucene/internal/hppc/TestIntObjectHashMap.java +++ b/lucene/core/src/test/org/apache/lucene/internal/hppc/TestIntObjectHashMap.java @@ -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 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 List toList(Iterable> values) { + ArrayList list = new ArrayList<>(); + for (var c : values) { + list.add(c.value); + } + return list; } /* */