public class StringUtils extends Object
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
boolean |
allEmpty(List list)
Check to see if all the string objects passed
in are empty.
|
static String |
capitalizeFirstLetter(String data)
Capitalize the first letter but leave the rest as they are.
|
static String |
chop(String s,
int i)
Chop i characters off the end of a string.
|
static String |
chop(String s,
int i,
String eol)
Chop i characters off the end of a string.
|
static String |
collapseNewlines(String argStr)
Remove/collapse multiple newline characters.
|
static String |
collapseSpaces(String argStr)
Remove/collapse multiple spaces.
|
String |
concat(List list)
Concatenates a list of objects as a String.
|
static String |
fileContentsToString(String file)
Read the contents of a file and place them in
a string object.
|
static String |
firstLetterCaps(String data)
Makes the first letter caps and the rest lowercase.
|
static String |
formatFileString(Directive directive)
Creates a string that formats the template filename with line number
and column of the given Directive.
|
static String |
formatFileString(Info info)
Simply creates a string that formats the template filename with line number
and column.
|
static String |
formatFileString(Node node)
Creates a string that formats the template filename with line number
and column of the given Node.
|
static String |
formatFileString(String template,
int linenum,
int colnum)
Simply creates a string that formats the template filename with line number
and column.
|
static String |
getPackageAsPath(String pckge)
Return a package name as a relative path name
|
static String |
normalizePath(String path)
Return a context-relative path, beginning with a "/", that represents
the canonical version of the specified path after ".." and "." elements
are resolved out.
|
static String |
nullTrim(String s)
Trim the string, but pass a null through.
|
static String |
removeAndHump(String data)
'Camels Hump' replacement of underscores.
|
static String |
removeAndHump(String data,
String replaceThis)
'Camels Hump' replacement.
|
String |
select(boolean state,
String trueString,
String falseString)
If state is true then return the trueString, else
return the falseString.
|
static String[] |
split(String line,
String delim)
Create a string array from a string separated by delim
|
static String |
stackTrace(Throwable e)
Returns the output of printStackTrace as a String.
|
static StringBuffer |
stringSubstitution(String argStr,
Hashtable vars) |
static StringBuffer |
stringSubstitution(String argStr,
Map vars)
Perform a series of substitutions.
|
static String |
sub(String line,
String oldString,
String newString)
Replaces all instances of oldString with newString in line.
|
static List |
trimStrings(List list)
Trim all strings in a List.
|
public String concat(List list)
list
- The list of objects to concatenate.public static String getPackageAsPath(String pckge)
pckge
- package name to convert to a directory.public static String removeAndHump(String data)
'Camels Hump' replacement of underscores.
Remove underscores from a string but leave the capitalization of the other letters unchanged.
For example foo_barBar
becomes FooBarBar
.
data
- string to humppublic static String removeAndHump(String data, String replaceThis)
'Camels Hump' replacement.
Remove one string from another string but leave the capitalization of the other letters unchanged.
For example, removing "_" from foo_barBar
becomes FooBarBar
.
data
- string to humpreplaceThis
- string to be replacedpublic static String firstLetterCaps(String data)
Makes the first letter caps and the rest lowercase.
For example fooBar
becomes Foobar
.
data
- capitalize thispublic static String capitalizeFirstLetter(String data)
Capitalize the first letter but leave the rest as they are.
For example fooBar
becomes FooBar
.
data
- capitalize thispublic static String[] split(String line, String delim)
line
- the line to splitdelim
- the delimter to split bypublic static String chop(String s, int i)
s
- String to chop.i
- Number of characters to chop.public static String chop(String s, int i, String eol)
s
- String to chop.i
- Number of characters to chop.eol
- A String representing the EOL (end of line).public static StringBuffer stringSubstitution(String argStr, Hashtable vars)
argStr
- vars
- public static StringBuffer stringSubstitution(String argStr, Map vars)
argStr
- target stringvars
- name/value pairs used for substitutionpublic static String fileContentsToString(String file)
file
- path to file.public static String collapseNewlines(String argStr)
argStr
- string to collapse newlines in.public static String collapseSpaces(String argStr)
argStr
- string to remove multiple spaces from.public static final String sub(String line, String oldString, String newString)
line
- original string.oldString
- string in line to replace.newString
- replace oldString with this.public static final String stackTrace(Throwable e)
e
- A Throwable.public static final String normalizePath(String path)
null
instead.path
- Path to be normalizedpublic String select(boolean state, String trueString, String falseString)
state
- trueString
- falseString
- public boolean allEmpty(List list)
list
- A list of String
objects.public static List trimStrings(List list)
list
- public static String nullTrim(String s)
s
- public static final String formatFileString(Directive directive)
public static final String formatFileString(Node node)
public static final String formatFileString(Info info)
public static final String formatFileString(String template, int linenum, int colnum)
template
- File name of template, can be nulllinenum
- Line number within the filecolnum
- Column number withing the file at linenumCopyright © 2000–2016 The Apache Software Foundation. All rights reserved.