public class UtilityOperations
extends java.lang.Object
| Constructor and Description |
|---|
UtilityOperations() |
| Modifier and Type | Method and Description |
|---|---|
static java.io.File |
findFile(java.lang.String toFind)
Given the path of a path relative to the Magpie jar, find the actual path.
|
static boolean |
isInteger(java.lang.String str)
Determine whether a string represents an integer.
|
static java.lang.Object |
loadState(java.io.InputStream input)
Read in a Magpie object from a stream
|
static java.lang.Object |
loadState(java.lang.String filename)
Read the state from file using serialization
|
static java.lang.String |
millisecondsToString(long time)
Print a time, stored in milliseconds, into a human-readable string.
|
static <T> java.util.List<java.util.List<T>> |
partitionList(java.util.List<T> toSplit,
int nPartitions)
Split a list into smaller sublists that are as equally-sized as possible.
|
static void |
printRunTime(long start_time)
Print elapsed time to screen
|
static void |
saveState(java.lang.Object obj,
java.io.OutputStream output)
Use serialization to save object state to an output stream
|
static void |
saveState(java.lang.Object obj,
java.lang.String filename)
Use serialization to save object state to file
|
static int[] |
sortAndGetRanks(double[] x,
boolean descending)
Sort an array and return the original indices of the each value.
|
static int[] |
sortAndGetRanks(double[] x,
java.util.Comparator<java.lang.Double> comp)
Sort an array and return the original index of each member.
|
static org.json.JSONArray |
toJSONArray(double[] array)
Convert an array of doubles into a JSON array.
|
public static java.lang.Object loadState(java.lang.String filename)
throws java.lang.Exception
filename - Filename for inputjava.lang.Exceptionpublic static java.lang.Object loadState(java.io.InputStream input)
throws java.io.IOException,
java.lang.ClassNotFoundException
input - Input streamjava.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic static void saveState(java.lang.Object obj,
java.lang.String filename)
throws java.io.IOException
obj - Object to be serialized and savedfilename - Desired filenamejava.io.IOExceptionpublic static void saveState(java.lang.Object obj,
java.io.OutputStream output)
throws java.io.IOException
obj - Outputoutput - Output streamjava.io.IOExceptionpublic static void printRunTime(long start_time)
start_time - When operation started (as reported by System.currentTimeMillis())public static boolean isInteger(java.lang.String str)
str - String containing a single wordpublic static java.io.File findFile(java.lang.String toFind)
toFind - Relative path to file or directory (e.g. "py/lasso.py")public static <T> java.util.List<java.util.List<T>> partitionList(java.util.List<T> toSplit,
int nPartitions)
toSplit - List to be splitnPartitions - Number of partitions to createpublic static org.json.JSONArray toJSONArray(double[] array)
Changes in NaN or inf values into strings (JSON doesn't support these as numbers
array - Array to be convertedpublic static java.lang.String millisecondsToString(long time)
time - Time in millisecondspublic static int[] sortAndGetRanks(double[] x,
boolean descending)
x - Array to be sorteddescending - Whether to sort the list in descending orderpublic static int[] sortAndGetRanks(double[] x,
java.util.Comparator<java.lang.Double> comp)
x - Array to be sortedcomp - How to compare entries in the array