public final class CollectionUtil extends Object
Collections,
Arrays| Modifier and Type | Method | Description |
|---|---|---|
static <E> void |
addAll(Collection<E> pCollection,
Iterator<? extends E> pIterator) |
Adds all elements of the iterator to the collection.
|
static <K,V> Map<V,K> |
invert(Map<K,V> pSource) |
Creates an inverted mapping of the key/value pairs in the given map.
|
static <K,V> Map<V,K> |
invert(Map<K,V> pSource,
Map<V,K> pResult,
DuplicateHandler<K> pHandler) |
Creates an inverted mapping of the key/value pairs in the given map.
|
static <E> ListIterator<E> |
iterator(E[] pArray) |
Creates a thin
Iterator wrapper around an array. |
static <E> ListIterator<E> |
iterator(E[] pArray,
int pStart,
int pLength) |
Creates a thin
Iterator wrapper around an array. |
static <T> Iterator<T> |
iterator(Enumeration<T> pEnum) |
|
static void |
main(String[] pArgs) |
Testing only.
|
static Object |
mergeArrays(Object pArray1,
int pOffset1,
int pLength1,
Object pArray2,
int pOffset2,
int pLength2) |
Merges two arrays into a new array.
|
static Object |
mergeArrays(Object pArray1,
Object pArray2) |
Merges two arrays into a new array.
|
static <T> Comparator<T> |
reverseOrder(Comparator<T> pOriginal) |
|
static Object |
subArray(Object pArray,
int pStart) |
Creates an array containing a subset of the original array.
|
static Object |
subArray(Object pArray,
int pStart,
int pLength) |
Creates an array containing a subset of the original array.
|
static <T> T[] |
subArray(T[] pArray,
int pStart) |
Creates an array containing a subset of the original array.
|
static <T> T[] |
subArray(T[] pArray,
int pStart,
int pLength) |
Creates an array containing a subset of the original array.
|
public static void main(String[] pArgs)
pArgs - command line arguentspublic static Object mergeArrays(Object pArray1, Object pArray2)
pArray1 - First arraypArray2 - Second array, must be compatible with (assignable from)
the first arraymergeArrays(Object,int,int,Object,int,int),
System.arraycopy(Object,int,Object,int,int)public static Object mergeArrays(Object pArray1, int pOffset1, int pLength1, Object pArray2, int pOffset2, int pLength2)
pArray1 - First arraypOffset1 - the offset into the first arraypLength1 - the number of elements to copy from the first arraypArray2 - Second array, must be compatible with (assignable from)
the first arraypOffset2 - the offset into the second arraypLength2 - the number of elements to copy from the second arraySystem.arraycopy(Object,int,Object,int,int)public static Object subArray(Object pArray, int pStart)
pStart == 0), the original array will be returned.pArray - the original arraypStart - the start index of the original arraypStart is 0.IllegalArgumentException - if pArray is null or
if pArray is not an array.ArrayIndexOutOfBoundsException - if pStart < 0public static <T> T[] subArray(T[] pArray,
int pStart)
pStart == 0), the original array will be returned.pArray - the original arraypStart - the start index of the original arraypStart is 0.IllegalArgumentException - if pArray is nullArrayIndexOutOfBoundsException - if pStart < 0public static Object subArray(Object pArray, int pStart, int pLength)
pLength parameter is negative, it will be ignored.
If there are not pLength elements in the original array
after pStart, the pLength parameter will be
ignored.
If the sub array is same length as the original, the original array will
be returned.pArray - the original arraypStart - the start index of the original arraypLength - the length of the new arraypStart is 0 and pLength is either
negative, or greater or equal to pArray.length.IllegalArgumentException - if pArray is null or
if pArray is not an array.ArrayIndexOutOfBoundsException - if pStart < 0public static <T> T[] subArray(T[] pArray,
int pStart,
int pLength)
pLength parameter is negative, it will be ignored.
If there are not pLength elements in the original array
after pStart, the pLength parameter will be
ignored.
If the sub array is same length as the original, the original array will
be returned.pArray - the original arraypStart - the start index of the original arraypLength - the length of the new arraypStart is 0 and pLength is either
negative, or greater or equal to pArray.length.IllegalArgumentException - if pArray is nullArrayIndexOutOfBoundsException - if pStart < 0public static <T> Iterator<T> iterator(Enumeration<T> pEnum)
public static <E> void addAll(Collection<E> pCollection, Iterator<? extends E> pIterator)
pCollection - the collectionpIterator - the elements to addUnsupportedOperationException - if add is not supported by
the given collection.ClassCastException - class of the specified element prevents it
from being added to this collection.NullPointerException - if the specified element is null and this
collection does not support null elements.IllegalArgumentException - some aspect of this element prevents
it from being added to this collection.public static <E> ListIterator<E> iterator(E[] pArray)
Iterator wrapper around an array.pArray - the array to iterateListIteratorIllegalArgumentException - if pArray is null,
pStart < 0, or
pLength > pArray.length - pStartpublic static <E> ListIterator<E> iterator(E[] pArray, int pStart, int pLength)
Iterator wrapper around an array.pArray - the array to iteratepStart - the offset into the arraypLength - the number of elements to include in the iteratorListIteratorIllegalArgumentException - if pArray is null,
pStart < 0, or
pLength > pArray.length - pStartpublic static <K,V> Map<V,K> invert(Map<K,V> pSource)
pSource - the source mapMap of same type as pSourceIllegalArgumentException - if pSource == null,
or if a new map can't be instantiated,
or if source map contains duplicates.invert(java.util.Map, java.util.Map, DuplicateHandler)public static <K,V> Map<V,K> invert(Map<K,V> pSource, Map<V,K> pResult, DuplicateHandler<K> pHandler)
pSource - the source mappResult - the map used to contain the result, may be null,
in that case a new Map of same type as pSource is created.
The result map should be empty, otherwise duplicate values will need to be resolved.pHandler - duplicate handler, may be null if source map don't contain duplicate valuespResult, or a new Map if pResult == nullIllegalArgumentException - if pSource == null,
or if result map is null and a new map can't be instantiated,
or if source map contains duplicate values and pHandler == null.public static <T> Comparator<T> reverseOrder(Comparator<T> pOriginal)
Copyright © 2018. All rights reserved.