|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--xbn.XBNObject | +--xbn.util.Utility
Random functions.
Source code: Utility.java
Fields inherited from class xbn.XBNObject |
bFALSE_IN_PRODUCTION, bTRUE_IN_PRODUCTION, sCNSTR, sES, sLINE_SEP |
Constructor Summary | |
Utility()
Create a Utility. |
Method Summary | |
void |
appendFileText(StringOrBuffer str_orBfr,
String s_fileName)
Read all text in from a file and append it onto a StringOrBuffer. |
void |
appendWebPage(StringOrBuffer str_orBfr,
String s_httpUrl,
char[] ac_endingString)
Read all text in from a web page, and append it onto a StringOrBuffer. |
void |
crashIfBadMLCs(StringOrBuffer sob_code,
String s_mlcStart,
String s_mlcEnd)
Analyzes the provided code, and crashes with a specific error message if any multi-line comments are invalidly formatted. |
void |
elimJSFunction(String s_function,
StringOrBuffer sob_code)
Eliminate the requested function from your JavaScript code. |
static StringBuffer |
getActlCmdLineParams(String[] as_cmdLineParams)
A utility function for applications to get all of the actually-provided command line parameters. |
Hashtable |
getOptimizedHT(Hashtable h_ashtable)
Get an optimized version of the provided Hashtable. |
s_acs_acs[] |
getPackageDependencies(String s_baseDir,
int i_subDirLevels,
Outputter optr_dbg,
String[] as_acceptPkgPre,
boolean b_crashIfSelfDependent,
FileFilter file_filter)
For all packages in the provided directory path, find out which packages are dependent on each other. |
boolean |
getRandomBoolean()
Get a random boolean. |
int |
getRandomInt(int i_max)
Get a random int. |
int |
getRandomInt(int i_min,
int i_max)
Get a random int between the desired bounds. |
void |
stripMLCs(StringOrBuffer sob_code,
String s_mlcStart,
String s_mlcEnd)
String all multi-line comments out of the provided code. |
void |
stripSLCs(StringOrBuffer sob_sourceCode,
String s_slcDelimiter)
Eliminate all single line comments from the source code. |
Methods inherited from class xbn.XBNObject |
getXMsgPrefix, sop, sopl, sopl, throwAX, throwAXIfBadStr, throwAXIfNull, throwAXSpoof |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Utility()
Create a Utility. This constructor does nothing.
Method Detail |
public static final StringBuffer getActlCmdLineParams(String[] as_cmdLineParams)
A utility function for applications to get all of the actually-provided command line parameters.
This returns all values contained in the provided string array, space delimiting each. If any value contains spaces, then it is put inside of double quotes (unless it contains a double quote, in which case it is put inside single quotes).
If there are no parameters, the empty string ('') is returned.
public final boolean getRandomBoolean()
Get a random boolean.
(getRandomInt(0, 1) == 1)
public final int getRandomInt(int i_max)
Get a random int.
getRandomInt(0, i_max)
public final int getRandomInt(int i_min, int i_max)
Get a random int between the desired bounds.
i_min
- The minimum possible int to return. May not be greater than i_max.i_max
- The maximum possible int to return. May not be less than i_min.public final Hashtable getOptimizedHT(Hashtable h_ashtable)
Get an optimized version of the provided Hashtable.
A Hashtable is only optimized as long as no other objects are added to it.
h_ashtable
- The Hashtable to optimize. May not be null and h_ashtable.size must be one or greater.h_ashtable.size()
, and it's "load factor" is set to 1, meaning "100%". That is, when a new object is added (causing the total number of objects to exceed [size * loadfactor]) capacity is added to the Hashtable, decreasing its efficiency. Therefore, if no more objects are added to this hashtable, it's capacity never changes and retrieving objects from it is as quick and efficient as possible.public final void appendWebPage(StringOrBuffer str_orBfr, String s_httpUrl, char[] ac_endingString) throws MalformedURLException, IOException
Read all text in from a web page, and append it onto a StringOrBuffer.
I got this from http://www.davidreilly.com/java/java_network_programming/
, item 2.3.
Be aware that this is a slooooow function, sometimes. But since I've only ever tried it on dialup, take this warning with a grain of salt.
public void appendFileText(StringOrBuffer str_orBfr, String s_fileName)
Read all text in from a file and append it onto a StringOrBuffer. No parsing is done, this is just a blind file read. Note: This function is useful, not efficient (?).
Finally, I have figured out how to read in exactly the contents of the file, even if it does not end with a newline :' )
s_fileName
- The full path and name of the file to be read. Must point to an existing and readable file.AssertException
- Thrown when s_fileName
is invalid or any IO error occurspublic final void crashIfBadMLCs(StringOrBuffer sob_code, String s_mlcStart, String s_mlcEnd)
Analyzes the provided code, and crashes with a specific error message if any multi-line comments are invalidly formatted.
Note: s_mlcStart may not be contained in any string, or this function will not work properly. It is suggested that, if you need to put s_mlcStart into any of your strings, then give the actual multiple-line comment start tag an extra asterisk ("/**
" instead of "/*
").
public final void stripMLCs(StringOrBuffer sob_code, String s_mlcStart, String s_mlcEnd)
String all multi-line comments out of the provided code. This function assumes that you have successfully called crashIfBadMLCs (ie, it did nothing/did not crash), otherwise this function will give you unpredictable results.
public final void stripSLCs(StringOrBuffer sob_sourceCode, String s_slcDelimiter)
Eliminate all single line comments from the source code.
This eliminates all text from (and including) the single line comment delimiter, through the last character in the line. This leaves any preceding text (including tabs and spaces) alone. Also, this cannot distinguish an actual single line comment delimiter from one existing inside a string. Therefore, ensure that none exist unless they are truly delimiting a single line comment.
sob_sourceCode
- The StringOrBuffer containing source code, in which single line comments should be deleted. May not be null.s_slcDelimiter
- The single line comment delimiter. May not be null or zero characters in length.public final void elimJSFunction(String s_function, StringOrBuffer sob_code)
Eliminate the requested function from your JavaScript code. Assumes that the final "}" is the first "}" that has the same indentation as the "function " + s_function
line. There may only be one space between "function" and s_function. Indentation may only contain tabs, no spaces.
public s_acs_acs[] getPackageDependencies(String s_baseDir, int i_subDirLevels, Outputter optr_dbg, String[] as_acceptPkgPre, boolean b_crashIfSelfDependent, FileFilter file_filter)
For all packages in the provided directory path, find out which packages are dependent on each other.
Note that the names of packages for the analyzed java files are based upon the last directory element in s_baseDir, not the actual "package" statements existing in the java code. For example, take this class: xbn.util.Utility
The first line of code in this file, Utility.java, is package xbn.util.
, meaning, of course, that its actual package is just that: xbn.util. However, if the full path and name of Utility.java were actually
C:\temp\xbn\whatever\Utility.java
and s_baseDir were provided as
C:\temp\xbn\
Then this function would consider the fully qualified class name of Utility.java to be
xbn.whatever.Utility
In other words, the "package
" line is ignored. Rather, the package for all classes is defined in this manner.
The first line of code creates a new DirFile with
new DirFile(s_baseDir, i_subDirLevels, (new FFJava()), optr_dbg)
Where FFJava is:
class FFJava implements FileFilter {
public boolean accept(File f_ile) {
if(f_ile.isDirectory() &&
!f_ile.getPath().toLowerCase().startsWith("cvs") &&
!f_ile.getPath().toLowerCase().endsWith("cvs")) {
return true;
}
if(f_ile.getPath().toLowerCase().endsWith(".java")) {
return true;
}
return false;
}
}
s_baseDir
- The directory to analyze. Must end with a File.separator, and contain at least one File.separator before the last one.as_acceptPkgPre
- The names of package prefixes to recognize. If null, then all imported packages are reported. If non-null, then this contains all the packages to be reported on (all others are ignored and not reported). If non-null, must be at least one element in length, where all elements are non-null, unique, ordered ascending, and at least one character in length.b_crashIfSelfDependent
- If true, and a package depends on itself, then throw a descriptive error. As far as this function is concerned, if a package is dependent on itself, it means that a class within that package is explicitely importing another class from the same package. That import is therefore unneccessary.file_filter
- What packages/classes should be included/excluded. If null, then every *.java
file within the search directories is analyzed.xbn.util
'.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright 1997-2003, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.
http://sourceforge.net/projects/xbnjava