org.prorefactor.core
Class Util

java.lang.Object
  extended by org.prorefactor.core.Util

public class Util
extends java.lang.Object

General purpose utilities


Field Summary
static java.lang.String LINESEP
          OS specific text file line seperator - '\n' on unix, "\r\n" on Windows
 
Constructor Summary
Util()
           
 
Method Summary
static void copyAllFiles(java.io.File sourceDir, java.io.File targetDir)
          Copy all files from one directory to another.
static void fileAppend(java.lang.String target, java.lang.String source)
          Append one file to another.
static void fileAppendString(java.lang.String target, java.lang.String source)
          Append a string to a file.
static void fileCopy(java.lang.String from, java.lang.String to)
          Copy a file.
static java.lang.String getExceptionText(java.lang.Throwable e)
           
static boolean isInRange(int x, int y, int[] begin, int[] end)
          Assuming an x,y range, this function returns whether an input x and y are within the specified range of x,y begin and x,y end.
static java.util.List permsList(java.util.List topList)
          Given a mainlist of sublists, return a new newlist of newsublists, such that: - the number of newsublists is the number of "cycles" ("permutations"?) - each newsublist has the same number of objects in it as the original mainlist had sublists.
static java.lang.StringBuffer readFile(java.io.File from)
          Read the contents of a file into a StringBuffer
static java.util.ArrayList split(java.lang.String s, char divider)
          Deprecated. Use Java 1.4 String.split() instead.
static boolean wipeDirectory(java.io.File dir, boolean recursive)
          Delete all files and directories within a directory - causes the specified directory to be empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINESEP

public static final java.lang.String LINESEP
OS specific text file line seperator - '\n' on unix, "\r\n" on Windows

Constructor Detail

Util

public Util()
Method Detail

copyAllFiles

public static void copyAllFiles(java.io.File sourceDir,
                                java.io.File targetDir)
                         throws java.io.IOException
Copy all files from one directory to another. Target directory does not have to exist - this will create it. Is not recursive (does not copy subdirectories).

Throws:
java.io.IOException

fileAppend

public static void fileAppend(java.lang.String target,
                              java.lang.String source)
                       throws java.io.IOException
Append one file to another.

Parameters:
target - The file that gets appended to.
source - The file to append.
Throws:
java.io.IOException

fileAppendString

public static void fileAppendString(java.lang.String target,
                                    java.lang.String source)
                             throws java.io.IOException
Append a string to a file.

Parameters:
target - The file that gets appended to.
source - The string to append.
Throws:
java.io.IOException

fileCopy

public static void fileCopy(java.lang.String from,
                            java.lang.String to)
                     throws java.io.IOException
Copy a file.

Parameters:
from - filename to copy from
to - filename to copy to
Throws:
java.io.IOException

getExceptionText

public static java.lang.String getExceptionText(java.lang.Throwable e)

isInRange

public static boolean isInRange(int x,
                                int y,
                                int[] begin,
                                int[] end)
Assuming an x,y range, this function returns whether an input x and y are within the specified range of x,y begin and x,y end. We use this primarily for checking if a line/column are within the specified range. The "range" may be open ended, see parameter descriptions.

Parameters:
x - The x value to check that it is within range
y - The y value to check that it is within range
begin - An array of 2 integers to specify the beginning of the x,y range. May be null to indicate that the beginning is open ended.
end - An array of 2 integers to specify the ending of the x,y range. May be null to indicate that the beginning is open ended.
Returns:

permsList

public static java.util.List permsList(java.util.List topList)
Given a mainlist of sublists, return a new newlist of newsublists, such that: - the number of newsublists is the number of "cycles" ("permutations"?) - each newsublist has the same number of objects in it as the original mainlist had sublists. There is one object from each of the original sublists. (i.e. If the mainlist contains 3 sublists, and the number of items in the sublists is: 2, 1, 4, then the number of cycles is: 2 * 1 * 4 = 8. The newlist will contain 8 newsublists with three objects each.) (Might be easier to think of the return list as a matrix of m by n, where m (rows) is the number of original sublists, and n (columns) is the number of cycles/permutations.) I'm sure there's proper terminology and algorithms for this, but I don't know what they are.


readFile

public static java.lang.StringBuffer readFile(java.io.File from)
                                       throws java.io.IOException
Read the contents of a file into a StringBuffer

Throws:
java.io.IOException

split

public static java.util.ArrayList split(java.lang.String s,
                                        char divider)
Deprecated. Use Java 1.4 String.split() instead.

Split a string into pieces based on the given divider character. Used for Java 1.3 compatability - String.split() is new as of 1.4.

Parameters:
s - the string to split
divider - the character on which to split. Occurrences of this character are not included in the output
Returns:
An ArrayList of the pieces.

wipeDirectory

public static boolean wipeDirectory(java.io.File dir,
                                    boolean recursive)
                             throws java.io.IOException
Delete all files and directories within a directory - causes the specified directory to be empty.

Parameters:
dir - A File object for the directory to be emptied.
recursive - Recursively delete subdirectories?
Returns:
false if any files or directories could not be deleted.
Throws:
java.io.IOException


Copyright © 2008 Joanju Software. All Rights Reserved.