|
Purple Code | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.purpletech.util.Utils
| Nested Class Summary | |
static class |
Utils.ExecInfo
Class encapsulating information from an exec call -- slightly easier than the standard API |
| Constructor Summary | |
Utils()
|
|
| Method Summary | |
static java.lang.String |
abbreviate(java.lang.String s,
int max)
Turn "Now is the time for all good men" into "Now is the time for..." |
static java.lang.String |
capitalize(java.lang.String s)
capitalize the first character of s |
static java.lang.String |
commaList(java.util.Collection c)
Deprecated. use org.apache.commons.lang.StringUtils.join() |
static java.lang.String |
commaList(java.util.Iterator i)
Deprecated. use org.apache.commons.lang.StringUtils.join() |
static java.lang.String |
commaList(java.lang.Object[] a)
Deprecated. use org.apache.commons.lang.StringUtils.join() |
static int |
count(java.lang.String s,
char ch)
Deprecated. use org.apache.commons.lang.StringUtils.countMatches instead |
static Utils.ExecInfo |
exec(java.lang.String command,
java.lang.String input,
long sleep)
Wrapper for Runtime.exec. |
static int |
getMaxLength(java.util.Iterator i)
calculate the maximum length of all strings in i. |
static java.lang.String |
getStackTrace(java.lang.Throwable t)
|
static java.lang.String |
htmlescape(java.lang.String s1)
Turns funky characters into HTML entity equivalents |
static java.lang.String |
htmlunescape(java.lang.String s1)
Given a string containing entity escapes, returns a string containing the actual Unicode characters corresponding to the escapes. |
static java.lang.String |
indent(int indent)
|
static boolean |
isWhitespace(java.lang.String s)
|
static java.lang.String |
javaEscape(java.lang.String source)
|
static void |
javaEscape(java.lang.String source,
java.io.Writer out)
Prepares a string for output inside a Java string, Example: |
static java.lang.String |
jsEscape(java.lang.String source)
Prepares a string for output inside a JavaScript string, e.g. |
static void |
jsEscape(java.lang.String source,
java.io.Writer out)
Prepares a string for output inside a JavaScript string, e.g. |
static java.lang.String |
lowerize(java.lang.String s)
lowercase the first character of s |
static java.lang.String |
ltrim(java.lang.String orig)
Trim the left spacing off of a String. |
static boolean |
ok(java.lang.String s)
|
static java.lang.String |
pad(java.lang.String s,
int length)
pad or truncate |
static java.lang.String |
pluralize(java.lang.String s)
turn String s into a plural noun (doing the right thing with "story" -> "stories" and "mess" -> "messes") |
static void |
printCommaList(java.io.PrintWriter out,
java.util.Iterator i)
Given an iterator, prints it as a comma-delimited list (actually a comma-and-space delimited list). |
static void |
printIndent(java.io.PrintWriter out,
int indent)
|
static java.lang.String |
replace(java.lang.String source,
java.lang.String target,
java.lang.String replacement)
Replace all occurences of target inside source with replacement. |
static java.lang.String |
rtrim(java.lang.String orig)
Trim the whitespace off the right side of a String. |
static void |
sleep(long msec)
|
static java.lang.String |
strdiff(java.lang.String s1,
java.lang.String s2)
Compare two strings, and return the portion where they differ. |
static int |
strdiffat(java.lang.String s1,
java.lang.String s2)
Compare two strings, and return the index at which the strings begin to diverge |
static java.lang.String |
strdiffVerbose(java.lang.String expected,
java.lang.String actual)
Compare two strings, and return a verbose description of how they differ. |
static java.lang.String |
stripWhitespace(java.lang.String s)
Deprecated. use org.apache.commons.lang.StringUtils deleteSpaces instead |
static java.lang.String |
toUnderscore(java.lang.String s)
Converts camelCaseVersusC to camel_case_versus_c |
static java.lang.String |
uncurlQuotes(java.lang.String input)
Filter out Windows and Mac curly quotes, replacing them with the non-curly versions. |
static java.lang.String |
zerofill(int x,
int desiredWidth)
fills the left side of a number with zeros e.g. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Utils()
| Method Detail |
public static java.lang.String zerofill(int x,
int desiredWidth)
public static void printIndent(java.io.PrintWriter out,
int indent)
public static java.lang.String indent(int indent)
public static java.lang.String commaList(java.lang.Object[] a)
public static java.lang.String commaList(java.util.Collection c)
public static java.lang.String commaList(java.util.Iterator i)
public static void printCommaList(java.io.PrintWriter out,
java.util.Iterator i)
out - the stream to write toi - an iterator containing printable (toString) objects, e.g. stringspublic static boolean isWhitespace(java.lang.String s)
public static Utils.ExecInfo exec(java.lang.String command,
java.lang.String input,
long sleep)
throws java.io.IOException
command - the command-line to executeinput - a string to pass to the process as standard inputsleep - msec to wait before terminating process (if <= 0, waits forever)
java.io.IOException
public static java.lang.String abbreviate(java.lang.String s,
int max)
Specifically:
If str is less than max characters long, return it. Else abbreviate it to (substring(str, 0, max-3) + "..."). If max is less than 3, throw an IllegalArgumentException. In no case will it return a string of length greater than max.
max - maximum length of result string
public static java.lang.String pad(java.lang.String s,
int length)
public static java.lang.String strdiff(java.lang.String s1,
java.lang.String s2)
E.g. strdiff("i am a machine", "i am a robot") -> "robot"
public static int strdiffat(java.lang.String s1,
java.lang.String s2)
E.g. strdiff("i am a machine", "i am a robot") -> 7
public static java.lang.String strdiffVerbose(java.lang.String expected,
java.lang.String actual)
strings differ at character 7 Expected: ...am a robot Actual: ...am a machineThis was developed in order to provide some sanity to JUnit's assertEquals routine.
public static int count(java.lang.String s,
char ch)
public static java.lang.String replace(java.lang.String source,
java.lang.String target,
java.lang.String replacement)
public static java.lang.String rtrim(java.lang.String orig)
Trim the whitespace off the right side of a String.
orig - String to rtrim.
String - orig with no right spacespublic static java.lang.String ltrim(java.lang.String orig)
Trim the left spacing off of a String.
orig - String to rtrim.
String - orig with no left spacespublic static int getMaxLength(java.util.Iterator i)
public static java.lang.String htmlescape(java.lang.String s1)
e.g. "bread" & "butter" => "bread" & "butter". Update: supports nearly all HTML entities, including funky accents. See the source code for more detail.
htmlunescape(String)public static java.lang.String htmlunescape(java.lang.String s1)
htmlescape(String)public static java.lang.String jsEscape(java.lang.String source)
input string: He didn't say, "Stop!" output string: He didn\'t say, \"Stop!\"Deals with quotes and control-chars (tab, backslash, cr, ff, etc.) Bug: does not yet properly escape Unicode / high-bit characters.
jsEscape(String, Writer)public static java.lang.String javaEscape(java.lang.String source)
javaEscape(String, Writer)
public static void jsEscape(java.lang.String source,
java.io.Writer out)
throws java.io.IOException
input string: He didn't say, "stop!" output string: He didn\'t say, \"stop!\"Deals with quotes and control-chars (tab, backslash, cr, ff, etc.)
java.io.IOExceptionjsEscape(String)
public static void javaEscape(java.lang.String source,
java.io.Writer out)
throws java.io.IOException
input string: He didn't say, "stop!" output string: He didn't say, \"stop!\"Deals with quotes and control-chars (tab, backslash, cr, ff, etc.)
java.io.IOExceptionjsEscape(String,Writer)public static java.lang.String uncurlQuotes(java.lang.String input)
public static java.lang.String capitalize(java.lang.String s)
public static java.lang.String lowerize(java.lang.String s)
public static java.lang.String pluralize(java.lang.String s)
public static boolean ok(java.lang.String s)
public static java.lang.String toUnderscore(java.lang.String s)
public static java.lang.String stripWhitespace(java.lang.String s)
public static java.lang.String getStackTrace(java.lang.Throwable t)
public static void sleep(long msec)
|
Documentation generated March 5 2003 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||