Package org.apache.sshd.common.util
Class GenericUtils
java.lang.Object
org.apache.sshd.common.util.GenericUtils
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<String> The complement ofString.CASE_INSENSITIVE_ORDERstatic final boolean[]static final byte[]static final char[]static final Object[]static final String[]static final ObjectA value indicating anullvalue - to be used as a placeholder wherenulls are not allowedstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> List<T> asList(T... values) static <T> Set<T> asSet(T... values) static <V extends Comparable<V>>
NavigableSet<V> asSortedSet(Collection<? extends V> values) static <V> NavigableSet<V> asSortedSet(Comparator<? super V> comp, Collection<? extends V> values) static <V> NavigableSet<V> asSortedSet(Comparator<? super V> comp, V... values) static <V extends Comparable<V>>
NavigableSet<V> asSortedSet(V... values) static intcompare(char[] c1, char[] c2) Compares 2 character arrays - Note:nulland empty are considered equalstatic <T> booleancontainsAny(Collection<? extends T> coll, Iterable<? extends T> values) static <B,D extends B>
Function<D, B> downcast()static <T> booleanequals(Collection<T> c1, Collection<T> c2) filterToNotBlank(List<String> values) static <T> intfindFirstDifferentValueIndex(Iterable<? extends T> c1, Iterable<? extends T> c2) static <T> intfindFirstDifferentValueIndex(Iterable<? extends T> c1, Iterable<? extends T> c2, UnaryEquator<? super T> equator) static <T> intfindFirstDifferentValueIndex(Iterator<? extends T> i1, Iterator<? extends T> i2) static <T> intfindFirstDifferentValueIndex(Iterator<? extends T> i1, Iterator<? extends T> i2, UnaryEquator<? super T> equator) static <T> intfindFirstDifferentValueIndex(List<? extends T> c1, List<? extends T> c2) static <T> intfindFirstDifferentValueIndex(List<? extends T> c1, List<? extends T> c2, UnaryEquator<? super T> equator) static <T> TfindFirstMatchingMember(Predicate<? super T> acceptor, Collection<? extends T> values) static <T> TfindFirstMatchingMember(Predicate<? super T> acceptor, T... values) static <T> voidstatic intstatic intstatic <T> Tstatic intindexOf(CharSequence cs, char c) static booleanisBlank(CharSequence cs) Checks if a CharSequence is empty (""), null or whitespace only.static booleanisEmpty(char[] chars) static booleanisEmpty(CharSequence cs) static <T> booleanstatic booleanisEmpty(Collection<?> c) static <T> booleanstatic <T> booleanisEmpty(T[] a) static booleanCheck if a duration is negative or zerostatic booleanstatic booleanstatic <T> booleanisNotEmpty(Iterable<? extends T> iter) static booleanisNotEmpty(Collection<?> c) static <T> booleanisNotEmpty(Iterator<? extends T> iter) static booleanCheck if a duration is positivestatic <T> Iterator<T> iteratorOf(Iterable<T> iterable) Resolves to an always non-nulliteratorstatic <T> Iterator<T> iteratorOf(Iterator<T> iter) Resolves to an always non-nulliteratorstatic Stringstatic Stringjoin(Iterable<?> iter, CharSequence sep) static Stringstatic Stringjoin(Iterator<?> iter, CharSequence sep) static <T> Stringjoin(T[] values, char ch) static <T> Stringjoin(T[] values, CharSequence sep) static intlastIndexOf(CharSequence cs, char c) static intlength(char[] chars) static intlength(CharSequence cs) static <T> intlength(T... a) static <T,U> List <U> map(Collection<? extends T> values, Function<? super T, ? extends U> mapper) static <T,U> NavigableSet <U> mapSort(Collection<? extends T> values, Function<? super T, ? extends U> mapper, Comparator<? super U> comparator) static <T> Supplier<T> memoizeLock(Supplier<? extends T> delegate) The delegate Suppliers get() method is called exactly once and the result is cached.static <T> Iterable<T> multiIterableSuppliers(Iterable<? extends Supplier<? extends Iterable<? extends T>>> providers) of(E... values) of(Collection<? extends E> values) static StringReplace a String with another String inside a larger String, for the firstmaxvalues of the search String.static Stringstatic intsafeCompare(String s1, String s2, boolean caseSensitive) static <T> List<T> selectMatchingMembers(Predicate<? super T> acceptor, Collection<? extends T> values) Returns a list of all the values that were accepted by a predicatestatic <T> List<T> selectMatchingMembers(Predicate<? super T> acceptor, T... values) Returns a list of all the values that were accepted by a predicatestatic <T> TselectNextMatchingValue(Iterator<?> values, Class<T> type) static intsize(Collection<?> c) static String[]static <T> Stream<T> static CharSequencestripDelimiters(CharSequence s, char delim) static CharSequencestatic <T> Supplier<T> supplierOf(T value) Wraps a value into aSupplierstatic <T> Collector<T, ?, NavigableSet<T>> toSortedSet(Comparator<? super T> comparator) static Stringstatic <T> List<T> unmodifiableList(Collection<? extends T> values) static <T> List<T> unmodifiableList(Stream<T> values) static <T> List<T> unmodifiableList(T... values) static <U,V> Iterable <V> wrapIterable(Iterable<? extends U> iter, Function<? super U, ? extends V> mapper) static <U,V> Iterator <V> wrapIterator(Iterable<? extends U> iter, Function<? super U, ? extends V> mapper) static <U,V> Iterator <V> wrapIterator(Iterator<? extends U> iter, Function<? super U, ? extends V> mapper)
-
Field Details
-
EMPTY_BYTE_ARRAY
public static final byte[] EMPTY_BYTE_ARRAY -
EMPTY_CHAR_ARRAY
public static final char[] EMPTY_CHAR_ARRAY -
EMPTY_STRING_ARRAY
-
EMPTY_OBJECT_ARRAY
-
EMPTY_BOOLEAN_ARRAY
public static final boolean[] EMPTY_BOOLEAN_ARRAY -
NULL
A value indicating anullvalue - to be used as a placeholder wherenulls are not allowed -
CASE_SENSITIVE_ORDER
The complement ofString.CASE_INSENSITIVE_ORDER -
QUOTES
- See Also:
-
-
Constructor Details
-
GenericUtils
private GenericUtils()
-
-
Method Details
-
trimToEmpty
-
replaceWhitespaceAndTrim
-
replace
Replace a String with another String inside a larger String, for the first
maxvalues of the search String.A
nullreference passed to this method is a no-op.- Parameters:
text- text to search and replace inrepl- String to search forwith- String to replace withmax- maximum number of values to replace, or-1if no maximum- Returns:
- the text with any replacements processed author Arnout J. Kuiper ajkuiper@wxs.nl author Magesh Umasankar author Bruce Atherton author Antoine Levy-Lambert
-
hashCode
- 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
- 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
-
length
-
isEmpty
-
isNotEmpty
-
isBlank
Checks if a CharSequence is empty (""), null or whitespace only.
Whitespace is defined by
Character.isWhitespace(char).GenericUtils.isBlank(null) = true GenericUtils.isBlank("") = true GenericUtils.isBlank(" ") = true GenericUtils.isBlank("bob") = false GenericUtils.isBlank(" bob ") = false- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is null, empty or whitespace only
-
isNotBlank
-
filterToNotBlank
-
indexOf
-
lastIndexOf
-
split
-
join
-
join
-
join
-
join
-
join
-
join
-
size
-
isEmpty
-
isNotEmpty
-
equals
- Type Parameters:
T- Generic element type- Parameters:
c1- First collectionc2- Second collection- Returns:
trueif the following holds:- Same size - Note:
nullcollections are consider equal to empty ones - First collection contains all elements of second one and vice versa
- Same size - Note:
-
length
-
isEmpty
-
isNotEmpty
-
isEmpty
-
isNotEmpty
-
isEmpty
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
-
of
-
findFirstDifferentValueIndex
-
findFirstDifferentValueIndex
public static <T> int findFirstDifferentValueIndex(List<? extends T> c1, List<? extends T> c2, UnaryEquator<? super T> equator) -
findFirstDifferentValueIndex
-
findFirstDifferentValueIndex
public static <T> int findFirstDifferentValueIndex(Iterable<? extends T> c1, Iterable<? extends T> c2, UnaryEquator<? super T> equator) -
findFirstDifferentValueIndex
-
findFirstDifferentValueIndex
public static <T> int findFirstDifferentValueIndex(Iterator<? extends T> i1, Iterator<? extends T> i2, UnaryEquator<? super T> equator) -
containsAny
-
forEach
-
map
public static <T,U> List<U> map(Collection<? extends T> values, Function<? super T, ? extends U> mapper) -
mapSort
public static <T,U> NavigableSet<U> mapSort(Collection<? extends T> values, Function<? super T, ? extends U> mapper, Comparator<? super U> comparator) -
toSortedSet
-
stream
-
unmodifiableList
-
unmodifiableList
-
unmodifiableList
-
asList
-
asSet
-
asSortedSet
-
asSortedSet
-
asSortedSet
- 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> NavigableSet<V> asSortedSet(Comparator<? super V> comp, 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
-
findFirstMatchingMember
@SafeVarargs public static <T> T findFirstMatchingMember(Predicate<? super T> acceptor, T... values) -
findFirstMatchingMember
public static <T> T findFirstMatchingMember(Predicate<? super T> acceptor, Collection<? extends T> values) -
selectMatchingMembers
@SafeVarargs public static <T> List<T> selectMatchingMembers(Predicate<? super T> acceptor, T... values) Returns a list of all the values that were accepted by a predicate -
selectMatchingMembers
public static <T> List<T> selectMatchingMembers(Predicate<? super T> acceptor, Collection<? extends T> values) Returns a list of all the values that were accepted by a predicate -
stripQuotes
- 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
- 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
-
supplierOf
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
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:
-
downcast
- Type Parameters:
B- Generic base classD- Generic child class- Returns:
- An identity
Functionthat returns its input child class as a base class
-
head
- Type Parameters:
T- Type of element- Parameters:
it- TheIterableinstance - ignored ifnull/empty- Returns:
- first element by iteration or
nullif none available
-
iteratorOf
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:
-
wrapIterable
-
wrapIterator
-
wrapIterator
-
selectNextMatchingValue
- 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> Iterable<T> multiIterableSuppliers(Iterable<? extends Supplier<? extends 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
-
memoizeLock
The delegate Suppliers get() method is called exactly once and the result is cached.- Type Parameters:
T- Generic type of supplied value- Parameters:
delegate- The actual Supplier- Returns:
- The memoized Supplier
-
isPositive
Check if a duration is positive- Parameters:
d- the duration- Returns:
trueif the duration is greater than zero
-
isNegativeOrNull
Check if a duration is negative or zero- Parameters:
d- the duration- Returns:
trueif the duration is negative or zero
-