public final class CollectionAlgorithms extends Object
Modifier and Type | Class and Description |
---|---|
static class |
CollectionAlgorithms.ComparisonOfDifferentTypes<T1,T2>
Represents a method that compares two objects of different types.
|
Modifier and Type | Method and Description |
---|---|
static <T> int |
binarySearch(List<T> collection,
T item)
Uses a binary search algorithm to locate a specific element in the sorted
List . |
static <T> int |
binarySearch(List<T> collection,
T item,
Comparator<T> comparer)
Uses a binary search algorithm to locate a specific element in the sorted
List . |
static <T> int |
binarySearch(List<T> collection,
T item,
Comparator<T> comparer,
int startIndex,
int length)
Uses a binary search algorithm to locate a specific element in the sorted
List . |
static <TListItem,TMatchItem> |
binarySearch(List<TListItem> collection,
TMatchItem item,
CollectionAlgorithms.ComparisonOfDifferentTypes<TListItem,TMatchItem> comparer)
Uses a binary search algorithm to locate a specific element in the sorted
List . |
static <TListItem,TMatchItem> |
binarySearch(List<TListItem> collection,
TMatchItem item,
CollectionAlgorithms.ComparisonOfDifferentTypes<TListItem,TMatchItem> comparer,
int startIndex,
int length)
Uses a binary search algorithm to locate a specific element in the sorted
List . |
static double[][] |
createJaggedDoubleArray(int n,
int m)
Creates a two-dimensional, jagged double array of the specified dimensions.
|
static <T> void |
reverse(List<T> collection)
Reverses the sequences of elements in a collection.
|
public static <T> int binarySearch(@Nonnull List<T> collection, T item)
List
.
T
- The type of item in the collection.collection
- The collection to search.item
- The item to find.item
is found; otherwise, a negative number
that is the bitwise complement of the index of the next element that is larger than
item
or, if there is no larger element, the bitwise complement of
Count
(get
).public static <T> int binarySearch(@Nonnull List<T> collection, T item, Comparator<T> comparer)
List
.
T
- The type of item in the collection.collection
- The collection to search.item
- The item to find.comparer
- The Comparator
implementation to use when comparing elements.item
is found; otherwise, a negative number
that is the bitwise complement of the index of the next element that is larger than
item
or, if there is no larger element, the bitwise complement of
Count
(get
).public static <T> int binarySearch(@Nonnull List<T> collection, T item, @Nonnull Comparator<T> comparer, int startIndex, int length)
List
.
T
- The type of item in the collection.collection
- The collection to search.item
- The item to find.comparer
- The Comparator
implementation to use when comparing elements.startIndex
- The index of the first item to consider in the search.length
- The number of items to consider in the search, starting with startIndex
.item
is found; otherwise, a negative number
that is the bitwise complement of the index of the next element that is larger than
item
or, if there is no larger element, the bitwise complement of
Count
(get
).public static <TListItem,TMatchItem> int binarySearch(@Nonnull List<TListItem> collection, TMatchItem item, CollectionAlgorithms.ComparisonOfDifferentTypes<TListItem,TMatchItem> comparer)
List
. The element to search for can be a different type from the items
in the collection.
TListItem
- The type of item in the collection.TMatchItem
- The type of item to search for.collection
- The collection to search.item
- The item to find.comparer
- The comparison to use to compare items in the collection to the item
to search for.item
is found; otherwise, a negative number
that is the bitwise complement of the index of the next element that is larger than
item
or, if there is no larger element, the bitwise complement of
Count
(get
).public static <TListItem,TMatchItem> int binarySearch(@Nonnull List<TListItem> collection, TMatchItem item, @Nonnull CollectionAlgorithms.ComparisonOfDifferentTypes<TListItem,TMatchItem> comparer, int startIndex, int length)
List
. The element to search for can be a different type from the items
in the collection.
TListItem
- The type of item in the collection.TMatchItem
- The type of item to search for.collection
- The collection to search.item
- The item to find.comparer
- The comparison to use to compare items in the collection to the item
to search for.startIndex
- The index of the first item to consider in the search.length
- The number of items to consider in the search, starting with startIndex
.item
is found; otherwise, a negative number
that is the bitwise complement of the index of the next element that is larger than
item
or, if there is no larger element, the bitwise complement of
Count
(get
).public static <T> void reverse(@Nonnull List<T> collection)
T
- The type of the element in the collection to reverse.collection
- The collection to reverse.@Nonnull public static double[][] createJaggedDoubleArray(int n, int m)
n
- The dimension of the outer array.m
- The dimension of the inner array.