|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.sandev.basics.util.StringUtil
public class StringUtil
Utilities for String value manipulation. These aren't strictly necessary but they make coding easier.
Number conversion:
When converting from a string to a number, you really just want two methods: one to tell you if it can be converted (so you can do a nice error if it's not going to work), and another to do the conversion in an intelligent way. Writing the same code blocks repeatedly for this is annoying, so we have the methods factored here. That leaves all the ParseException, NumberFormatException, ClassCastException stuff from cluttering up the application code.
| Field Summary | |
|---|---|
protected static java.text.DateFormat |
dateFormat
Our DateFormat instance so we don't have to keep retrieving a new one for every date field translation call. |
protected static java.text.NumberFormat |
numberFormat
Our NumberFormat instance so we don't have to keep retrieving this on repeated calls. |
| Constructor Summary | |
|---|---|
StringUtil()
|
|
| Method Summary | |
|---|---|
static java.lang.String[] |
atomize(java.lang.String text)
Split up the given text into individual words. |
static java.lang.String |
capitalize(java.lang.String str)
Capitalize the given text and return the result. |
static java.lang.String |
capwords(java.lang.String str)
Capitalize all words in the given text. |
static java.lang.String |
convertSlashFormat(java.lang.String probtext,
java.text.DateFormat df)
If the date pattern we are using is not slash separated, and we got a string with slashes in it, then reformat it. |
static boolean |
convertsToDate(java.lang.String val)
Return true if the given value can be converted to a Date, false otherwise. |
static boolean |
convertsToDate(java.lang.String val,
java.lang.String format,
java.lang.String tzid)
Like the standard convertsToDate but uses the given format string for parsing. |
static boolean |
convertsToDouble(java.lang.String val)
Return true if the given value can be converted to a long, false otherwise. |
static boolean |
convertsToInt(java.lang.String val)
Return true if the given value can be converted to an int, false otherwise. |
static boolean |
convertsToLong(java.lang.String val)
Return true if the given value can be converted to a long, false otherwise. |
static java.lang.String |
dateToString(java.util.Date date)
Return the String value of the given Date. |
static java.lang.String |
dateToString(java.util.Date date,
java.lang.String format,
java.lang.String tzid)
Like the single parameter dateToString but uses the given format to convert the date to a String. |
static void |
debugDumpMonthNames(java.lang.String[] months)
Write out the given months array for debug purposes. |
protected static void |
debugout(java.lang.String text)
Debug output informational method. |
static java.lang.String |
fix24HourTimeEntry(java.lang.String probtext,
java.text.DateFormat df)
If we are on 12 hour time and the time was entered in 24 hour format, then convert it. |
static java.lang.String |
fixAMPMSpecification(java.lang.String probtext,
java.text.DateFormat df)
Assuming AM or PM needs to be specified and was not, then append the appropriate value. |
static java.lang.String |
fixCommaWithNoSpace(java.lang.String probtext,
java.text.DateFormat df)
If the date pattern we are using has a comma followed by a space, and what we are reading forgot the space, then add it back in. |
static java.lang.String |
fixNoTimeSpecified(java.lang.String probtext)
If no time was specified, then return a default time of 12:00. |
static java.lang.String |
fixSecondsIgnored(java.lang.String probtext,
java.text.DateFormat df)
If the format specifies no seconds, and seconds are given then trim them from the string. |
static java.lang.String |
fixSecondsRequired(java.lang.String probtext,
java.text.DateFormat df)
If seconds are required, but not specified, then add zero seconds to the time spec. |
static java.lang.String |
fixSpuriousLeadingZeroForHour(java.lang.String probtext,
java.text.DateFormat df)
If the format specifies the base hour without a leading zero, and we have a leading zero, then get rid of it. |
static java.text.DateFormat |
getDateFormat()
Initializing accessor for dateFormat. |
static java.util.Date |
getDateValue(java.lang.String val)
Convert the given String to a Date value. |
static java.util.Date |
getDateValue(java.lang.String val,
java.lang.String format,
java.lang.String timezoneID)
Workhorse for single parameter getDateValue that can take a separate format specification. |
static java.lang.String |
getDecimalValue(double val,
int decimals,
boolean sep)
Convert the given double value to a text representation with the given number of decimals. |
static java.lang.String |
getDecimalValue(int val,
int decimals)
Given a decimalized integer, and the decimal precision, return a string representation of the decimal value. |
static double |
getDoubleValue(java.lang.String val)
Convert the given String to a double value. |
static int |
getIntValue(java.lang.String val)
Convert the given String to an int value. |
static long |
getLongValue(java.lang.String val)
Convert the given String to a long value. |
static java.lang.String[] |
getMonthNames(java.text.SimpleDateFormat dateformat,
java.lang.String monthformat)
Return an array of the month names as specified by the given DateFormat pattern. |
static java.text.NumberFormat |
getNumberFormat()
Initializing accessor for numberFormat. |
static char |
getRandomChar(java.util.Random random)
Return the next random character from the random sequence generator. |
static java.lang.String |
getRandomText(int length)
Return a random string of the specified length. |
static java.lang.String |
guessMonth(java.lang.String probtext,
java.text.DateFormat df)
Guess the month specification from what was entered and convert it to the canonical format. |
static java.lang.String |
localeToString(java.util.Locale loc)
Transform the given Locale to a String. |
static java.lang.String |
mailify(java.lang.String source)
Attempt to convert the given source text escaping any characters that would cause problems if used literally within a mailto link. |
static java.lang.String |
quoteString(java.lang.String source)
Return the given string with double quotes around it. |
static java.lang.String |
reconstitute(java.lang.String[] atoms)
Reconstitute the given atom array back into a single string. |
static java.lang.String |
replaceAll(java.lang.String source,
java.lang.String tag,
java.lang.String repl)
Works like replaceFirst except it does all instances. |
static java.lang.String |
replaceFirst(java.lang.String source,
java.lang.String tag,
java.lang.String repl)
Replace the first instance of tag in source with repl. |
static java.util.Date |
safeGetDateValue(java.lang.String val)
Calls getDateValue but returns null rather than throwing if the value cannot be converted. |
static java.util.Date |
safeGetDateValue(java.lang.String val,
java.lang.String format,
java.lang.String tzid)
Same as the single parameter safeGetDateValue but using the specified format string. |
static double |
safeGetDoubleValue(java.lang.String val)
Calls getDoubleValue but returns 0 rather than throwing if the value can't be converted. |
static int |
safeGetIntValue(java.lang.String val)
Calls getIntValue but returns 0 rather than throwing if the value can't be converted. |
static long |
safeGetLongValue(java.lang.String val)
Calls getLongValue but returns 0 rather than throwing if the value can't be converted. |
static java.util.Date |
sandGetDateValue(java.lang.String val)
Wraps getDateValue and throws a SandException if anything goes wrong. |
static java.util.Date |
sandGetDateValue(java.lang.String val,
java.lang.String format)
Same as the single parameter sandGetDateValue but using the specified format string. |
static double |
sandGetDoubleValue(java.lang.String val)
Wraps getDoubleValue and throws a SandException if anything goes wrong. |
static int |
sandGetIntValue(java.lang.String val)
Wraps getIntValue and throws a SandException if anything goes wrong. |
static long |
sandGetLongValue(java.lang.String val)
Wraps getLongValue and throws a SandException if anything goes wrong. |
static java.util.Locale |
stringToLocale(java.lang.String locstr)
Reconstitute the Locale previously converted to a String via the localeToString method. |
static java.lang.String |
uncapitalize(java.lang.String str)
Uncapitalize the given text and return the result. |
static java.lang.String |
uncapwords(java.lang.String str)
Uncapitalize all words in the given text. |
static java.lang.String |
unquoteString(java.lang.String source)
String the containing double quotes from the given string. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static java.text.NumberFormat numberFormat
protected static java.text.DateFormat dateFormat
| Constructor Detail |
|---|
public StringUtil()
| Method Detail |
|---|
public static java.text.NumberFormat getNumberFormat()
public static java.text.DateFormat getDateFormat()
public static boolean convertsToInt(java.lang.String val)
public static int getIntValue(java.lang.String val)
throws java.text.ParseException
java.text.ParseExceptionpublic static int safeGetIntValue(java.lang.String val)
public static int sandGetIntValue(java.lang.String val)
throws SandException
SandException
public static java.lang.String getDecimalValue(int val,
int decimals)
public static boolean convertsToLong(java.lang.String val)
public static long getLongValue(java.lang.String val)
throws java.text.ParseException
java.text.ParseExceptionpublic static long safeGetLongValue(java.lang.String val)
public static long sandGetLongValue(java.lang.String val)
throws SandException
SandExceptionpublic static boolean convertsToDouble(java.lang.String val)
public static double getDoubleValue(java.lang.String val)
throws java.text.ParseException
java.text.ParseExceptionpublic static double safeGetDoubleValue(java.lang.String val)
public static double sandGetDoubleValue(java.lang.String val)
throws SandException
SandException
public static java.lang.String getDecimalValue(double val,
int decimals,
boolean sep)
public static java.lang.String dateToString(java.util.Date date)
A null Date value returns the empty string.
public static java.lang.String dateToString(java.util.Date date,
java.lang.String format,
java.lang.String tzid)
A null Date value returns the empty string.
public static boolean convertsToDate(java.lang.String val)
public static boolean convertsToDate(java.lang.String val,
java.lang.String format,
java.lang.String tzid)
public static java.util.Date getDateValue(java.lang.String val)
throws java.text.ParseException
This method is synchronized because a DateFormat is not thread safe, so we prevent multiple threads trying to use it at the same time.
java.text.ParseException
public static java.util.Date getDateValue(java.lang.String val,
java.lang.String format,
java.lang.String timezoneID)
throws java.text.ParseException
java.text.ParseExceptionpublic static java.util.Date safeGetDateValue(java.lang.String val)
public static java.util.Date safeGetDateValue(java.lang.String val,
java.lang.String format,
java.lang.String tzid)
public static java.util.Date sandGetDateValue(java.lang.String val)
throws SandException
SandException
public static java.util.Date sandGetDateValue(java.lang.String val,
java.lang.String format)
throws SandException
SandException
public static java.lang.String convertSlashFormat(java.lang.String probtext,
java.text.DateFormat df)
public static java.lang.String fixCommaWithNoSpace(java.lang.String probtext,
java.text.DateFormat df)
public static java.lang.String fixNoTimeSpecified(java.lang.String probtext)
public static java.lang.String fix24HourTimeEntry(java.lang.String probtext,
java.text.DateFormat df)
public static java.lang.String fixSecondsRequired(java.lang.String probtext,
java.text.DateFormat df)
public static java.lang.String fixSecondsIgnored(java.lang.String probtext,
java.text.DateFormat df)
public static java.lang.String fixSpuriousLeadingZeroForHour(java.lang.String probtext,
java.text.DateFormat df)
public static java.lang.String fixAMPMSpecification(java.lang.String probtext,
java.text.DateFormat df)
public static java.lang.String guessMonth(java.lang.String probtext,
java.text.DateFormat df)
public static java.lang.String[] getMonthNames(java.text.SimpleDateFormat dateformat,
java.lang.String monthformat)
public static void debugDumpMonthNames(java.lang.String[] months)
protected static void debugout(java.lang.String text)
public static java.lang.String localeToString(java.util.Locale loc)
public static java.util.Locale stringToLocale(java.lang.String locstr)
public static java.lang.String[] atomize(java.lang.String text)
public static java.lang.String reconstitute(java.lang.String[] atoms)
public static java.lang.String getRandomText(int length)
public static char getRandomChar(java.util.Random random)
public static java.lang.String replaceFirst(java.lang.String source,
java.lang.String tag,
java.lang.String repl)
public static java.lang.String replaceAll(java.lang.String source,
java.lang.String tag,
java.lang.String repl)
public static java.lang.String quoteString(java.lang.String source)
public static java.lang.String unquoteString(java.lang.String source)
public static java.lang.String mailify(java.lang.String source)
public static java.lang.String capitalize(java.lang.String str)
public static java.lang.String uncapitalize(java.lang.String str)
public static java.lang.String capwords(java.lang.String str)
public static java.lang.String uncapwords(java.lang.String str)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||