public class Utils
extends java.lang.Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static float |
colorToFloat(java.awt.Color clr)
Returns the Hue associated with a Color.
|
static <T> T[] |
concatenate(T[] A,
T[] B)
Concatenate two arrays A, B to produce a third array A + B.
|
static void |
displayLocalHtmlInBrowser(java.lang.String url)
Launch an .html page using the system's default browser.
|
static java.lang.String |
doubleArrayToString(double[] data)
Utility to class to convert arrays of doubles to strings.
|
static java.lang.String[] |
doubleArrayToStringArray(double[] line)
Converts an array of doubles into an array of Strings of those doubles.
|
static java.lang.String |
doubleMatrixToString(double[][] matrix)
Convert a 2-d array of doubles to a string.
|
static java.lang.String[][] |
doubleMatrixToStringMatrix(double[][] matrix)
Converts a matrix of doubles into a matrix of Strings representing those
doubles.
|
static double |
doubleParsable(javax.swing.JTextField tField)
Tests whether the string in a text field is parsable into a double.
|
static double |
doubleParsable(java.lang.String text)
Like
doubleParsable(JTextField) but checks for the formatting of a
string rather than a text field. |
static java.awt.Color |
floatToHue(float fclr)
Converts a floating point value into a color in HSB, with Saturation and
Brightness 1.
|
static java.lang.String |
getDir(java.io.File theFile)
Get the directory component of a file.
|
static double[][] |
getDoubleMatrix(java.io.File theFile)
Read a csv (comma-separated-values) files.
|
static java.lang.String |
getNameFromPath(java.lang.String thePath)
Extract file name from a path description.
|
(package private) static boolean |
getOSMatches(java.lang.String osNamePrefix)
Decides if the operating system matches.
|
static java.lang.String |
getRelativePath(java.lang.String baseDir,
java.lang.String absolutePath)
Helper method to create a relative path for use in saving simulation
files which refer to files within directories.
|
static java.util.Properties |
getSimbrainProperties()
Return the Simbrain properties file, or null if it is not found.
|
static java.lang.String[][] |
getStringMatrix(java.io.File theFile)
Read a csv (comma-separated-values) files.
|
static java.lang.String |
getTimeString()
Helper method that returns the date and time in a format that can be used
to create filenames.
|
static java.lang.String |
getVectorString(double[] theVec,
java.lang.String delimiter)
Convert an array of doubles into a String.
|
static double[] |
getVectorString(java.lang.String theVec,
java.lang.String delimiter)
Convert a delimited string of doubles into an array of doubles.
|
static java.util.Collection |
intersection(java.util.Collection a,
java.util.Collection b)
Re-implementation of same method from
org.apache.commons.collections.CollectionUtils.
|
static <T> boolean |
intersects(java.util.Collection<T> A,
java.util.Collection<T> B)
True if collection A has a non-empty intersection with collection B,
false otherwise.
|
static boolean |
isMacOSX()
Determines whether the system is a Mac os x.
|
static java.lang.Integer |
parseInteger(javax.swing.JTextField tField)
Parses the given String in the text field into an integer.
|
static java.lang.Integer |
parseInteger(java.lang.String text)
The same as
parseInteger(JTextField) except using a String
directly as an input. |
static double[] |
parseVectorString(java.lang.String vectorString)
Converts a String representation of a vector (e.g.
|
static java.lang.String |
readFileContents(java.io.File file)
Returns the contents of a file as a String.
|
static java.lang.String |
round(double num,
int precision)
Returns a string rounded to the desired precision.
|
static java.util.Collection |
select(java.util.Collection selection,
Predicate filter)
Reimplementation of same method from
org.apache.commons.collections.CollectionUtils.
|
static int |
setAlpha(int alpha,
int rgbIntColor)
Sets the alpha of the color represented by rgBInt to the value specified
in alpha and returns the resulting color.
|
static int |
setBlue(int blue,
int rgbIntColor)
Sets the blue value of the color represented by rgbIntColor to the value
specified by blue and returns the resulting color.
|
static int |
setGreen(int green,
int rgbIntColor)
Sets the green value of the color represented by rgbIntColor to the value
specified by green and returns the resulting color.
|
static int |
setRed(int red,
int rgbIntColor)
Sets the red value of the color represented by rgbIntColor to the value
specified by red and returns the resulting color.
|
static void |
showHelpPage(java.lang.String helpPage)
Display a documentation page under {simbrainhome}/docs/...
|
static double[] |
stringArrayToDoubleArray(java.lang.String[] line)
Converts an array of strings containing doubles into an array of doubles.
|
static java.util.Collection |
union(java.util.Collection a,
java.util.Collection b)
Re-implementation of same method from
org.apache.commons.collections.CollectionUtils.
|
static void |
writeMatrix(double[][] data,
java.io.File theFile)
Write a matrix of doubles to a file.
|
static void |
writeMatrix(java.lang.String[][] data,
java.io.File theFile)
Save data as CSV (comma-separated-value) file.
|
public static java.lang.String getTimeString()
public static double[][] getDoubleMatrix(java.io.File theFile)
theFile
- the file to read inpublic static java.lang.String[][] getStringMatrix(java.io.File theFile)
theFile
- the file to read inpublic static void writeMatrix(double[][] data, java.io.File theFile)
data
- the matrix of doubles to writetheFile
- the file to write topublic static void writeMatrix(java.lang.String[][] data, java.io.File theFile)
data
- Data to be writtentheFile
- File to be written topublic static java.lang.String getRelativePath(java.lang.String baseDir, java.lang.String absolutePath)
baseDir
- absolute path of the local simbrain directory.absolutePath
- the absolute path of the file to be savedpublic static java.lang.String getNameFromPath(java.lang.String thePath)
thePath
- the pathpublic static java.lang.String getDir(java.io.File theFile)
theFile
- the file to get the directory of.public static double doubleParsable(javax.swing.JTextField tField)
tField
- The text field to read from and test if its text can be
parsed into a double valuepublic static double doubleParsable(java.lang.String text)
doubleParsable(JTextField)
but checks for the formatting of a
string rather than a text field.text
- the text to checkpublic static java.lang.Integer parseInteger(javax.swing.JTextField tField)
tField
- the text field containing the String to be parsed.public static java.lang.Integer parseInteger(java.lang.String text)
parseInteger(JTextField)
except using a String
directly as an input.text
- public static java.lang.String getVectorString(double[] theVec, java.lang.String delimiter)
theVec
- the array of doubles to convertdelimiter
- Delimiterpublic static double[] getVectorString(java.lang.String theVec, java.lang.String delimiter)
theVec
- string version of vectordelimiter
- delimiter used in that stringpublic static double[] stringArrayToDoubleArray(java.lang.String[] line)
line
- the array of stringspublic static java.lang.String[] doubleArrayToStringArray(double[] line)
line
- the array of doublespublic static java.lang.String[][] doubleMatrixToStringMatrix(double[][] matrix)
matrix
- the matrix of doublespublic static java.lang.String doubleArrayToString(double[] data)
data
- array of doublespublic static double[] parseVectorString(java.lang.String vectorString)
vectorString
- the string to parse.public static java.lang.String round(double num, int precision)
num
- double to convertprecision
- number of decimal placespublic static void showHelpPage(java.lang.String helpPage)
helpPage
- Help pagepublic static void displayLocalHtmlInBrowser(java.lang.String url)
url
- the url to display. Assumes it is in the local file system.public static java.awt.Color floatToHue(float fclr)
fclr
- Float colorpublic static float colorToFloat(java.awt.Color clr)
clr
- Colorpublic static int setAlpha(int alpha, int rgbIntColor)
alpha
- an opacity value on [0, 255]rgbIntColor
- an integer representing a color where bits 0-7 are
blue, 8-15 are green, 16-23 are red, and 24-31 are alphapublic static int setRed(int red, int rgbIntColor)
red
- a red value on [0, 255]rgbIntColor
- an integer representing a color where bits 0-7 are
blue, 8-15 are green, 16-23 are red, and 24-31 are alphapublic static int setGreen(int green, int rgbIntColor)
green
- a green value on [0, 255]rgbIntColor
- an integer representing a color where bits 0-7 are
blue, 8-15 are green, 16-23 are red, and 24-31 are alphapublic static int setBlue(int blue, int rgbIntColor)
blue
- a blue value on [0, 255]rgbIntColor
- an integer representing a color where bits 0-7 are
blue, 8-15 are green, 16-23 are red, and 24-31 are alphapublic static java.lang.String doubleMatrixToString(double[][] matrix)
matrix
- the matrix to printstatic boolean getOSMatches(java.lang.String osNamePrefix)
Decides if the operating system matches.
Source adapted from org.apache.commons.lang.SystemUtilsosNamePrefix
- the prefix for the os namepublic static boolean isMacOSX()
public static java.util.Collection select(java.util.Collection selection, Predicate filter)
selection
- the collection to filterfilter
- the predicate to be used in filtering.public static java.util.Collection union(java.util.Collection a, java.util.Collection b)
a
- Collectionb
- Collectionpublic static java.util.Collection intersection(java.util.Collection a, java.util.Collection b)
a
- Collectionb
- Collectionpublic static java.util.Properties getSimbrainProperties()
public static java.lang.String readFileContents(java.io.File file)
file
- the file to readpublic static <T> T[] concatenate(T[] A, T[] B)
T
- type of the arrays to concatenateA
- first arrayB
- second arraypublic static <T> boolean intersects(java.util.Collection<T> A, java.util.Collection<T> B)
T
- A
- first collectionB
- second collection