Package org.apache.lucene.util
Class CollectionUtil
java.lang.Object
org.apache.lucene.util.CollectionUtil
Methods for manipulating (sorting) and creating collections. Sort methods work directly on the
supplied lists and don't copy to/from arrays before/after. For medium size collections as used in
the Lucene indexer that is much more efficient.
- NOTE: This API is for internal purposes only and might change in incompatible ways in the next release.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<? super T>>
voidSorts the given random accessList
in natural order.static <T> void
introSort
(List<T> list, Comparator<? super T> comp) Sorts the given random accessList
using theComparator
.static <K,
V> HashMap <K, V> newHashMap
(int size) Returns a newHashMap
sized to containsize
items without resizing the internal array.static <E> HashSet
<E> newHashSet
(int size) Returns a newHashSet
sized to containsize
items without resizing the internal array.static <T extends Comparable<? super T>>
voidSorts the given random accessList
in natural order.static <T> void
timSort
(List<T> list, Comparator<? super T> comp) Sorts the given random accessList
using theComparator
.
-
Method Details
-
newHashMap
Returns a newHashMap
sized to containsize
items without resizing the internal array. -
newHashSet
Returns a newHashSet
sized to containsize
items without resizing the internal array. -
introSort
Sorts the given random accessList
using theComparator
. The list must implementRandomAccess
. This method uses the intro sort algorithm, but falls back to insertion sort for small lists.- Throws:
IllegalArgumentException
- if list is e.g. a linked list without random access.- See Also:
-
introSort
Sorts the given random accessList
in natural order. The list must implementRandomAccess
. This method uses the intro sort algorithm, but falls back to insertion sort for small lists.- Throws:
IllegalArgumentException
- if list is e.g. a linked list without random access.- See Also:
-
timSort
Sorts the given random accessList
using theComparator
. The list must implementRandomAccess
. This method uses the Tim sort algorithm, but falls back to binary sort for small lists.- Throws:
IllegalArgumentException
- if list is e.g. a linked list without random access.- See Also:
-
timSort
Sorts the given random accessList
in natural order. The list must implementRandomAccess
. This method uses the Tim sort algorithm, but falls back to binary sort for small lists.- Throws:
IllegalArgumentException
- if list is e.g. a linked list without random access.- See Also:
-