Package org.apache.sshd.common.util
Class GenericUtils
- java.lang.Object
-
- org.apache.sshd.common.util.GenericUtils
-
public final class GenericUtils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.function.SupplierCASE_INSENSITIVE_MAP_FACTORYstatic java.util.Comparator<java.lang.String>CASE_SENSITIVE_ORDERThe complement ofString.CASE_INSENSITIVE_ORDERstatic boolean[]EMPTY_BOOLEAN_ARRAYstatic byte[]EMPTY_BYTE_ARRAYstatic char[]EMPTY_CHAR_ARRAYstatic java.lang.Object[]EMPTY_OBJECT_ARRAYstatic java.lang.String[]EMPTY_STRING_ARRAYstatic java.lang.ObjectNULLA value indicating anullvalue - to be used as a placeholder wherenulls are not allowedstatic java.lang.StringQUOTES
-
Constructor Summary
Constructors Modifier Constructor Description privateGenericUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends java.lang.Throwable>
TaccumulateException(T current, T extra)Used to "accumulate" exceptions of the same type.static <T> java.util.List<T>asList(T... values)static <T> java.util.Set<T>asSet(T... values)static <V extends java.lang.Comparable<V>>
java.util.NavigableSet<V>asSortedSet(java.util.Collection<? extends V> values)static <V> java.util.NavigableSet<V>asSortedSet(java.util.Comparator<? super V> comp, java.util.Collection<? extends V> values)static <V> java.util.NavigableSet<V>asSortedSet(java.util.Comparator<? super V> comp, V... values)static <V extends java.lang.Comparable<V>>
java.util.NavigableSet<V>asSortedSet(V... values)static <V> java.util.function.Supplier<java.util.NavigableMap<java.lang.String,V>>caseInsensitiveMap()static intcompare(char[] c1, char[] c2)Compares 2 character arrays - Note:nulland empty are considered equalstatic <T> booleancontainsAny(java.util.Collection<? extends T> coll, java.lang.Iterable<? extends T> values)static <B,D extends B>
java.util.function.Function<D,B>downcast()static <T> intfindFirstDifferentValueIndex(java.lang.Iterable<? extends T> c1, java.lang.Iterable<? extends T> c2)static <T> intfindFirstDifferentValueIndex(java.lang.Iterable<? extends T> c1, java.lang.Iterable<? extends T> c2, UnaryEquator<? super T> equator)static <T> intfindFirstDifferentValueIndex(java.util.Iterator<? extends T> i1, java.util.Iterator<? extends T> i2)static <T> intfindFirstDifferentValueIndex(java.util.Iterator<? extends T> i1, java.util.Iterator<? extends T> i2, UnaryEquator<? super T> equator)static <T> intfindFirstDifferentValueIndex(java.util.List<? extends T> c1, java.util.List<? extends T> c2)static <T> intfindFirstDifferentValueIndex(java.util.List<? extends T> c1, java.util.List<? extends T> c2, UnaryEquator<? super T> equator)static <T> TfindFirstMatchingMember(java.util.function.Predicate<? super T> acceptor, java.util.Collection<? extends T> values)static <T> TfindFirstMatchingMember(java.util.function.Predicate<? super T> acceptor, T... values)static <K,V,M extends java.util.Map<V,K>>
MflipMap(java.util.Map<? extends K,? extends V> map, java.util.function.Supplier<? extends M> mapCreator, boolean allowDuplicates)Flips between keys and values of an input mapstatic <T> voidforEach(java.lang.Iterable<? extends T> values, java.util.function.Consumer<? super T> consumer)static inthashCode(java.lang.String s)static inthashCode(java.lang.String s, java.lang.Boolean useUppercase)static <T> Thead(java.lang.Iterable<? extends T> it)Returns the first element in iterable - it has some optimization forList-sDeque-s andSortedSets.static intindexOf(java.lang.CharSequence cs, char c)static booleanisEmpty(char[] chars)static booleanisEmpty(java.lang.CharSequence cs)static <T> booleanisEmpty(java.lang.Iterable<? extends T> iter)static booleanisEmpty(java.util.Collection<?> c)static <T> booleanisEmpty(java.util.Iterator<? extends T> iter)static booleanisEmpty(java.util.Map<?,?> m)static <T> booleanisEmpty(T... a)static booleanisNotEmpty(java.lang.CharSequence cs)static <T> booleanisNotEmpty(java.lang.Iterable<? extends T> iter)static booleanisNotEmpty(java.util.Collection<?> c)static <T> booleanisNotEmpty(java.util.Iterator<? extends T> iter)static booleanisNotEmpty(java.util.Map<?,?> m)static <T> booleanisSameReference(T o1, T o2)static <T> java.util.Iterator<T>iteratorOf(java.lang.Iterable<T> iterable)Resolves to an always non-nulliteratorstatic <T> java.util.Iterator<T>iteratorOf(java.util.Iterator<T> iter)Resolves to an always non-nulliteratorstatic java.lang.Stringjoin(java.lang.Iterable<?> iter, char ch)static java.lang.Stringjoin(java.lang.Iterable<?> iter, java.lang.CharSequence sep)static java.lang.Stringjoin(java.util.Iterator<?> iter, char ch)static java.lang.Stringjoin(java.util.Iterator<?> iter, java.lang.CharSequence sep)static <T> java.lang.Stringjoin(T[] values, char ch)static <T> java.lang.Stringjoin(T[] values, java.lang.CharSequence sep)static intlastIndexOf(java.lang.CharSequence cs, char c)static intlength(char[] chars)static intlength(java.lang.CharSequence cs)static <T> intlength(T... a)static <T,U>
java.util.List<U>map(java.util.Collection<? extends T> values, java.util.function.Function<? super T,? extends U> mapper)static <T,U>
java.util.NavigableSet<U>mapSort(java.util.Collection<? extends T> values, java.util.function.Function<? super T,? extends U> mapper, java.util.Comparator<? super U> comparator)static <K,V,M extends java.util.Map<K,V>>
MmapValues(java.util.function.Function<? super V,? extends K> keyMapper, java.util.function.Supplier<? extends M> mapCreator, java.util.Collection<? extends V> values)Creates a map out of a group of valuesstatic <K,V,M extends java.util.Map<K,V>>
MmapValues(java.util.function.Function<? super V,? extends K> keyMapper, java.util.function.Supplier<? extends M> mapCreator, V... values)static <T> java.lang.Iterable<T>multiIterableSuppliers(java.lang.Iterable<? extends java.util.function.Supplier<? extends java.lang.Iterable<? extends T>>> providers)Wraps a group ofSuppliers ofIterableinstances into a "unified"Iterableof their values, in the same order as the suppliers - i.e., once the values from a specific supplier are exhausted, the next one is consulted, and so on, until all suppliers have been consultedstatic <E extends java.lang.Enum<E>>
java.util.Set<E>of(E... values)static <E extends java.lang.Enum<E>>
java.util.Set<E>of(java.util.Collection<? extends E> values)static java.lang.ThrowablepeelException(java.lang.Throwable t)Attempts to get to the "effective" exception being thrown, by taking care of some known exceptions that wrap the original thrown one.static java.lang.StringreplaceWhitespaceAndTrim(java.lang.String s)static java.lang.ThrowableresolveExceptionCause(java.lang.Throwable t)static intsafeCompare(java.lang.String s1, java.lang.String s2, boolean caseSensitive)static <T> java.util.List<T>selectMatchingMembers(java.util.function.Predicate<? super T> acceptor, java.util.Collection<? extends T> values)Returns a list of all the values that were accepted by a predicatestatic <T> java.util.List<T>selectMatchingMembers(java.util.function.Predicate<? super T> acceptor, T... values)Returns a list of all the values that were accepted by a predicatestatic <T> TselectNextMatchingValue(java.util.Iterator<?> values, java.lang.Class<T> type)static intsize(java.util.Collection<?> c)static intsize(java.util.Map<?,?> m)static java.lang.String[]split(java.lang.String s, char ch)static <T> java.util.stream.Stream<T>stream(java.lang.Iterable<T> values)static java.lang.CharSequencestripDelimiters(java.lang.CharSequence s, char delim)static java.lang.CharSequencestripQuotes(java.lang.CharSequence s)static <T> java.util.function.Supplier<T>supplierOf(T value)Wraps a value into aSupplierstatic <T> java.util.function.BinaryOperator<T>throwingMerger()static java.io.IOExceptiontoIOException(java.lang.Throwable e)static java.lang.RuntimeExceptiontoRuntimeException(java.lang.Throwable t)static java.lang.RuntimeExceptiontoRuntimeException(java.lang.Throwable t, boolean peelThrowable)Converts a thrown generic exception to aRuntimeExceptionstatic <T,K,U>
java.util.NavigableMap<K,U>toSortedMap(java.lang.Iterable<? extends T> values, java.util.function.Function<? super T,? extends K> keyMapper, java.util.function.Function<? super T,? extends U> valueMapper, java.util.Comparator<? super K> comparator)static <T,K,U>
java.util.stream.Collector<T,?,java.util.NavigableMap<K,U>>toSortedMap(java.util.function.Function<? super T,? extends K> keyMapper, java.util.function.Function<? super T,? extends U> valueMapper, java.util.Comparator<? super K> comparator)static <T> java.util.stream.Collector<T,?,java.util.NavigableSet<T>>toSortedSet(java.util.Comparator<? super T> comparator)static java.lang.StringtrimToEmpty(java.lang.String s)static <T> java.util.List<T>unmodifiableList(java.util.Collection<? extends T> values)static <T> java.util.List<T>unmodifiableList(java.util.stream.Stream<T> values)static <T> java.util.List<T>unmodifiableList(T... values)static <U,V>
java.lang.Iterable<V>wrapIterable(java.lang.Iterable<? extends U> iter, java.util.function.Function<? super U,? extends V> mapper)static <U,V>
java.util.Iterator<V>wrapIterator(java.lang.Iterable<? extends U> iter, java.util.function.Function<? super U,? extends V> mapper)static <U,V>
java.util.Iterator<V>wrapIterator(java.util.Iterator<? extends U> iter, java.util.function.Function<? super U,? extends V> mapper)
-
-
-
Field Detail
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY
-
EMPTY_CHAR_ARRAY
public static final char[] EMPTY_CHAR_ARRAY
-
EMPTY_STRING_ARRAY
public static final java.lang.String[] EMPTY_STRING_ARRAY
-
EMPTY_OBJECT_ARRAY
public static final java.lang.Object[] EMPTY_OBJECT_ARRAY
-
EMPTY_BOOLEAN_ARRAY
public static final boolean[] EMPTY_BOOLEAN_ARRAY
-
NULL
public static final java.lang.Object NULL
A value indicating anullvalue - to be used as a placeholder wherenulls are not allowed
-
CASE_SENSITIVE_ORDER
public static final java.util.Comparator<java.lang.String> CASE_SENSITIVE_ORDER
The complement ofString.CASE_INSENSITIVE_ORDER
-
QUOTES
public static final java.lang.String QUOTES
- See Also:
- Constant Field Values
-
CASE_INSENSITIVE_MAP_FACTORY
private static final java.util.function.Supplier CASE_INSENSITIVE_MAP_FACTORY
-
-
Method Detail
-
trimToEmpty
public static java.lang.String trimToEmpty(java.lang.String s)
-
replaceWhitespaceAndTrim
public static java.lang.String replaceWhitespaceAndTrim(java.lang.String s)
-
hashCode
public static int hashCode(java.lang.String s)
- Parameters:
s- TheStringvalue to calculate the hash code on - may benull/empty in which case a value of zero is returned- Returns:
- The calculated hash code
- See Also:
hashCode(String, Boolean)
-
hashCode
public static int hashCode(java.lang.String s, java.lang.Boolean useUppercase)- Parameters:
s- TheStringvalue to calculate the hash code on - may benull/empty in which case a value of zero is returneduseUppercase- Whether to convert the string to uppercase, lowercase or not at all:null- no conversionBoolean.TRUE- get hash code of uppercaseBoolean.FALSE- get hash code of lowercase
- Returns:
- The calculated hash code
-
safeCompare
public static int safeCompare(java.lang.String s1, java.lang.String s2, boolean caseSensitive)
-
isSameReference
public static <T> boolean isSameReference(T o1, T o2)
-
length
public static int length(java.lang.CharSequence cs)
-
isEmpty
public static boolean isEmpty(java.lang.CharSequence cs)
-
isNotEmpty
public static boolean isNotEmpty(java.lang.CharSequence cs)
-
indexOf
public static int indexOf(java.lang.CharSequence cs, char c)
-
lastIndexOf
public static int lastIndexOf(java.lang.CharSequence cs, char c)
-
split
public static java.lang.String[] split(java.lang.String s, char ch)
-
join
public static <T> java.lang.String join(T[] values, char ch)
-
join
public static java.lang.String join(java.lang.Iterable<?> iter, char ch)
-
join
public static java.lang.String join(java.util.Iterator<?> iter, char ch)
-
join
public static <T> java.lang.String join(T[] values, java.lang.CharSequence sep)
-
join
public static java.lang.String join(java.lang.Iterable<?> iter, java.lang.CharSequence sep)
-
join
public static java.lang.String join(java.util.Iterator<?> iter, java.lang.CharSequence sep)
-
size
public static int size(java.util.Collection<?> c)
-
isEmpty
public static boolean isEmpty(java.util.Collection<?> c)
-
isNotEmpty
public static boolean isNotEmpty(java.util.Collection<?> c)
-
size
public static int size(java.util.Map<?,?> m)
-
isEmpty
public static boolean isEmpty(java.util.Map<?,?> m)
-
isNotEmpty
public static boolean isNotEmpty(java.util.Map<?,?> m)
-
length
@SafeVarargs public static <T> int length(T... a)
-
isEmpty
public static <T> boolean isEmpty(java.lang.Iterable<? extends T> iter)
-
isNotEmpty
public static <T> boolean isNotEmpty(java.lang.Iterable<? extends T> iter)
-
isEmpty
public static <T> boolean isEmpty(java.util.Iterator<? extends T> iter)
-
isNotEmpty
public static <T> boolean isNotEmpty(java.util.Iterator<? extends T> iter)
-
isEmpty
@SafeVarargs public static <T> boolean isEmpty(T... a)
-
length
public static int length(char[] chars)
-
isEmpty
public static boolean isEmpty(char[] chars)
-
compare
public static int compare(char[] c1, char[] c2)Compares 2 character arrays - Note:nulland empty are considered equal- Parameters:
c1- 1st arrayc2- 2nd array- Returns:
- Negative is 1st array comes first in lexicographical order, positive if 2nd array comes first and zero if equal
-
of
@SafeVarargs public static <E extends java.lang.Enum<E>> java.util.Set<E> of(E... values)
-
of
public static <E extends java.lang.Enum<E>> java.util.Set<E> of(java.util.Collection<? extends E> values)
-
findFirstDifferentValueIndex
public static <T> int findFirstDifferentValueIndex(java.util.List<? extends T> c1, java.util.List<? extends T> c2)
-
findFirstDifferentValueIndex
public static <T> int findFirstDifferentValueIndex(java.util.List<? extends T> c1, java.util.List<? extends T> c2, UnaryEquator<? super T> equator)
-
findFirstDifferentValueIndex
public static <T> int findFirstDifferentValueIndex(java.lang.Iterable<? extends T> c1, java.lang.Iterable<? extends T> c2)
-
findFirstDifferentValueIndex
public static <T> int findFirstDifferentValueIndex(java.lang.Iterable<? extends T> c1, java.lang.Iterable<? extends T> c2, UnaryEquator<? super T> equator)
-
findFirstDifferentValueIndex
public static <T> int findFirstDifferentValueIndex(java.util.Iterator<? extends T> i1, java.util.Iterator<? extends T> i2)
-
findFirstDifferentValueIndex
public static <T> int findFirstDifferentValueIndex(java.util.Iterator<? extends T> i1, java.util.Iterator<? extends T> i2, UnaryEquator<? super T> equator)
-
containsAny
public static <T> boolean containsAny(java.util.Collection<? extends T> coll, java.lang.Iterable<? extends T> values)
-
forEach
public static <T> void forEach(java.lang.Iterable<? extends T> values, java.util.function.Consumer<? super T> consumer)
-
map
public static <T,U> java.util.List<U> map(java.util.Collection<? extends T> values, java.util.function.Function<? super T,? extends U> mapper)
-
mapSort
public static <T,U> java.util.NavigableSet<U> mapSort(java.util.Collection<? extends T> values, java.util.function.Function<? super T,? extends U> mapper, java.util.Comparator<? super U> comparator)
-
toSortedMap
public static <T,K,U> java.util.NavigableMap<K,U> toSortedMap(java.lang.Iterable<? extends T> values, java.util.function.Function<? super T,? extends K> keyMapper, java.util.function.Function<? super T,? extends U> valueMapper, java.util.Comparator<? super K> comparator)
-
toSortedMap
public static <T,K,U> java.util.stream.Collector<T,?,java.util.NavigableMap<K,U>> toSortedMap(java.util.function.Function<? super T,? extends K> keyMapper, java.util.function.Function<? super T,? extends U> valueMapper, java.util.Comparator<? super K> comparator)
-
throwingMerger
public static <T> java.util.function.BinaryOperator<T> throwingMerger()
-
toSortedSet
public static <T> java.util.stream.Collector<T,?,java.util.NavigableSet<T>> toSortedSet(java.util.Comparator<? super T> comparator)
-
stream
public static <T> java.util.stream.Stream<T> stream(java.lang.Iterable<T> values)
-
unmodifiableList
@SafeVarargs public static <T> java.util.List<T> unmodifiableList(T... values)
-
unmodifiableList
public static <T> java.util.List<T> unmodifiableList(java.util.Collection<? extends T> values)
-
unmodifiableList
public static <T> java.util.List<T> unmodifiableList(java.util.stream.Stream<T> values)
-
asList
@SafeVarargs public static <T> java.util.List<T> asList(T... values)
-
asSet
@SafeVarargs public static <T> java.util.Set<T> asSet(T... values)
-
asSortedSet
@SafeVarargs public static <V extends java.lang.Comparable<V>> java.util.NavigableSet<V> asSortedSet(V... values)
-
asSortedSet
public static <V extends java.lang.Comparable<V>> java.util.NavigableSet<V> asSortedSet(java.util.Collection<? extends V> values)
-
asSortedSet
@SafeVarargs public static <V> java.util.NavigableSet<V> asSortedSet(java.util.Comparator<? super V> comp, V... values)- Type Parameters:
V- The element type- Parameters:
comp- The (non-null)Comparatorto usevalues- The values to be added (ignored ifnull)- Returns:
- A
NavigableSetcontaining the values (if any) sorted using the provided comparator
-
asSortedSet
public static <V> java.util.NavigableSet<V> asSortedSet(java.util.Comparator<? super V> comp, java.util.Collection<? extends V> values)- Type Parameters:
V- The element type- Parameters:
comp- The (non-null)Comparatorto usevalues- The values to be added (ignored ifnull/empty)- Returns:
- A
NavigableSetcontaining the values (if any) sorted using the provided comparator
-
caseInsensitiveMap
public static <V> java.util.function.Supplier<java.util.NavigableMap<java.lang.String,V>> caseInsensitiveMap()
- Type Parameters:
V- Type of mapped value- Returns:
- A
Supplierthat returns a newNavigableMapwhenever itsget()method is invoked
-
flipMap
public static <K,V,M extends java.util.Map<V,K>> M flipMap(java.util.Map<? extends K,? extends V> map, java.util.function.Supplier<? extends M> mapCreator, boolean allowDuplicates)Flips between keys and values of an input map- Type Parameters:
K- Original map key typeV- Original map value typeM- Flipped map type- Parameters:
map- The original map to flipmapCreator- The creator of the target mapallowDuplicates- Whether to ignore duplicates on flip- Returns:
- The flipped map result
- Throws:
java.lang.IllegalArgumentException- if allowDuplicates isfalseand a duplicate value found in the original map.
-
mapValues
@SafeVarargs public static <K,V,M extends java.util.Map<K,V>> M mapValues(java.util.function.Function<? super V,? extends K> keyMapper, java.util.function.Supplier<? extends M> mapCreator, V... values)
-
mapValues
public static <K,V,M extends java.util.Map<K,V>> M mapValues(java.util.function.Function<? super V,? extends K> keyMapper, java.util.function.Supplier<? extends M> mapCreator, java.util.Collection<? extends V> values)Creates a map out of a group of values- Type Parameters:
K- The key typeV- The value typeM- The resultMaptype- Parameters:
keyMapper- TheFunctionthat generates a key for a given value. If the returned key isnullthen the value is not mappedmapCreator- TheSupplierused to create/retrieve the result map - provided non-empty group of valuesvalues- The values to be mapped- Returns:
- The resulting
Map- Note: no validation is made to ensure that 2 (or more) values are not mapped to the same key
-
findFirstMatchingMember
@SafeVarargs public static <T> T findFirstMatchingMember(java.util.function.Predicate<? super T> acceptor, T... values)
-
findFirstMatchingMember
public static <T> T findFirstMatchingMember(java.util.function.Predicate<? super T> acceptor, java.util.Collection<? extends T> values)
-
selectMatchingMembers
@SafeVarargs public static <T> java.util.List<T> selectMatchingMembers(java.util.function.Predicate<? super T> acceptor, T... values)Returns a list of all the values that were accepted by a predicate- Type Parameters:
T- The type of value being evaluated- Parameters:
acceptor- ThePredicateto consult whether a member is selectedvalues- The values to be scanned- Returns:
- A
Listof all the values that were accepted by the predicate
-
selectMatchingMembers
public static <T> java.util.List<T> selectMatchingMembers(java.util.function.Predicate<? super T> acceptor, java.util.Collection<? extends T> values)Returns a list of all the values that were accepted by a predicate- Type Parameters:
T- The type of value being evaluated- Parameters:
acceptor- ThePredicateto consult whether a member is selectedvalues- The values to be scanned- Returns:
- A
Listof all the values that were accepted by the predicate
-
stripQuotes
public static java.lang.CharSequence stripQuotes(java.lang.CharSequence s)
- Parameters:
s- TheCharSequenceto be checked- Returns:
- If the sequence contains any of the
QUOTESon both ends, then they are stripped, otherwise nothing is done - See Also:
stripDelimiters(CharSequence, char)
-
stripDelimiters
public static java.lang.CharSequence stripDelimiters(java.lang.CharSequence s, char delim)- Parameters:
s- TheCharSequenceto be checkeddelim- The expected delimiter- Returns:
- If the sequence contains the delimiter on both ends, then it is are stripped, otherwise nothing is done
-
toRuntimeException
public static java.lang.RuntimeException toRuntimeException(java.lang.Throwable t)
-
toRuntimeException
public static java.lang.RuntimeException toRuntimeException(java.lang.Throwable t, boolean peelThrowable)Converts a thrown generic exception to aRuntimeException- Parameters:
t- The original thrown exceptionpeelThrowable- Whether to determine the root cause by "peeling" any enclosing exceptions- Returns:
- The thrown cause if already a runtime exception, otherwise a runtime exception of the resolved exception as its cause
- See Also:
peelException(Throwable)
-
peelException
public static java.lang.Throwable peelException(java.lang.Throwable t)
Attempts to get to the "effective" exception being thrown, by taking care of some known exceptions that wrap the original thrown one.- Parameters:
t- The originalThrowable- ignored ifnull- Returns:
- The effective exception - same as input if not a wrapper
-
resolveExceptionCause
public static java.lang.Throwable resolveExceptionCause(java.lang.Throwable t)
- Parameters:
t- The originalThrowable- ignored ifnull- Returns:
- If
Throwable.getCause()is non-nullthen the cause, otherwise the original exception -nullif the original exception wasnull
-
accumulateException
public static <T extends java.lang.Throwable> T accumulateException(T current, T extra)Used to "accumulate" exceptions of the same type. If the current exception isnullthen the new one becomes the current, otherwise the new one is added as a suppressed exception to the current one- Type Parameters:
T- The exception type- Parameters:
current- The current exceptionextra- The extra/new exception- Returns:
- The resolved exception
- See Also:
Throwable.addSuppressed(Throwable)
-
toIOException
public static java.io.IOException toIOException(java.lang.Throwable e)
-
supplierOf
public static <T> java.util.function.Supplier<T> supplierOf(T value)
Wraps a value into aSupplier- Type Parameters:
T- Type of value being supplied- Parameters:
value- The value to be supplied- Returns:
- The supplier wrapper
-
iteratorOf
public static <T> java.util.Iterator<T> iteratorOf(java.lang.Iterable<T> iterable)
Resolves to an always non-nulliterator- Type Parameters:
T- Type of value being iterated- Parameters:
iterable- TheIterableinstance- Returns:
- A non-
nulliterator which may be empty if no iterable instance or no iterator returned from it - See Also:
iteratorOf(Iterator)
-
downcast
public static <B,D extends B> java.util.function.Function<D,B> downcast()
- Type Parameters:
B- Generic base classD- Generic child class- Returns:
- An identity
Functionthat returns its input child class as a base class
-
head
public static <T> T head(java.lang.Iterable<? extends T> it)
Returns the first element in iterable - it has some optimization forList-sDeque-s andSortedSets.- Type Parameters:
T- Type of element- Parameters:
it- TheIterableinstance - ignored ifnull/empty- Returns:
- first element by iteration or
nullif none available
-
iteratorOf
public static <T> java.util.Iterator<T> iteratorOf(java.util.Iterator<T> iter)
Resolves to an always non-nulliterator- Type Parameters:
T- Type of value being iterated- Parameters:
iter- TheIteratorinstance- Returns:
- A non-
nulliterator which may be empty if no iterator instance - See Also:
Collections.emptyIterator()
-
wrapIterable
public static <U,V> java.lang.Iterable<V> wrapIterable(java.lang.Iterable<? extends U> iter, java.util.function.Function<? super U,? extends V> mapper)
-
wrapIterator
public static <U,V> java.util.Iterator<V> wrapIterator(java.lang.Iterable<? extends U> iter, java.util.function.Function<? super U,? extends V> mapper)
-
wrapIterator
public static <U,V> java.util.Iterator<V> wrapIterator(java.util.Iterator<? extends U> iter, java.util.function.Function<? super U,? extends V> mapper)
-
selectNextMatchingValue
public static <T> T selectNextMatchingValue(java.util.Iterator<?> values, java.lang.Class<T> type)- Type Parameters:
T- Generic return type- Parameters:
values- The source values - ignored ifnulltype- The (never @code null) type of values to select - any value whose type is assignable to this type will be selected by the iterator.- Returns:
- The first value that matches the specified type -
nullif none found
-
multiIterableSuppliers
public static <T> java.lang.Iterable<T> multiIterableSuppliers(java.lang.Iterable<? extends java.util.function.Supplier<? extends java.lang.Iterable<? extends T>>> providers)
Wraps a group ofSuppliers ofIterableinstances into a "unified"Iterableof their values, in the same order as the suppliers - i.e., once the values from a specific supplier are exhausted, the next one is consulted, and so on, until all suppliers have been consulted- Type Parameters:
T- Type of value being iterated- Parameters:
providers- The providers - ignored ifnull(i.e., return an empty iterable instance)- Returns:
- The wrapping instance
-
-