Apache Lucene open-source search software
Use HashMap#newHashMap and HashSet#newHashSet instead of CollectionUtil#newHashMap and CollectionUtil#newHashSet. (#15517)
zhouhui02c40ba2c229
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 399bd8d1a2f..67767f23d83 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -7,6 +7,9 @@ http://s.apache.org/luceneversionsAPI Changes---------------------+* GITHUB#15517: Remove newHashMap, newHashSet from CollectionUtil, and use HashMap.newHashMap, HashSet.newHashSet+ directly. (Zhou Hui)+* GITHUB#15309: PriorityQueue.remove method has been removed entirely. If you need remove(), implementit yourself in a subclass (heap access and size, upHeap and downHeap are protected members of PQ). (Dawid Weiss)diff --git a/lucene/analysis/common/src/java/org/apache/lucene/analysis/custom/CustomAnalyzer.java b/lucene/analysis/common/src/java/org/apache/lucene/analysis/custom/CustomAnalyzer.javaindex 71906c220ef..a6a41e94c0c 100644--- a/lucene/analysis/common/src/java/org/apache/lucene/analysis/custom/CustomAnalyzer.java+++ b/lucene/analysis/common/src/java/org/apache/lucene/analysis/custom/CustomAnalyzer.java@@ -24,6 +24,7 @@ import java.nio.file.Path;import java.util.ArrayList;import java.util.Arrays;import java.util.Collections;+import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Objects;@@ -41,7 +42,6 @@ import org.apache.lucene.analysis.miscellaneous.ConditionalTokenFilterFactory;import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;import org.apache.lucene.analysis.util.FilesystemResourceLoader;import org.apache.lucene.util.ClasspathResourceLoader;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.ResourceLoader;import org.apache.lucene.util.ResourceLoaderAware;import org.apache.lucene.util.SetOnce;@@ -606,7 +606,8 @@ public final class CustomAnalyzer extends Analyzer {throw new IllegalArgumentException("Key-value pairs expected, so the number of params must be even.");}- final Map<String, String> map = CollectionUtil.newHashMap(params.length / 2);+ // Plus 1 since applyDefaultParams will add a default param later.+ final Map<String, String> map = HashMap.newHashMap(params.length / 2 + 1);for (int i = 0; i < params.length; i += 2) {Objects.requireNonNull(params[i], "Key of param may not be null.");map.put(params[i], params[i + 1]);diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsReader.javaindex 7a096548502..8d578b8fdca 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsReader.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene40/blocktree/Lucene40BlockTreeTermsReader.java@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene40.blocktree;import java.io.IOException;import java.util.ArrayList;import java.util.Collections;+import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;@@ -35,7 +36,6 @@ import org.apache.lucene.index.Terms;import org.apache.lucene.store.ChecksumIndexInput;import org.apache.lucene.store.IndexInput;import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.fst.ByteSequenceOutputs;import org.apache.lucene.util.fst.Outputs;@@ -198,7 +198,7 @@ public final class Lucene40BlockTreeTermsReader extends FieldsProducer {if (numFields < 0) {throw new CorruptIndexException("invalid numFields: " + numFields, termsMetaIn);}- fieldMap = CollectionUtil.newHashMap(numFields);+ fieldMap = HashMap.newHashMap(numFields);for (int i = 0; i < numFields; ++i) {final int field = termsMetaIn.readVInt();final long numTerms = termsMetaIn.readVLong();diff --git a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50CompoundReader.java b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50CompoundReader.javaindex 23cffa6714b..819d45a5328 100644--- a/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50CompoundReader.java+++ b/lucene/backward-codecs/src/java/org/apache/lucene/backward_codecs/lucene50/Lucene50CompoundReader.java@@ -19,6 +19,7 @@ package org.apache.lucene.backward_codecs.lucene50;import java.io.FileNotFoundException;import java.io.IOException;import java.util.Collections;+import java.util.HashMap;import java.util.Map;import java.util.Set;import org.apache.lucene.backward_codecs.store.EndiannessReverserUtil;@@ -31,7 +32,6 @@ import org.apache.lucene.store.ChecksumIndexInput;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.IOUtils;/**@@ -131,7 +131,7 @@ final class Lucene50CompoundReader extends CompoundDirectory {private Map<String, FileEntry> readMapping(IndexInput entriesStream) throws IOException {final int numEntries = entriesStream.readVInt();- Map<String, FileEntry> mapping = CollectionUtil.newHashMap(numEntries);+ Map<String, FileEntry> mapping = HashMap.newHashMap(numEntries);for (int i = 0; i < numEntries; i++) {final FileEntry fileEntry = new FileEntry();final String id = entriesStream.readString();diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestDocValuesCompression.java b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestDocValuesCompression.javaindex 4aae092e2e1..b1ab62c3595 100644--- a/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestDocValuesCompression.java+++ b/lucene/backward-codecs/src/test/org/apache/lucene/backward_codecs/lucene80/TestDocValuesCompression.java@@ -41,7 +41,6 @@ import org.apache.lucene.tests.util.LuceneTestCase;import org.apache.lucene.tests.util.LuceneTestCase.Nightly;import org.apache.lucene.tests.util.TestUtil;import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.CollectionUtil;@Nightly // N-2 formats are only tested on nightly runspublic class TestDocValuesCompression extends LuceneTestCase {@@ -90,7 +89,7 @@ public class TestDocValuesCompression extends LuceneTestCase {public void testReseekAfterSkipDecompression() throws IOException {final int CARDINALITY = (Lucene80DocValuesFormat.TERMS_DICT_BLOCK_LZ4_SIZE << 1) + 11;- Set<String> valueSet = CollectionUtil.newHashSet(CARDINALITY);+ Set<String> valueSet = HashSet.newHashSet(CARDINALITY);for (int i = 0; i < CARDINALITY; i++) {valueSet.add(TestUtil.randomSimpleString(random(), 64));}diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.javaindex 2f707e1241b..30f17e0fdba 100644--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextSegmentInfoFormat.java@@ -20,6 +20,8 @@ import java.io.IOException;import java.nio.charset.StandardCharsets;import java.text.ParseException;import java.util.Arrays;+import java.util.HashMap;+import java.util.HashSet;import java.util.Map;import java.util.Set;import org.apache.lucene.codecs.SegmentInfoFormat;@@ -38,7 +40,6 @@ import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexOutput;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.BytesRefBuilder;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.StringHelper;import org.apache.lucene.util.Version;@@ -120,7 +121,7 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {SimpleTextUtil.readLine(input, scratch);assert StringHelper.startsWith(scratch.get(), SI_NUM_DIAG);int numDiag = Integer.parseInt(readString(SI_NUM_DIAG.length, scratch));- Map<String, String> diagnostics = CollectionUtil.newHashMap(numDiag);+ Map<String, String> diagnostics = HashMap.newHashMap(numDiag);for (int i = 0; i < numDiag; i++) {SimpleTextUtil.readLine(input, scratch);@@ -136,7 +137,7 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {SimpleTextUtil.readLine(input, scratch);assert StringHelper.startsWith(scratch.get(), SI_NUM_ATT);int numAtt = Integer.parseInt(readString(SI_NUM_ATT.length, scratch));- Map<String, String> attributes = CollectionUtil.newHashMap(numAtt);+ Map<String, String> attributes = HashMap.newHashMap(numAtt);for (int i = 0; i < numAtt; i++) {SimpleTextUtil.readLine(input, scratch);@@ -152,7 +153,7 @@ public class SimpleTextSegmentInfoFormat extends SegmentInfoFormat {SimpleTextUtil.readLine(input, scratch);assert StringHelper.startsWith(scratch.get(), SI_NUM_FILES);int numFiles = Integer.parseInt(readString(SI_NUM_FILES.length, scratch));- Set<String> files = CollectionUtil.newHashSet(numFiles);+ Set<String> files = HashSet.newHashSet(numFiles);for (int i = 0; i < numFiles; i++) {SimpleTextUtil.readLine(input, scratch);diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/uniformsplit/sharedterms/STUniformSplitTermsWriter.java b/lucene/codecs/src/java/org/apache/lucene/codecs/uniformsplit/sharedterms/STUniformSplitTermsWriter.javaindex badf681048c..4cac2aff271 100755--- a/lucene/codecs/src/java/org/apache/lucene/codecs/uniformsplit/sharedterms/STUniformSplitTermsWriter.java+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/uniformsplit/sharedterms/STUniformSplitTermsWriter.java@@ -50,7 +50,6 @@ import org.apache.lucene.index.Terms;import org.apache.lucene.index.TermsEnum;import org.apache.lucene.store.ByteBuffersDataOutput;import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.PriorityQueue;/**@@ -337,7 +336,7 @@ public class STUniformSplitTermsWriter extends UniformSplitTermsWriter {createSegmentTermsQueue(segmentTermsList);List<TermIterator<SegmentTerms>> groupedSegmentTerms = new ArrayList<>(segmentTermsList.size());Map<String, List<SegmentPostings>> fieldPostingsMap =- CollectionUtil.newHashMap(mergeState.fieldInfos.length);+ HashMap.newHashMap(mergeState.fieldInfos.length);List<MergingFieldTerms> groupedFieldTerms = new ArrayList<>(mergeState.fieldInfos.length);List<FieldMetadataTermState> termStates = new ArrayList<>(mergeState.fieldInfos.length);@@ -357,8 +356,7 @@ public class STUniformSplitTermsWriter extends UniformSplitTermsWriter {private Map<String, MergingFieldTerms> createMergingFieldTermsMap(List<FieldMetadata> fieldMetadataList, int numSegments) {- Map<String, MergingFieldTerms> fieldTermsMap =- CollectionUtil.newHashMap(fieldMetadataList.size());+ Map<String, MergingFieldTerms> fieldTermsMap = HashMap.newHashMap(fieldMetadataList.size());for (FieldMetadata fieldMetadata : fieldMetadataList) {FieldInfo fieldInfo = fieldMetadata.getFieldInfo();fieldTermsMap.put(diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90CompoundReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90CompoundReader.javaindex 8d986b63983..85a13b4ad79 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90CompoundReader.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene90/Lucene90CompoundReader.java@@ -19,6 +19,7 @@ package org.apache.lucene.codecs.lucene90;import java.io.FileNotFoundException;import java.io.IOException;import java.util.Collections;+import java.util.HashMap;import java.util.Map;import java.util.Set;import org.apache.lucene.codecs.CodecUtil;@@ -30,7 +31,6 @@ import org.apache.lucene.store.ChecksumIndexInput;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexInput;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.IOUtils;/**@@ -126,7 +126,7 @@ final class Lucene90CompoundReader extends CompoundDirectory {private Map<String, FileEntry> readMapping(IndexInput entriesStream) throws IOException {final int numEntries = entriesStream.readVInt();- Map<String, FileEntry> mapping = CollectionUtil.newHashMap(numEntries);+ Map<String, FileEntry> mapping = HashMap.newHashMap(numEntries);for (int i = 0; i < numEntries; i++) {final FileEntry fileEntry = new FileEntry();final String id = entriesStream.readString();diff --git a/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldPostingsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldPostingsFormat.javaindex 5e247c50b5c..18835dff7f0 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldPostingsFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/perfield/PerFieldPostingsFormat.java@@ -43,7 +43,6 @@ import org.apache.lucene.index.MergeState;import org.apache.lucene.index.SegmentReadState;import org.apache.lucene.index.SegmentWriteState;import org.apache.lucene.index.Terms;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.MergedIterator;@@ -254,7 +253,7 @@ public abstract class PerFieldPostingsFormat extends PostingsFormat {}Map<PostingsFormat, FieldsGroup> formatToGroups =- CollectionUtil.newHashMap(formatToGroupBuilders.size());+ HashMap.newHashMap(formatToGroupBuilders.size());formatToGroupBuilders.forEach((postingsFormat, builder) -> formatToGroups.put(postingsFormat, builder.build()));return formatToGroups;diff --git a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.javaindex 269f24bf1fd..52a93ea0186 100644--- a/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java+++ b/lucene/core/src/java/org/apache/lucene/index/FieldInfos.java@@ -35,7 +35,6 @@ import java.util.Set;import java.util.stream.Collectors;import java.util.stream.StreamSupport;import org.apache.lucene.internal.hppc.IntObjectHashMap;-import org.apache.lucene.util.CollectionUtil;/*** Collection of {@link FieldInfo}s (accessible by number or by name).@@ -86,7 +85,7 @@ public class FieldInfos implements Iterable<FieldInfo> {String softDeletesField = null;String parentField = null;- byName = CollectionUtil.newHashMap(infos.length);+ byName = HashMap.newHashMap(infos.length);int maxFieldNumber = -1;boolean fieldNumberStrictlyAscending = true;for (FieldInfo info : infos) {diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.javaindex dac837a3080..595cb3f2caf 100644--- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java+++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java@@ -43,7 +43,6 @@ import org.apache.lucene.store.DataOutput;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;import org.apache.lucene.store.IndexOutput;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.StringHelper;import org.apache.lucene.util.Version;@@ -443,7 +442,7 @@ public final class SegmentInfos implements Cloneable, Iterable<SegmentCommitInfoif (numDVFields == 0) {dvUpdateFiles = Collections.emptyMap();} else {- Map<Integer, Set<String>> map = CollectionUtil.newHashMap(numDVFields);+ Map<Integer, Set<String>> map = HashMap.newHashMap(numDVFields);for (int i = 0; i < numDVFields; i++) {map.put(CodecUtil.readBEInt(input), input.readSetOfStrings());}diff --git a/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java b/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.javaindex 16969ecefdd..03b06944b22 100644--- a/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java+++ b/lucene/core/src/java/org/apache/lucene/index/StandardDirectoryReader.java@@ -23,6 +23,7 @@ import java.util.Arrays;import java.util.Collection;import java.util.Collections;import java.util.Comparator;+import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Set;@@ -34,7 +35,6 @@ import org.apache.lucene.store.AlreadyClosedException;import org.apache.lucene.store.Directory;import org.apache.lucene.store.IOContext;import org.apache.lucene.util.Bits;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.IOFunction;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.Version;@@ -252,7 +252,7 @@ public final class StandardDirectoryReader extends DirectoryReader {Map<String, Integer> previousSegmentReaders = Collections.emptyMap();if (oldReaders != null) {- previousSegmentReaders = CollectionUtil.newHashMap(oldReaders.size());+ previousSegmentReaders = HashMap.newHashMap(oldReaders.size());// create a Map SegmentName->SegmentReaderfor (int i = 0, c = oldReaders.size(); i < c; i++) {final SegmentReader sr = (SegmentReader) oldReaders.get(i);diff --git a/lucene/core/src/java/org/apache/lucene/util/CollectionUtil.java b/lucene/core/src/java/org/apache/lucene/util/CollectionUtil.javaindex 8e66694543a..72c8b517c9c 100644--- a/lucene/core/src/java/org/apache/lucene/util/CollectionUtil.java+++ b/lucene/core/src/java/org/apache/lucene/util/CollectionUtil.java@@ -18,8 +18,6 @@ package org.apache.lucene.util;import java.util.Collections;import java.util.Comparator;-import java.util.HashMap;-import java.util.HashSet;import java.util.List;import java.util.RandomAccess;@@ -34,24 +32,6 @@ public final class CollectionUtil {private CollectionUtil() {} // no instance- /**- * Returns a new {@link HashMap} sized to contain {@code size} items without resizing the internal- * array.- */- public static <K, V> HashMap<K, V> newHashMap(int size) {- // This should be replaced with HashMap.newHashMap when lucene moves to jdk19 minimum version- return new HashMap<>((int) (size / 0.75f) + 1);- }-- /**- * Returns a new {@link HashSet} sized to contain {@code size} items without resizing the internal- * array.- */- public static <E> HashSet<E> newHashSet(int size) {- // This should be replaced with HashSet.newHashSet when lucene moves to jdk19 minimum version- return new HashSet<>((int) (size / 0.75f) + 1);- }-private static final class ListIntroSorter<T> extends IntroSorter {T pivot;diff --git a/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90DocValuesFormat.java b/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90DocValuesFormat.javaindex 489ee868139..feeeaf2e29c 100644--- a/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90DocValuesFormat.java+++ b/lucene/core/src/test/org/apache/lucene/codecs/lucene90/TestLucene90DocValuesFormat.java@@ -71,7 +71,6 @@ import org.apache.lucene.tests.index.RandomIndexWriter;import org.apache.lucene.tests.util.TestUtil;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.BytesRefBuilder;-import org.apache.lucene.util.CollectionUtil;/** Tests Lucene90DocValuesFormat */public class TestLucene90DocValuesFormat extends BaseCompressingDocValuesFormatTestCase {@@ -786,7 +785,7 @@ public class TestLucene90DocValuesFormat extends BaseCompressingDocValuesFormatTpublic void testReseekAfterSkipDecompression() throws IOException {final int CARDINALITY = (Lucene90DocValuesFormat.TERMS_DICT_BLOCK_LZ4_SIZE << 1) + 11;- Set<String> valueSet = CollectionUtil.newHashSet(CARDINALITY);+ Set<String> valueSet = HashSet.newHashSet(CARDINALITY);for (int i = 0; i < CARDINALITY; i++) {valueSet.add(TestUtil.randomSimpleString(random(), 64));}diff --git a/lucene/core/src/test/org/apache/lucene/util/TestSentinelIntSet.java b/lucene/core/src/test/org/apache/lucene/util/TestSentinelIntSet.javaindex bf9785b5838..c73bcfe7e40 100644--- a/lucene/core/src/test/org/apache/lucene/util/TestSentinelIntSet.java+++ b/lucene/core/src/test/org/apache/lucene/util/TestSentinelIntSet.java@@ -51,7 +51,7 @@ public class TestSentinelIntSet extends LuceneTestCase {int maxVal =(random().nextBoolean() ? random().nextInt(50) : random().nextInt(Integer.MAX_VALUE)) + 1;- HashSet<Integer> a = CollectionUtil.newHashSet(initSz);+ HashSet<Integer> a = HashSet.newHashSet(initSz);SentinelIntSet b = new SentinelIntSet(initSz, -1);for (int j = 0; j < num; j++) {diff --git a/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java b/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.javaindex 0e08fb9a544..bcbf06808a3 100644--- a/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java+++ b/lucene/core/src/test/org/apache/lucene/util/bkd/TestDocIdsWriter.java@@ -18,6 +18,7 @@ package org.apache.lucene.util.bkd;import java.io.IOException;import java.util.Arrays;+import java.util.HashSet;import java.util.Set;import org.apache.lucene.index.PointValues.IntersectVisitor;import org.apache.lucene.index.PointValues.Relation;@@ -27,7 +28,6 @@ import org.apache.lucene.store.IndexInput;import org.apache.lucene.store.IndexOutput;import org.apache.lucene.tests.util.LuceneTestCase;import org.apache.lucene.tests.util.TestUtil;-import org.apache.lucene.util.CollectionUtil;public class TestDocIdsWriter extends LuceneTestCase {@@ -91,7 +91,7 @@ public class TestDocIdsWriter extends LuceneTestCase {try (Directory dir = newDirectory()) {for (int iter = 0; iter < numIters; ++iter) {int size = 1 + random().nextInt(5000);- Set<Integer> set = CollectionUtil.newHashSet(size);+ Set<Integer> set = HashSet.newHashSet(size);int small = random().nextInt(1000);while (set.size() < size) {set.add(small + random().nextInt(size * 16));diff --git a/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java b/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.javaindex 3471c4ccabe..802ceb4feaa 100644--- a/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java+++ b/lucene/grouping/src/java/org/apache/lucene/search/grouping/FirstPassGroupingCollector.java@@ -31,7 +31,6 @@ import org.apache.lucene.search.ScoreMode;import org.apache.lucene.search.SimpleCollector;import org.apache.lucene.search.Sort;import org.apache.lucene.search.SortField;-import org.apache.lucene.util.CollectionUtil;/*** FirstPassGroupingCollector is the first of two passes necessary to collect grouped hits. This@@ -120,7 +119,7 @@ public class FirstPassGroupingCollector<T> extends SimpleCollector {}spareSlot = topNGroups;- groupMap = CollectionUtil.newHashMap(topNGroups);+ groupMap = HashMap.newHashMap(topNGroups);}@Overridediff --git a/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java b/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.javaindex b10a64230aa..fadfabb0d68 100644--- a/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java+++ b/lucene/highlighter/src/java/org/apache/lucene/search/highlight/QueryScorer.java@@ -17,6 +17,7 @@package org.apache.lucene.search.highlight;import java.io.IOException;+import java.util.HashMap;import java.util.HashSet;import java.util.Map;import java.util.Set;@@ -28,7 +29,6 @@ import org.apache.lucene.index.IndexReader;import org.apache.lucene.index.memory.MemoryIndex;import org.apache.lucene.queries.spans.SpanQuery;import org.apache.lucene.search.Query;-import org.apache.lucene.util.CollectionUtil;/*** {@link Scorer} implementation which scores text fragments by the number of unique query terms@@ -99,7 +99,7 @@ public class QueryScorer implements Scorer {* @param weightedTerms an array of pre-created {@link WeightedSpanTerm}s*/public QueryScorer(WeightedSpanTerm[] weightedTerms) {- this.fieldWeightedSpanTerms = CollectionUtil.newHashMap(weightedTerms.length);+ this.fieldWeightedSpanTerms = HashMap.newHashMap(weightedTerms.length);for (WeightedSpanTerm weightedTerm : weightedTerms) {WeightedSpanTerm existingTerm = fieldWeightedSpanTerms.get(weightedTerm.term);diff --git a/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java b/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.javaindex 75728bbfee7..0e24931b4bd 100644--- a/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java+++ b/lucene/highlighter/src/java/org/apache/lucene/search/uhighlight/UnifiedHighlighter.java@@ -62,7 +62,6 @@ import org.apache.lucene.search.ScoreDoc;import org.apache.lucene.search.TopDocs;import org.apache.lucene.search.Weight;import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.IOUtils;import org.apache.lucene.util.InPlaceMergeSorter;@@ -1001,7 +1000,7 @@ public class UnifiedHighlighter {// caller simply iterates it to build another structure.// field -> object highlights parallel to docIdsIn- Map<String, Object[]> resultMap = CollectionUtil.newHashMap(fields.length);+ Map<String, Object[]> resultMap = HashMap.newHashMap(fields.length);for (int f = 0; f < fields.length; f++) {resultMap.put(fields[f], highlightDocsInByField[f]);}diff --git a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/messages/NLS.java b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/messages/NLS.javaindex da72b80e19f..ca5883b0168 100644--- a/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/messages/NLS.java+++ b/lucene/queryparser/src/java/org/apache/lucene/queryparser/flexible/messages/NLS.java@@ -24,7 +24,6 @@ import java.util.Locale;import java.util.Map;import java.util.MissingResourceException;import java.util.ResourceBundle;-import org.apache.lucene.util.CollectionUtil;/*** MessageBundles classes extend this class, to implement a bundle.@@ -118,7 +117,7 @@ public class NLS {// build a map of field names to Field objectsfinal int len = fieldArray.length;- Map<String, Field> fields = CollectionUtil.newHashMap(len);+ Map<String, Field> fields = HashMap.newHashMap(len);for (Field field : fieldArray) {fields.put(field.getName(), field);loadfieldValue(field, clazz);diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryLeafProfilerBreakdown.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryLeafProfilerBreakdown.javaindex e53a54c92e5..e76d2639e43 100644--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryLeafProfilerBreakdown.java+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryLeafProfilerBreakdown.java@@ -21,8 +21,8 @@ import java.util.Arrays;import java.util.Collection;import java.util.Collections;import java.util.EnumMap;+import java.util.HashMap;import java.util.Map;-import org.apache.lucene.util.CollectionUtil;/*** A record of timings for the various operations that may happen during query execution. A node's@@ -51,7 +51,7 @@ public class QueryLeafProfilerBreakdown {/** Build a timing count breakdown. */public final Map<String, Long> toBreakdownMap() {- Map<String, Long> map = CollectionUtil.newHashMap(timers.length * 2);+ Map<String, Long> map = HashMap.newHashMap(timers.length * 2);for (QueryProfilerTimingType type : LEAF_LEVEL_TIMING_TYPE) {map.put(type.toString(), timers[type.ordinal()].getApproximateTiming());map.put(type.toString() + "_count", timers[type.ordinal()].getCount());@@ -60,7 +60,7 @@ public class QueryLeafProfilerBreakdown {}public final AggregatedQueryLeafProfilerResult getLeafProfilerResult(Thread thread) {- final Map<String, Long> map = CollectionUtil.newHashMap(LEAF_LEVEL_TIMING_TYPE.size() * 2);+ final Map<String, Long> map = HashMap.newHashMap(LEAF_LEVEL_TIMING_TYPE.size() * 2);long sliceStartTime = Long.MAX_VALUE;long sliceEndTime = Long.MIN_VALUE;for (QueryProfilerTimingType type : LEAF_LEVEL_TIMING_TYPE) {diff --git a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerBreakdown.java b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerBreakdown.javaindex 29e5c09598b..6ef99c54a93 100644--- a/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerBreakdown.java+++ b/lucene/sandbox/src/java/org/apache/lucene/sandbox/search/QueryProfilerBreakdown.java@@ -24,7 +24,6 @@ import java.util.HashMap;import java.util.List;import java.util.Map;import org.apache.lucene.search.Query;-import org.apache.lucene.util.CollectionUtil;/*** A record of timings for the various operations that may happen during query execution. A node's@@ -62,8 +61,7 @@ class QueryProfilerBreakdown {Query query, List<QueryProfilerResult> childrenProfileResults) {long queryStartTime = Long.MAX_VALUE;long queryTotalTime = 0;- final Map<String, Long> breakdownMap =- CollectionUtil.newHashMap(QUERY_LEVEL_TIMING_TYPE.size() * 2);+ final Map<String, Long> breakdownMap = HashMap.newHashMap(QUERY_LEVEL_TIMING_TYPE.size() * 2);for (QueryProfilerTimingType type : QUERY_LEVEL_TIMING_TYPE) {final QueryProfilerTimer timer = queryProfilerTimers.get(type);if (timer.getCount() > 0) {diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.javaindex 3b606b983bb..7e8a9817d13 100644--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConcavePolygon.java@@ -21,9 +21,9 @@ import java.io.InputStream;import java.io.OutputStream;import java.util.ArrayList;import java.util.BitSet;+import java.util.HashMap;import java.util.List;import java.util.Map;-import org.apache.lucene.util.CollectionUtil;/*** GeoConcavePolygon objects are generic building blocks of more complex structures. The only@@ -262,8 +262,8 @@ class GeoConcavePolygon extends GeoBasePolygon {}// For each edge, create a bounds object.- prevBrotherMap = CollectionUtil.newHashMap(edges.length);- nextBrotherMap = CollectionUtil.newHashMap(edges.length);+ prevBrotherMap = HashMap.newHashMap(edges.length);+ nextBrotherMap = HashMap.newHashMap(edges.length);for (int edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {final SidedPlane invertedEdge = invertedEdges[edgeIndex];int bound1Index = legalIndex(edgeIndex + 1);diff --git a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.javaindex 0cbe4120ed4..00122ffd0da 100755--- a/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java+++ b/lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoConvexPolygon.java@@ -21,9 +21,9 @@ import java.io.InputStream;import java.io.OutputStream;import java.util.ArrayList;import java.util.BitSet;+import java.util.HashMap;import java.util.List;import java.util.Map;-import org.apache.lucene.util.CollectionUtil;/*** GeoConvexPolygon objects are generic building blocks of more complex structures. The only@@ -254,8 +254,8 @@ class GeoConvexPolygon extends GeoBasePolygon {}// For each edge, create a bounds object.- prevBrotherMap = CollectionUtil.newHashMap(edges.length);- nextBrotherMap = CollectionUtil.newHashMap(edges.length);+ prevBrotherMap = HashMap.newHashMap(edges.length);+ nextBrotherMap = HashMap.newHashMap(edges.length);for (int edgeIndex = 0; edgeIndex < edges.length; edgeIndex++) {final SidedPlane edge = edges[edgeIndex];int bound1Index = legalIndex(edgeIndex + 1);diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/CompletionFieldsProducer.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/CompletionFieldsProducer.javaindex 1a0d709bdec..7930357e54f 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/CompletionFieldsProducer.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/CompletionFieldsProducer.java@@ -25,6 +25,7 @@ import java.io.IOException;import java.util.ArrayList;import java.util.Collection;import java.util.Collections;+import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;@@ -41,7 +42,6 @@ import org.apache.lucene.store.IndexInput;import org.apache.lucene.store.PreloadHint;import org.apache.lucene.util.Accountable;import org.apache.lucene.util.Accountables;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.IOUtils;/**@@ -105,7 +105,7 @@ final class CompletionFieldsProducer extends FieldsProducer implements Accountab// read suggest field numbers and their offsets in the terms file from indexint numFields = index.readVInt();- readers = CollectionUtil.newHashMap(numFields);+ readers = HashMap.newHashMap(numFields);for (int i = 0; i < numFields; i++) {int fieldNumber = index.readVInt();long offset = index.readVLong();diff --git a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/ContextQuery.java b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/ContextQuery.javaindex 71418f231c8..b9e8d6213fe 100644--- a/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/ContextQuery.java+++ b/lucene/suggest/src/java/org/apache/lucene/search/suggest/document/ContextQuery.java@@ -31,7 +31,6 @@ import org.apache.lucene.search.Weight;import org.apache.lucene.util.Accountable;import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.BytesRefBuilder;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.IntsRef;import org.apache.lucene.util.IntsRefBuilder;import org.apache.lucene.util.RamUsageEstimator;@@ -202,7 +201,7 @@ public class ContextQuery extends CompletionQuery implements Accountable {contextsAutomaton =Operations.determinize(contextsAutomaton, Operations.DEFAULT_DETERMINIZE_WORK_LIMIT);- final Map<IntsRef, Float> contextMap = CollectionUtil.newHashMap(contexts.size());+ final Map<IntsRef, Float> contextMap = HashMap.newHashMap(contexts.size());final IntHashSet contextLengths = new IntHashSet();for (Map.Entry<IntsRef, ContextMetaData> entry : contexts.entrySet()) {ContextMetaData contextMetaData = entry.getValue();diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestSuggestStopFilterFactory.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestSuggestStopFilterFactory.javaindex 1cc77b6cf01..b8c5f9cb9ca 100644--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestSuggestStopFilterFactory.java+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/analyzing/TestSuggestStopFilterFactory.java@@ -17,12 +17,12 @@package org.apache.lucene.search.suggest.analyzing;import java.io.IOException;+import java.util.HashMap;import java.util.Map;import org.apache.lucene.analysis.CharArraySet;import org.apache.lucene.analysis.en.EnglishAnalyzer;import org.apache.lucene.tests.analysis.BaseTokenStreamTestCase;import org.apache.lucene.util.ClasspathResourceLoader;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.ResourceLoader;import org.apache.lucene.util.Version;@@ -108,7 +108,7 @@ public class TestSuggestStopFilterFactory extends BaseTokenStreamTestCase {if (params.length % 2 != 0) {throw new IllegalArgumentException("invalid keysAndValues map");}- Map<String, String> args = CollectionUtil.newHashMap(params.length / 2);+ Map<String, String> args = HashMap.newHashMap(params.length / 2);for (int i = 0; i < params.length; i += 2) {String previous = args.put(params[i], params[i + 1]);assertNull("duplicate values for key: " + params[i], previous);diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseTermVectorsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseTermVectorsFormatTestCase.javaindex 64733b91555..e19775ab223 100644--- a/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseTermVectorsFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/index/BaseTermVectorsFormatTestCase.java@@ -75,7 +75,6 @@ import org.apache.lucene.tests.util.TestUtil;import org.apache.lucene.util.AttributeImpl;import org.apache.lucene.util.AttributeReflector;import org.apache.lucene.util.BytesRef;-import org.apache.lucene.util.CollectionUtil;import org.apache.lucene.util.IOUtils;/**@@ -251,8 +250,8 @@ public abstract class BaseTermVectorsFormatTestCase extends BaseIndexFileFormatT}}- positionToTerms = CollectionUtil.newHashMap(len);- startOffsetToTerms = CollectionUtil.newHashMap(len);+ positionToTerms = HashMap.newHashMap(len);+ startOffsetToTerms = HashMap.newHashMap(len);for (int i = 0; i < len; ++i) {positionToTerms.computeIfAbsent(positions[i], _ -> new HashSet<>(1)).add(i);startOffsetToTerms.computeIfAbsent(startOffsets[i], _ -> new HashSet<>(1)).add(i);