ucl.physiol.neuroconstruct.utils
Class GeneralUtils

java.lang.Object
  extended by ucl.physiol.neuroconstruct.utils.GeneralUtils

public class GeneralUtils
extends Object

Assorted handy utilities

Author:
Padraig Gleeson

Field Summary
static String ARCH_64BIT
           
static String ARCH_I386
           
static String ARCH_I686
           
static String ARCH_POWERPC
           
static String ARCH_UMAC
           
static String DIR_64BIT
           
static String DIR_I686
           
static String DIR_POWERPC
           
static String DIR_UMAC
           
 
Constructor Summary
GeneralUtils()
           
 
Method Summary
static String convertToCygwinPath(String winPath)
          Converts c\:temp to /cygdrive/c/temp etc.
static boolean copyDirIntoDir(File originalDir, File dirToCopyTo, boolean includeSubDirs, boolean ignoreCVS)
           
static File copyFileIntoDir(File originalFile, File dirToCopyTo)
           
static String getArchSpecificDir()
           
static String getBetterFileName(String oldName)
          Does a quick check for spaces, etc.
static String getBold(float num, boolean tabIt)
           
static String getBold(int num, boolean tabIt)
           
static String getBold(String text, boolean tabIt)
           
static String getBoldColouredString(String text, String colour, boolean html)
          Quick way to get either a string in plaintext, or a html coloured string depending on a boolean value
static String getColouredString(String text, String colour, boolean html)
          Quick way to get either a string in plaintext, or a html coloured string depending on a boolean value
static String getCurrentDateAsNiceString()
           
static String getCurrentTimeAsNiceString()
           
static String getCurrentTimeAsNiceStringWithMillis()
           
static String getEndLine(boolean html)
           
static Color getFractionalColour(Color zeroColour, Color oneColour, double fraction)
          Gets a colour the specified fraction along a line between the two colours in 3D Red Green Blue space.
static String getLocalHostname()
           
static String getMaxLenLine(String line, int maxLength)
           
static String getMinLenLine(String line, int minLength)
          Handy to ensure printed comments etc.
static String getNiceStringForSeconds(String timeInSeconds)
           
static ArrayList getOrderedList(Enumeration en, boolean ascending)
           
static Color getRainbowColour(double fraction)
          Gets a colour from Red to Violet, based on the fraction given.
static String getTabbedString(String text, String tabName, boolean tabIt)
          Quick way to get either a string in plaintext, or a html formatted string depending on a boolean value
static boolean includeOsbProjects()
           
static boolean includeParallelFunc()
          A simple check on whether to incl parallel/Python functionality.
static String incrementName(String name)
          Convenient function for creating an incremented string, e.g.
static boolean is64bitPlatform()
           
static boolean isLinuxBasedPlatform()
           
static boolean isMacBasedPlatform()
           
static boolean isVersionControlDir(File dir)
           
static boolean isVersionControlDir(String dirname)
           
static boolean isWindowsBasedPlatform()
           
static void main(String[] args)
           
static String parseForHyperlinks(String text)
           
static void printMemory(boolean forcePrint)
           
static String readShortFile(File shortFile)
           
static void removeAllFiles(File directory, boolean warn, boolean removeDirToo, boolean removeVC)
           
static AbstractList reorderAlphabetically(AbstractList list, boolean ascending)
           
static File[] reorderAlphabetically(File[] files, boolean ascending)
           
static String replaceAllTokens(String line, String oldToken, String newToken)
          Replaces all occurances of the old token with the new one
static String replaceToken(String line, String oldToken, String newToken, int fromIndex)
          Replaces the first occurance of the old token with the new one from the specified index
static void timeCheck(String marker)
          Prints the current time and the time since the function was last called Useful for timing methods
static void timeCheck(String marker, boolean alsoSysOut)
          Prints the current time and the time since the function was last called Useful for timing methods
static ArrayList<File> toArrayList(File[] files)
           
 String truncateString(String longString, int length, boolean dotsToo)
          Truncates a long string to the maximum length specified, and optionally adds three dots...
static String wrapLine(String origLine, String endLine, int wrapLength)
          Assumes a long string input, into which an endLine (usually \n or
) will be placed after every wrap characters
static void writeShortFile(File shortFile, String contents)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARCH_I686

public static final String ARCH_I686
See Also:
Constant Field Values

ARCH_I386

public static final String ARCH_I386
See Also:
Constant Field Values

ARCH_64BIT

public static final String ARCH_64BIT
See Also:
Constant Field Values

ARCH_POWERPC

public static final String ARCH_POWERPC
See Also:
Constant Field Values

ARCH_UMAC

public static final String ARCH_UMAC
See Also:
Constant Field Values

DIR_I686

public static final String DIR_I686
See Also:
Constant Field Values

DIR_64BIT

public static final String DIR_64BIT
See Also:
Constant Field Values

DIR_POWERPC

public static final String DIR_POWERPC
See Also:
Constant Field Values

DIR_UMAC

public static final String DIR_UMAC
See Also:
Constant Field Values
Constructor Detail

GeneralUtils

public GeneralUtils()
Method Detail

getArchSpecificDir

public static String getArchSpecificDir()
Returns:
i686 for most, x86_64 if "64" present in system properties os.arch, e.g. amd64. Will need updating as Neuron tested on more platforms...

is64bitPlatform

public static boolean is64bitPlatform()

isWindowsBasedPlatform

public static boolean isWindowsBasedPlatform()

isVersionControlDir

public static boolean isVersionControlDir(String dirname)

isVersionControlDir

public static boolean isVersionControlDir(File dir)

includeParallelFunc

public static boolean includeParallelFunc()
A simple check on whether to incl parallel/Python functionality. This is turned off in the released version as the parallel func is buggy


includeOsbProjects

public static boolean includeOsbProjects()

isLinuxBasedPlatform

public static boolean isLinuxBasedPlatform()

isMacBasedPlatform

public static boolean isMacBasedPlatform()

getLocalHostname

public static String getLocalHostname()

printMemory

public static void printMemory(boolean forcePrint)

writeShortFile

public static void writeShortFile(File shortFile,
                                  String contents)
                           throws IOException
Throws:
IOException

readShortFile

public static String readShortFile(File shortFile)

timeCheck

public static void timeCheck(String marker)
Prints the current time and the time since the function was last called Useful for timing methods

Parameters:
marker - A string identifing the time step

timeCheck

public static void timeCheck(String marker,
                             boolean alsoSysOut)
Prints the current time and the time since the function was last called Useful for timing methods

Parameters:
marker - A string identifing the time step
alsoSysOut - If true, also prints output to system out

truncateString

public String truncateString(String longString,
                             int length,
                             boolean dotsToo)
Truncates a long string to the maximum length specified, and optionally adds three dots...


getCurrentTimeAsNiceStringWithMillis

public static String getCurrentTimeAsNiceStringWithMillis()

getNiceStringForSeconds

public static String getNiceStringForSeconds(String timeInSeconds)

getCurrentTimeAsNiceString

public static String getCurrentTimeAsNiceString()

getCurrentDateAsNiceString

public static String getCurrentDateAsNiceString()

toArrayList

public static ArrayList<File> toArrayList(File[] files)

reorderAlphabetically

public static File[] reorderAlphabetically(File[] files,
                                           boolean ascending)

reorderAlphabetically

public static AbstractList reorderAlphabetically(AbstractList list,
                                                 boolean ascending)

getOrderedList

public static ArrayList getOrderedList(Enumeration en,
                                       boolean ascending)

parseForHyperlinks

public static String parseForHyperlinks(String text)

replaceToken

public static String replaceToken(String line,
                                  String oldToken,
                                  String newToken,
                                  int fromIndex)
Replaces the first occurance of the old token with the new one from the specified index


replaceAllTokens

public static String replaceAllTokens(String line,
                                      String oldToken,
                                      String newToken)
Replaces all occurances of the old token with the new one


incrementName

public static String incrementName(String name)
Convenient function for creating an incremented string, e.g. Section_2 out of Section_1, etc.


getBetterFileName

public static String getBetterFileName(String oldName)
Does a quick check for spaces, etc.


getTabbedString

public static String getTabbedString(String text,
                                     String tabName,
                                     boolean tabIt)
Quick way to get either a string in plaintext, or a html formatted string depending on a boolean value


getBold

public static String getBold(String text,
                             boolean tabIt)

getBold

public static String getBold(int num,
                             boolean tabIt)

getBold

public static String getBold(float num,
                             boolean tabIt)

getColouredString

public static String getColouredString(String text,
                                       String colour,
                                       boolean html)
Quick way to get either a string in plaintext, or a html coloured string depending on a boolean value


getBoldColouredString

public static String getBoldColouredString(String text,
                                           String colour,
                                           boolean html)
Quick way to get either a string in plaintext, or a html coloured string depending on a boolean value


getEndLine

public static String getEndLine(boolean html)

getMaxLenLine

public static String getMaxLenLine(String line,
                                   int maxLength)

getMinLenLine

public static String getMinLenLine(String line,
                                   int minLength)
Handy to ensure printed comments etc. are the same width...


copyFileIntoDir

public static File copyFileIntoDir(File originalFile,
                                   File dirToCopyTo)
                            throws IOException
Throws:
IOException

copyDirIntoDir

public static boolean copyDirIntoDir(File originalDir,
                                     File dirToCopyTo,
                                     boolean includeSubDirs,
                                     boolean ignoreCVS)
                              throws IOException
Throws:
IOException

getFractionalColour

public static Color getFractionalColour(Color zeroColour,
                                        Color oneColour,
                                        double fraction)
Gets a colour the specified fraction along a line between the two colours in 3D Red Green Blue space.


getRainbowColour

public static Color getRainbowColour(double fraction)
Gets a colour from Red to Violet, based on the fraction given. Roughly a colour of the rainbow...


convertToCygwinPath

public static String convertToCygwinPath(String winPath)
Converts c\:temp to /cygdrive/c/temp etc. as used by cygwin.


removeAllFiles

public static void removeAllFiles(File directory,
                                  boolean warn,
                                  boolean removeDirToo,
                                  boolean removeVC)

wrapLine

public static String wrapLine(String origLine,
                              String endLine,
                              int wrapLength)
Assumes a long string input, into which an endLine (usually \n or
) will be placed after every wrap characters


main

public static void main(String[] args)