public class CommonUtils
extends java.lang.Object
| Constructor and Description |
|---|
CommonUtils() |
| Modifier and Type | Method and Description |
|---|---|
static int |
binarySearch(int[] a,
int key)
Perform a binary search over a sorted array for the given key.
|
static int |
binarySearch(int[] a,
int key,
int start,
int end)
Perform a binary search over a sorted array for the given key.
|
static int |
binarySearch(java.util.List<java.lang.Object> a,
java.lang.Object key)
Perform a binary search over a sorted list for the given key.
|
static int |
binarySearch(java.lang.Object[] a,
java.lang.Object key)
Perform a binary search over a sorted array for the given key.
|
static boolean |
charsEqualIgnoreCase(char a,
char b) |
static <T,U> java.util.Comparator<T> |
comparing(java.util.Comparator<? super U> comparator,
java.util.function.Function<? super T,? extends U> keyExtractor)
Accepts a function that extracts an object of a type
U as sort key from a type T, and returns the
object that compares by the specified comparator. |
static boolean |
equals(java.lang.CharSequence s1,
java.lang.CharSequence s2,
boolean caseSensitive) |
static boolean |
equals(java.lang.Object o1,
java.lang.Object o2)
Checks if the two objects equal.
|
static boolean |
equals(java.lang.Object o1,
java.lang.Object o2,
boolean considerArrayOrList)
Checks if the two objects equal.
|
static void |
ignoreException(java.lang.Exception e)
Ignore the exception.
|
static void |
printException(java.lang.Exception e)
Prints out the message of the exception.
|
static void |
throwException(java.lang.Exception e)
Throws the exception.
|
static void |
throwInvocationTargetException(java.lang.reflect.InvocationTargetException e)
Throws the InvocationTargetException.
|
static char |
toLowerCase(char a)
A toLowerCase routine which is faster to process the ASCII lowercase letters then Character.toLowerCase.
|
static char |
toUpperCase(char a)
A toUpperCase routine which is faster to process the ASCII lowercase letters than Character.toUpperCase.
|
public static boolean equals(java.lang.Object o1,
java.lang.Object o2)
o1.equals(o2) to compare. If none of
the above conditions match, we return false.o1 - the first object to compareo2 - the second object to comparepublic static boolean equals(java.lang.Object o1,
java.lang.Object o2,
boolean considerArrayOrList)
o1.equals(o2) to compare. If none of the above conditions match, we return false.o1 - the first object to compareo2 - the second object to compareconsiderArrayOrList - If true, and if o1 and o2 are both array, we will compare each element in the array
instead of just compare the two array objects.public static boolean equals(java.lang.CharSequence s1,
java.lang.CharSequence s2,
boolean caseSensitive)
public static boolean charsEqualIgnoreCase(char a,
char b)
public static char toUpperCase(char a)
a - the character to be converted.public static char toLowerCase(char a)
a - the character to be converted.public static void ignoreException(java.lang.Exception e)
e - the exceptionpublic static void printException(java.lang.Exception e)
e - the exceptionpublic static void throwException(java.lang.Exception e)
e - the exceptionpublic static void throwInvocationTargetException(java.lang.reflect.InvocationTargetException e)
e - the exceptionpublic static int binarySearch(java.util.List<java.lang.Object> a,
java.lang.Object key)
a - the array to searchkey - the key to search forpublic static int binarySearch(java.lang.Object[] a,
java.lang.Object key)
a - the array to searchkey - the key to search forpublic static int binarySearch(int[] a,
int key)
a - the array to searchkey - the key to search forpublic static int binarySearch(int[] a,
int key,
int start,
int end)
a - the array to searchkey - the key to search forstart - the start index to search inclusiveend - the end index to search exclusivepublic static <T,U> java.util.Comparator<T> comparing(java.util.Comparator<? super U> comparator,
java.util.function.Function<? super T,? extends U> keyExtractor)
U as sort key from a type T, and returns the
object that compares by the specified comparator. For example, if a class Element has a value
which has a getter, but we only have a Comparator for the value, not for the Element. We can use this
method to call Person objects to get the value, then use the existing Comparator for the value.T - the original element typeU - the actual type for comparisoncomparator - a comparator that can sort the value.keyExtractor - the function used to extract the value sort key for the Comparator