public class Util
extends java.lang.Object
Constructor and Description |
---|
Util() |
Modifier and Type | Method and Description |
---|---|
static void |
addAll(java.util.HashSet<java.lang.Integer> set,
int[] array)
Adds all items in a primitive array to the given hash set
|
static void |
addAll(java.util.LinkedHashSet<java.lang.Integer> set,
int[] array)
Adds all items in a primitive array to the given linked hash set
|
static void |
addAll(java.util.LinkedList<java.lang.Integer> list,
int[] array)
Adds all items in a primitive array to the given linked list
|
static boolean |
areAnyObjectsNull(java.lang.Object... objects)
Checks if any of the objects are null
|
static int |
checkForPositiveInteger(java.lang.String input)
Checks if a String is a positive integer.
|
static java.nio.ByteBuffer |
cloneByteBuffer(java.nio.ByteBuffer original)
Deep copy of ByteBuffer.
|
static java.util.LinkedList<java.lang.Integer> |
convertArray(int[] array)
Converts an int[] to a LinkedList of Integer using streams
|
static void |
convertArray(int[] array,
java.util.HashSet<java.lang.Integer> set)
Converts an int[] to a HashSet of Integer using streams
|
static void |
convertArray(int[] array,
java.util.LinkedList<java.lang.Integer> list)
Converts an int[] to a LinkedList of Integer using streams
|
static int[] |
convertArrayList(java.util.ArrayList<java.lang.Integer> list)
Converts a ArrayList of Integer to an int[] using streams
|
static int[] |
convertHashSet(java.util.HashSet<java.lang.Integer> set)
Converts a HashSet of Integer to int[]
|
static void |
convertHashSet(int[] array,
java.util.HashSet<java.lang.Integer> set)
Converts a HashSet of Integer to a given int[]
|
static int[] |
convertLinkedList(java.util.LinkedList<java.lang.Integer> list)
Converts a LinkedList of Integer to an int[] using streams
|
static void |
convertLinkedList(java.util.LinkedList<java.lang.Integer> list,
int[] array)
Converts a LinkedList of Integer to a given int[] using streams
|
static <T> void |
convertLinkedListObject(java.util.LinkedList<T> list,
T[] array)
Converts a LinkedList of any given object into an array of that object
|
static java.lang.String |
dateAsString()
Returns the current date as yyyyMMdd_HHmm
|
static <T> T |
getFromHashSet(java.util.HashSet<T> set,
int number)
Gets a specific numbered item from the HashSet given.
There is no guarantee this may pick the same entry if run multiple times. |
static double |
mean(double[] array)
Returns the arithmetic mean of an array of doubles
|
static <T> T |
pickRandom(java.util.Random r,
java.util.ArrayList<T> list)
Picks a random item from a list
|
static int |
pickValidItem(java.util.Random r,
int size,
java.util.Collection<java.lang.Integer> deleteList)
Picks a random int in the range of 0(inc) to size(exc) where the int is not in deleteList
|
static <T> java.util.ArrayList<T> |
randomSelection(java.util.Random r,
int number,
java.util.ArrayList<T> target)
Picks a random sublist of a list.
|
static double |
round(double d,
int decimalPlaces)
Round to the given number of decimal places.
|
static int[] |
roundAndConvert(double[] toConvert,
int places)
Rounds and Converts a double[].
|
static int |
roundAndConvert(double toConvert,
int places)
Rounds and Converts a double.
|
static int[] |
roundAndConvert(int[] res,
double[] toConvert,
int places)
Rounds and Converts a double[].
|
static int[] |
roundArray(double[] arr)
Rounds and sorts a double[] to an int[]
|
static int[][] |
roundArray(double[][] arr)
Rounds and sorts a double[][] to an int[][]
|
static double[] |
roundArray(double[] arr,
int decimalPlaces)
Rounds and a double[] to a less precise double[]
|
static <T extends java.lang.Number> |
standardDeviation(java.util.ArrayList<T> array,
double mean)
Returns the standard deviation of an array
|
static double |
standardDeviation(double[] array,
double mean)
Returns the standard deviation of an array
|
static <T> java.util.List<T> |
subList(java.util.ArrayList<T> list,
int start,
int end)
Returns a sublist.
A copy of List.sublist() except the end is checked and shortened if too long |
public static int[][] roundArray(double[][] arr)
arr
- a double[][] to be roundedpublic static int[] roundArray(double[] arr)
arr
- a double[] to be roundedpublic static double[] roundArray(double[] arr, int decimalPlaces)
arr
- a double[] to be roundeddecimalPlaces
- the amount of decimal places to round each double in arrpublic static double round(double d, int decimalPlaces)
d
- a double to be roundeddecimalPlaces
- the number of decimal placespublic static int[] roundAndConvert(double[] toConvert, int places)
toConvert
- The array to convertplaces
- The number of decimal places to be retainedpublic static int[] roundAndConvert(int[] res, double[] toConvert, int places)
res
- The array to be populatedtoConvert
- The array to convertplaces
- The number of decimal places to be retainedpublic static int roundAndConvert(double toConvert, int places)
toConvert
- The double to convertplaces
- The number of decimal places to be retainedpublic static int checkForPositiveInteger(java.lang.String input) throws java.lang.NumberFormatException
input
- The String to be convertedjava.lang.NumberFormatException
- If the input is not an integer, or $lt; 0.public static <T> void convertLinkedListObject(java.util.LinkedList<T> list, T[] array)
T
- The type of objects in the listlist
- The list to be convertedarray
- The array to be populated with the new objectspublic static int[] convertLinkedList(java.util.LinkedList<java.lang.Integer> list)
list
- The linked list to convertpublic static int[] convertArrayList(java.util.ArrayList<java.lang.Integer> list)
list
- The ArrayList to convertpublic static void convertLinkedList(java.util.LinkedList<java.lang.Integer> list, int[] array)
list
- The linked list to convertarray
- The array to be populatedpublic static java.util.LinkedList<java.lang.Integer> convertArray(int[] array)
array
- The array to convertpublic static void convertArray(int[] array, java.util.LinkedList<java.lang.Integer> list)
array
- The array to convertlist
- The newly populated LinkedListpublic static void addAll(java.util.LinkedList<java.lang.Integer> list, int[] array)
list
- The list to be added toarray
- The array of items to addpublic static void addAll(java.util.LinkedHashSet<java.lang.Integer> set, int[] array)
set
- The set to be added toarray
- The array of items to addpublic static void addAll(java.util.HashSet<java.lang.Integer> set, int[] array)
set
- The set to be added toarray
- The array of items to addpublic static int[] convertHashSet(java.util.HashSet<java.lang.Integer> set)
set
- The set to be convertedpublic static void convertHashSet(int[] array, java.util.HashSet<java.lang.Integer> set)
set
- The set to be convertedarray
- The newly converted arraypublic static void convertArray(int[] array, java.util.HashSet<java.lang.Integer> set)
array
- The array to convertset
- The set to store the results inpublic static java.nio.ByteBuffer cloneByteBuffer(java.nio.ByteBuffer original)
original
- the ByteBuffer to copypublic static <T> T getFromHashSet(java.util.HashSet<T> set, int number)
T
- The type of object in the setset
- The Set to look throughnumber
- The item nmber to returnpublic static <T> java.util.List<T> subList(java.util.ArrayList<T> list, int start, int end)
T
- The type of object in the listlist
- The list to have a sublist ofstart
- The start indexend
- The end indexpublic static double mean(double[] array)
array
- The arraypublic static double standardDeviation(double[] array, double mean)
array
- The array itselfmean
- The mean of the arraypublic static <T extends java.lang.Number> double standardDeviation(java.util.ArrayList<T> array, double mean)
T
- The type of object in the array. Must be a Number.array
- The array itselfmean
- The mean of the arraypublic static <T> java.util.ArrayList<T> randomSelection(java.util.Random r, int number, java.util.ArrayList<T> target) throws FastGraphException
T
- The type of object in the listr
- The Random generatornumber
- The number of items to choosetarget
- The items to choose fromFastGraphException
- If the list is too smallpublic static java.lang.String dateAsString()
public static int pickValidItem(java.util.Random r, int size, java.util.Collection<java.lang.Integer> deleteList)
r
- Random number generatorsize
- The range of items to pickdeleteList
- But not in this listpublic static <T> T pickRandom(java.util.Random r, java.util.ArrayList<T> list)
T
- The type of object in the listr
- Random number generatorlist
- The list to pick frompublic static boolean areAnyObjectsNull(java.lang.Object... objects)
objects
- The objects to check