Package ubic.gemma.core.util
Class ListUtils
- java.lang.Object
-
- ubic.gemma.core.util.ListUtils
-
-
Constructor Summary
Constructors Constructor Description ListUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> List<List<T>>
batch(List<T> list, int batchSize)
static <T> T
getSparseArrayElement(List<T> array, int[] indices, int numberOfElements, int index, T defaultValue)
Get an element of a sparse array.static <T> T
getSparseRangeArrayElement(List<T> array, int[] offsets, int numberOfElements, int index)
Get an element of a sparse range array.static Map<String,Integer>
indexOfCaseInsensitiveStringElements(List<String> list)
Get a case-insensitive mapping of string elements to their first occurrence in aList
.static <T> Map<T,Integer>
indexOfElements(List<T> list)
Get a mapping of element to their first occurrence in aList
.static <T> List<T>
pad(List<T> list, T elementForPadding, int size)
Pad a collection with the given element.static <T> List<T>
padToNextPowerOfTwo(List<T> list, T elementForPadding)
Pad a collection to the next power of 2 with the given element.static <T> void
validateSparseArray(List<T> array, int[] indices, int numberOfElements, T defaultValue)
static void
validateSparseRangeArray(List<?> array, int[] offsets, int numberOfElements)
Validate a sparse range array.
-
-
-
Method Detail
-
indexOfElements
public static <T> Map<T,Integer> indexOfElements(List<T> list)
Get a mapping of element to their first occurrence in aList
.This of this as an efficient way of calling
List.indexOf(Object)
in a loop, since it will reduce the complexity to O(n) instead of O(n^2).I couldn't find this algorithm in Guava nor Apache Collections, but if you do, let me know!
-
indexOfCaseInsensitiveStringElements
public static Map<String,Integer> indexOfCaseInsensitiveStringElements(List<String> list)
Get a case-insensitive mapping of string elements to their first occurrence in aList
.- See Also:
indexOfElements(List)
-
getSparseArrayElement
public static <T> T getSparseArrayElement(List<T> array, int[] indices, int numberOfElements, int index, T defaultValue)
Get an element of a sparse array.
-
validateSparseArray
public static <T> void validateSparseArray(List<T> array, int[] indices, int numberOfElements, @Nullable T defaultValue)
-
getSparseRangeArrayElement
public static <T> T getSparseRangeArrayElement(List<T> array, int[] offsets, int numberOfElements, int index) throws IllegalArgumentException, IndexOutOfBoundsException
Get an element of a sparse range array.- Parameters:
array
- collection of elements applying for the rangesoffsets
- starting offsets of the rangesnumberOfElements
- the size of the original arrayindex
- a position to retrieve- Throws:
IndexOutOfBoundsException
- if the requested index is out of boundsIllegalArgumentException
- if the array is empty or its size differs from offsets- See Also:
validateSparseRangeArray(List, int[], int)
-
validateSparseRangeArray
public static void validateSparseRangeArray(List<?> array, int[] offsets, int numberOfElements) throws IllegalArgumentException
Validate a sparse range array.- Parameters:
array
- collection of elements applying for the rangesoffsets
- starting offsets of the rangesnumberOfElements
- the size of the original array- Throws:
IllegalArgumentException
- if the sparse range array is invalid
-
padToNextPowerOfTwo
public static <T> List<T> padToNextPowerOfTwo(List<T> list, T elementForPadding)
Pad a collection to the next power of 2 with the given element.
-
pad
public static <T> List<T> pad(List<T> list, T elementForPadding, int size)
Pad a collection with the given element.
-
-