|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.common.util.Strings
This class provides static utility methods for doing complex string processing.
Constructor Summary | |
Strings()
|
Method Summary | |
static java.lang.String |
capitalize(java.lang.String str)
Ensures the given string starts with a capital letter. |
static java.lang.String |
captureStackTrace(java.lang.Throwable t)
Takes a Throwable and prints its stack trace into a string. |
static byte[] |
compress(byte[] b,
boolean useZLIB)
Compresses a byte array with gzip. |
static java.lang.String |
concat(java.lang.String[] strings)
Concatenates the strings of a String array, using spaces. |
static java.lang.String |
concat(java.lang.String[] strings,
int index)
Concatenates the strings of a String array, starting at the passed array index. |
static java.lang.String |
concat(java.lang.String[] strings,
int start,
int end)
Concatenates the strings of a String array, starting at the passed array index, and ending just before the end-index. |
static java.lang.String |
concat(java.util.StringTokenizer st)
Concatenates the remaining tokens from the passed StringTokenizer using spaces and returns the resulting string. |
static boolean |
contains(java.lang.String[] array,
java.lang.String s)
Returns true if the passed String array contains the passed String. |
static java.lang.String |
create(char c,
int repeats)
Creates a string by concatenating N of the same character. |
static java.lang.String |
create(java.lang.String s,
int repeats)
Creates a string by concatenating N of the same string. |
static java.lang.String |
formatDouble(double d)
Returns a double formatted to 2 decimal places. |
static java.lang.String |
formatInt(long number)
Formats an integer with commas. |
static java.lang.String |
formatStringArray(java.lang.String[] strings)
Returns a printable version of a string array. |
static boolean |
isAllCaps(java.lang.String s)
Returns true if the passed string has no lowercase letters. |
static boolean |
isCapitalized(java.lang.String s)
Returns true if the first letter is a capital. |
static boolean |
isVowel(char c)
Returns true if the specified character is a vowel. |
static void |
main(java.lang.String[] args)
Tests some functions. |
static java.lang.String |
makeAllCaps(java.lang.String s)
Turns all lowercase letters into uppercase letters. |
static int |
occurrencesOf(java.lang.String s,
char c)
Counts occurrences of the specified character in a string. |
static java.lang.String |
pad(java.lang.String text,
int size)
Pads the passed string to N characters, appending spaces. |
static java.lang.String |
percent(double num1,
double num2)
Returns a percentage formatted to two decimal places. |
static void |
printArray(java.lang.Object[] objects)
Prints an arbitrary array of objects, invoking toString on them. |
static java.lang.String |
printField(java.lang.String s,
int len)
Creates a string of a fixed width containing the passed string. |
static void |
printStringArray(java.lang.String[] strings)
Prints a string array. |
static java.lang.String |
readFile(java.lang.String path)
Reads a text file into a single string. |
static java.lang.String |
replaceString(java.lang.String s,
java.lang.String orig,
java.lang.String newstr)
Replaces every occurrence of XX with YY in the passed string. |
static java.lang.String |
replaceString(java.lang.String s,
java.lang.String oldstr,
java.lang.String newstr,
boolean ignoreCase)
Replaces every occurrence of XX with YY in the passed string. |
static java.lang.String |
rpad(java.lang.String text,
int size)
Pads the passed string to N characters, prepending spaces, so that the string is right-justified. |
static java.lang.String[] |
splitSubject(java.lang.String subject)
Splits a dotted subject into an array of Strings, one per parent subject. |
static java.lang.String |
substitute(java.lang.String text,
java.lang.String oldstr,
java.lang.String newstr)
Performs a substitution of one substring for another in the passed String. |
static java.lang.String |
substitute(java.lang.String s,
java.lang.String oldstr,
java.lang.String newstr,
boolean ignoreCase)
Performs a substitution of one substring for another in the passed String. |
static java.lang.String[] |
tokenize(java.lang.String input)
Splits the string with a StringTokenizer and puts the results into a string array. |
static java.lang.String |
uncapitalize(java.lang.String str)
Ensures the given string starts with a lowercase letter. |
static byte[] |
uncompress(byte[] b)
Uncompresses an array of bytes compressed with gzip. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Strings()
Method Detail |
public static int occurrencesOf(java.lang.String s, char c)
s
- the string to examinec
- the character to look for
public static java.lang.String concat(java.util.StringTokenizer st)
st
- a StringTokenizer that may already have traversed
some of its tokens. Only includes the remaining tokens.public static java.lang.String concat(java.lang.String[] strings)
public static java.lang.String concat(java.lang.String[] strings, int index)
strings
- the String array to concatenateindex
- the starting index
public static java.lang.String concat(java.lang.String[] strings, int start, int end)
strings
- a String array to concatenatestart
- the starting indexend
- the ending index (NOT inclusive).
public static java.lang.String[] tokenize(java.lang.String input)
input
- the space-delimited input string
public static java.lang.String substitute(java.lang.String text, java.lang.String oldstr, java.lang.String newstr)
text
- the main string on which to perform the replacementoldstr
- the substring to replacenewstr
- the substring to replace public static java.lang.String substitute(java.lang.String s, java.lang.String oldstr, java.lang.String newstr, boolean ignoreCase)
s
- the main string on which to perform the replacementoldstr
- the substring to replacenewstr
- the substring to replace ignoreCase
- true if the replacement string should have
the same case (lowercase, capitalized, or all-caps) as the
string to replace.
public static java.lang.String replaceString(java.lang.String s, java.lang.String orig, java.lang.String newstr)
s
- the string on which to perform the replacementorig
- the substring to replace (XX)newstr
- the replacement substring (YY)
public static java.lang.String replaceString(java.lang.String s, java.lang.String oldstr, java.lang.String newstr, boolean ignoreCase)
s
- the string on which to perform the replacementoldstr
- the substring to replace (XX)newstr
- the replacement substring (YY)ignoreCase
- if true, then if the string to replace in
the original is capitalized, the replacement string will be
as well. And if the original substring is all-caps, the
replacement will be made all-caps.
public static java.lang.String create(char c, int repeats)
public static java.lang.String create(java.lang.String s, int repeats)
s
- the string to repeatrepeats
- the number of times to concat spublic static java.lang.String pad(java.lang.String text, int size)
text
- the string to padsize
- the length to return.
public static java.lang.String rpad(java.lang.String text, int size)
text
- the string to padsize
- the length to return.
public static java.lang.String capitalize(java.lang.String str)
public static java.lang.String uncapitalize(java.lang.String str)
public static boolean isAllCaps(java.lang.String s)
public static boolean isCapitalized(java.lang.String s)
public static java.lang.String makeAllCaps(java.lang.String s)
public static boolean isVowel(char c)
public static final boolean contains(java.lang.String[] array, java.lang.String s)
array
- a string arrays
- a string
public static java.lang.String captureStackTrace(java.lang.Throwable t)
public static java.lang.String printField(java.lang.String s, int len)
s
- the string to formatlen
- the field length
public static java.lang.String readFile(java.lang.String path)
path
- the absolute path to the file
public static byte[] compress(byte[] b, boolean useZLIB)
b
- the array of bytes to compressuseZLIB
- true to use ZLIB, false to use GZIP.
public static byte[] uncompress(byte[] b)
b
- a byte[] that was compressed with a DeflatorOutputStream
public static java.lang.String formatStringArray(java.lang.String[] strings)
public static void printStringArray(java.lang.String[] strings)
public static void printArray(java.lang.Object[] objects)
public static java.lang.String percent(double num1, double num2)
num1
- the numeratornum2
- the denominator
public static java.lang.String formatDouble(double d)
d
- a number like "37.02459234"
public static java.lang.String formatInt(long number)
public static java.lang.String[] splitSubject(java.lang.String subject)
subject
- a subject like "wyvern.player.init"
java.lang.NullPointerException
- is the subject is nullpublic static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |