public class GeneralUtilities extends Object
FileUtilities,
GuiUtilities,
StringUtilities,
SystemUtilities,
ThreadUtilities| Modifier and Type | Method and Description |
|---|---|
static boolean |
attemptClose(Closeable closeable)
Attempts to close a closeable, ignoring any failures (useful e.g.
|
static void |
println(String format,
Object... arguments)
Prints a line to standard out, with a leading message displaying the time and a trailing message indicating the location in the source code of the calling method.
|
static void |
reorder(BitSet bitSet,
int[] ordering)
adjusts the ordering of elements in the BitSet according to the ordering array.
|
static void |
reorder(boolean[] list,
int[] ordering)
adjusts the ordering of elements in the array according to the ordering array.
|
static void |
reorder(byte[] list,
int[] ordering)
adjusts the ordering of elements in the array according to the ordering array.
|
static void |
reorder(char[] list,
int[] ordering)
adjusts the ordering of elements in the array according to the ordering array.
|
static void |
reorder(int[] list,
int[] ordering)
adjusts the ordering of elements in the array according to the ordering array.
|
static <T> void |
reorder(List<T> list,
int[] ordering)
adjusts the ordering of elements in the array according to the ordering array.
|
static <T> boolean |
safeEquals(T a,
T b)
Safely checks whether two Objects are either equal (a.equals(b))
or both null, without ever throwing a NullPointerException.
|
static <T extends Comparable<? super T>> |
sort(List<T> list)
Just like
Collections.sort(java.util.List) but much faster in cases where list.size()<=2. |
static <T> void |
sort(List<T> list,
Comparator<? super T> comparator)
Just like
Collections.sort(java.util.List, java.util.Comparator) but much faster in cases where list.size()<=2. |
static void |
sort(Object[] arrayToSort)
Just like
Arrays.sort(Object[]) but much faster in cases where list.size()<=2. |
static <T> void |
sort(T[] arrayToSort,
Comparator<? super T> comparator)
Just like
Arrays.sort(Object[], java.util.Comparator) but much faster in cases where list.size()<=5. |
public static <T> boolean safeEquals(T a,
T b)
a - an Object whose equality to b is to be assessed, or null.b - an Object to which a's equality is to be assessed, or null.public static boolean attemptClose(Closeable closeable)
closeable - The closeable to close, or null to do nothingpublic static <T extends Comparable<? super T>> void sort(List<T> list)
Collections.sort(java.util.List) but much faster in cases where list.size()<=2.
This is because the Collections.sort implementation (as of Java 6 update 10) unnecessarily converts
to an array (even on length 0 lists) before sorting.list - the list to sort.public static <T> void sort(List<T> list, Comparator<? super T> comparator)
Collections.sort(java.util.List, java.util.Comparator) but much faster in cases where list.size()<=2.
This is because the Collections.sort implementation (as of Java 6 update 10) unnecessarily converts
to an array (even on length 0 lists) before sorting.list - the list to sort.comparator - the comparator to determine the order of the list. A
null value indicates that the elements' natural
ordering should be used.public static void sort(Object[] arrayToSort)
Arrays.sort(Object[]) but much faster in cases where list.size()<=2.
This is because the Arrays.sort implementation clones the array to be sorted even on empty arrays!arrayToSort - the array to sortpublic static <T> void sort(T[] arrayToSort,
Comparator<? super T> comparator)
Arrays.sort(Object[], java.util.Comparator) but much faster in cases where list.size()<=5.
This is because the Arrays.sort implementation clones the array to be sorted even on empty arrays!arrayToSort - the array to sortcomparator - the comparator to determine the order of the array. A
null value indicates that the elements' natural
ordering should be used.public static <T> void reorder(List<T> list, int[] ordering)
list - the list to reorder. May be null in which case this method does nothing.ordering - the reodering array as specified above. If this is less than the length of the list, then only the first ordering.length elements of list are reordered.public static void reorder(int[] list,
int[] ordering)
list - the list to reorder. May be null in which case this method does nothing.ordering - the reodering array as specified above. If this is less than the length of the list, then only the first ordering.length elements of list are reordered.public static void reorder(char[] list,
int[] ordering)
list - the list to reorder. May be null in which case this method does nothing.ordering - the reodering array as specified above. If this is less than the length of the list, then only the first ordering.length elements of list are reordered.public static void reorder(boolean[] list,
int[] ordering)
list - the list to reorder. May be null in which case this method does nothing.ordering - the reodering array as specified above. If this is less than the length of the list, then only the first ordering.length elements of list are reordered.public static void reorder(BitSet bitSet, int[] ordering)
bitSet - the BitSet to reorder. May be null in which case this method does nothing.ordering - the reordering array as specified above. If this is less than the length of the BitSet, then only the first ordering.length elements of BitSet are reordered.public static void reorder(byte[] list,
int[] ordering)
list - the list to reorder. May be null in which case this method does nothing.ordering - the reodering array as specified above. If this is less than the length of the list, then only the first ordering.length elements of list are reordered.public static void println(String format, Object... arguments)
format - a format string as specified by Formatterarguments - optional arguments to apply to the format string.