org.simbrain.util
Class Utils

java.lang.Object
  extended by org.simbrain.util.Utils

public class Utils
extends Object

Utils.


Constructor Summary
Utils()
           
 
Method Summary
static float colorToFloat(Color clr)
          returns the Hue associated with a Color.
static boolean containsName(ArrayList al, String theString)
          Checks whether an array list cantains a name, and warns you if it does.
static String doubleArrayToString(double[] data)
          Utility to class to convert arrays of doubles to strings.
static Color floatToHue(float fclr)
          Converts a floating point value into a color in HSB, with Saturation and Brightness 1.
static String getDir(File theFile)
          Get the directory component of a file.
static double[][] getDoubleMatrix(File theFile)
          Read a csv (comma-separated-values) files.
static String getNameFromPath(String thePath)
          Extract file name from a path description.
static String getRelativePath(String baseDir, String absolutePath)
          Helper method to create a relative path for use in saving simulation files which refer to files within directories.
static String[][] getStringMatrix(File theFile)
          Read a csv (comma-separated-values) files.
static String getVectorString(double[] theVec, String delimiter)
          Convert an array of doubles into a String.
static double[] getVectorString(String theVec, String delimiter)
          Convert a delimeted string of doubles into an array of doubles.
static String round(double num, int precision)
           
static void showQuickRef()
          Shows the quick reference guide in the help menu.
static void showQuickRef(String helpPage)
          Shows the quick reference guide in the help menu.
static double[] stringArrayToDoubleArray(String[] line)
          Converts an array of strings containing doubles into an array of values.
static void writeMatrix(String[][] data, File theFile)
          Save data as CSV (comma-separated-value) file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

getDoubleMatrix

public static double[][] getDoubleMatrix(File theFile)
Read a csv (comma-separated-values) files.

Parameters:
theFile - the file to read in
Returns:
an two-dimensional array of comma-separated values

getStringMatrix

public static String[][] getStringMatrix(File theFile)
Read a csv (comma-separated-values) files.

Parameters:
theFile - the file to read in
Returns:
an two-dimensional array of comma-separated values

writeMatrix

public static void writeMatrix(String[][] data,
                               File theFile)
Save data as CSV (comma-separated-value) file.

Parameters:
data - Data to be written
theFile - File to be written to

getRelativePath

public static String getRelativePath(String baseDir,
                                     String absolutePath)
Helper method to create a relative path for use in saving simulation files which refer to files within directories. Substracts the absolutePath of the local user directory from the absolute path of the file to be saved, and converts file-separators into forward slashes, which are used for saving simualtion files.

Parameters:
baseDir - absolute path of the local simbrain directory.
absolutePath - the absolute path of the file to be saved
Returns:
the relative path from the local directory to the file to be saved

getNameFromPath

public static String getNameFromPath(String thePath)
Extract file name from a path description.

Parameters:
thePath - the path
Returns:
the extracted file name

getDir

public static String getDir(File theFile)
Get the directory component of a file.

Parameters:
theFile - the file to get the directory of.
Returns:
the extracted directory path

getVectorString

public static String getVectorString(double[] theVec,
                                     String delimiter)
Convert an array of doubles into a String.

Parameters:
theVec - the array of doubles to convert
delimiter - Delimiter
Returns:
the String representation of the array

getVectorString

public static double[] getVectorString(String theVec,
                                       String delimiter)
Convert a delimeted string of doubles into an array of doubles. Undoes String getVectorString.

Parameters:
theVec - string version of vector
delimiter - delimeter used in that string
Returns:
the corresponding array of doubles

stringArrayToDoubleArray

public static double[] stringArrayToDoubleArray(String[] line)
Converts an array of strings containing doubles into an array of values.

Parameters:
line - the array of strings
Returns:
the array of doubles

doubleArrayToString

public static String doubleArrayToString(double[] data)
Utility to class to convert arrays of doubles to strings.

Parameters:
data - array of doubles
Returns:
string representation of that array

round

public static String round(double num,
                           int precision)
Parameters:
num - double to convert
precision - number of decimal places
Returns:
string representation of rounded decimal

containsName

public static boolean containsName(ArrayList al,
                                   String theString)
Checks whether an array list cantains a name, and warns you if it does.

Parameters:
al - the array list to check; must be an array of strings
theString - the name to check for
Returns:
true if the name is contained in the array, false otherwise

showQuickRef

public static void showQuickRef()
Shows the quick reference guide in the help menu. The quick reference is an html page in the Simbrain/doc directory


floatToHue

public static Color floatToHue(float fclr)
Converts a floating point value into a color in HSB, with Saturation and Brightness 1.

Parameters:
fclr - Float color
Returns:
Hue, saturation, and brightness

colorToFloat

public static float colorToFloat(Color clr)
returns the Hue associated with a Color.

Parameters:
clr - Color
Returns:
Hue, saturation and brightness

showQuickRef

public static void showQuickRef(String helpPage)
Shows the quick reference guide in the help menu. The quick reference is an html page in the Simbrain/doc directory.

Parameters:
helpPage - Help page