public class Utils
extends java.lang.Object
Constructor and Description |
---|
Utils() |
Modifier and Type | Method and Description |
---|---|
static boolean |
contains(java.lang.Object target,
java.lang.Object subject)
Returns true if the object in the first parameter contains the Object in the second parameter according
to the Objects equals method.
|
static java.lang.String |
convertDateToString(java.util.Date date,
java.lang.String dateFormat)
Converts a Java Date that into a formatted String.
|
static java.util.Date |
convertLongToDate(long milliseconds)
Converts a long representation of time to a Date.
|
static java.lang.String |
convertMillisecondsToTime(long milliseconds)
Converts a long that represents time in milliseconds to a String that displays the time in minutes and
seconds.
|
static java.util.Date |
convertStringToDate(java.lang.String dateString,
java.lang.String dateFormat)
Converts a String that contains a recognizable date/time to a Java Date object.
|
static java.lang.String |
encodeToSearchTerm(java.lang.String string)
Encodes a String to a single term for searching over fields that have been indexed encoded.
|
static java.lang.String |
encodeToSearchTerms(java.lang.String string)
Encodes a String to a String for searching over fields that have been indexed encoded.
|
static java.lang.String |
getDayOfWeekString(int dayOfWeek)
Gets a String representation of the Calendar.DAY_OF_WEEK field.
|
static java.lang.String |
getLexicalDateString(java.lang.String dateString)
Converts a date String of the form YYYY-mm-dd, YYYY-mm, YYYY or yyyy-MM-ddTHH:mm:ssZ to a searchable
Lucene (v2.x) lexical date String of the form 'yyyyMMddHHmmss', or null if unable to parse the date
String.
|
static java.util.Map |
getPropertiesMap(java.lang.String propertiesString)
Gets the Map from a String in the Java properties format of the form property=value one per line.
|
static java.util.ResourceBundle |
getPropertiesResourceBundle(java.lang.String propsFileName)
Gets a ResourceBundle from a properties file that is in a Jar file or class path within this
application's runtime environment.
|
static java.lang.String |
getRandomAlphaString(int length)
Generates a random alpha string of the given length.
|
static java.lang.String |
getRandomCharsString(int length)
Generates a random string containing extended chars of the given length
|
static int |
getRandomIntBetween(int low,
int high)
Generates a random integer greater-than or equal to low and less-than high.
|
static long |
getUniqueID()
Gets a global system unique ID.
|
static java.util.Date |
luceneStringToDate(java.lang.String dateString)
Converts a Lucene String-encoded date to a Date Object.
|
static java.util.Map |
map(java.util.Map myMap,
java.lang.String key,
java.lang.String value)
Puts items in a Map, creating a new TreeMap if null is passed in for the myMap argument, otherwise
updating the Map with the key/value pair.
|
static java.util.Map |
mapSortByValue(java.util.Map myMap,
java.lang.String key,
java.lang.String value,
java.lang.String ascending)
Puts items in a Map, creating a new Map if null is passed in for the myMap argument, otherwise updating
the Map with the key/value pair.
|
static boolean |
matches(java.lang.String source,
java.lang.String regEx)
Tells whether or not the source string matches the given regular expression.
|
static java.lang.String |
ObjectInspector(java.lang.Object o)
Inspects an objects type and methods to standard out.
|
static void |
print_char_values()
Prints the char values of all chars in range 0 to 256.
|
static void |
printElapsedTime(java.lang.String msg,
java.util.Date start,
java.util.Date end)
Print the elapsed time that occured beween two points of time as recorded in java Date objects.
|
static void |
printToSystemErr(java.lang.String s)
Sends the string to System-err-println.
|
static void |
printToSystemOut(java.lang.String s)
* Sends the string to System-out-println.
|
static java.lang.String |
RedirectEncoder(java.lang.String text)
Encodes a string used in the URL sent to the redirect server and ensures it does not contain problematic
characters for the Apache 1 mod_redirect rules (the character sequence %2F is replaced with /).
|
static java.lang.String |
replaceAll(java.lang.String source,
java.lang.String regEx,
java.lang.String replacement)
Replaces each substring of this string that matches the given regular expression with the given
replacement.
|
static java.lang.String |
replaceFirst(java.lang.String source,
java.lang.String regEx,
java.lang.String replacement)
Replaces the first substring of this string that matches the given regular expression with the given
replacement.
|
static int |
runCommand(java.lang.String command,
java.lang.StringBuffer standardOutput,
java.lang.StringBuffer errorOutput)
Runs the given command-line command.
|
static java.lang.String[] |
split(java.lang.String source,
java.lang.String regEx)
Splits this string around matches of the given regular expression.
|
static java.lang.String |
URLEncoder(java.lang.String text)
Encodes a String for use in a URL using UTF-8 character encoding.
|
public static final java.util.Date convertStringToDate(java.lang.String dateString, java.lang.String dateFormat) throws java.text.ParseException
SimpleDateFormat
for syntax information for the format String. For example a valid date String
might look like '2003-04-27MST' with a date format specifier of 'yyyy-MM-ddz' where yyyy indicates the
year, MM the month, dd the day and z the general time zone (GMT, MST, PST, etc).dateString
- A String that contains a recognizable date/time in it, for example
'2003-04-27MST'.dateFormat
- The format of the date String as specified in SimpleDateFormat
, for example 'yyyy-MM-ddz'.java.text.ParseException
- If unable to interpret the date String using the given format specifier.public static final java.lang.String convertDateToString(java.util.Date date, java.lang.String dateFormat) throws java.text.ParseException
SimpleDateFormat
for syntax
information for the format String. For example a valid date format specifier might be '"MMM' 'dd', 'yyyy'
'z"' where yyyy indicates the year, MMM the month, dd the day and z the time zone (GMT, MST, PST, etc).date
- A Java Date object.dateFormat
- The format of the date String to be output as specified in SimpleDateFormat
, for example 'yyyy-MM-ddz'.java.text.ParseException
- If unable to interpret the date Date using the given format specifier.public static final java.util.Date convertLongToDate(long milliseconds)
milliseconds
- Time in millisecondspublic static void printElapsedTime(java.lang.String msg, java.util.Date start, java.util.Date end)
start
- The start Date.end
- The end Date.msg
- A message inserted in front of the elapsed time string.public static java.lang.String convertMillisecondsToTime(long milliseconds)
milliseconds
- Time in millisoconds.public static java.lang.String getRandomAlphaString(int length)
length
- The length of the String to generatepublic static int getRandomIntBetween(int low, int high)
low
- Smallest possible valuehigh
- Highest possible valuepublic static java.lang.String getRandomCharsString(int length)
length
- The length of the Stringpublic static final boolean contains(java.lang.Object target, java.lang.Object subject)
Implements a more versitile version of the regular JSTL contains function.
target
- The target Objectsubject
- The subject Object for comparisonpublic static java.util.Map map(java.util.Map myMap, java.lang.String key, java.lang.String value)
myMap
- A Map or nullkey
- A key for insertion in the Mapvalue
- A value for insertion in the Map, or null to insert empty Stringpublic static java.util.Map mapSortByValue(java.util.Map myMap, java.lang.String key, java.lang.String value, java.lang.String ascending)
myMap
- A Map or nullkey
- A key for insertion in the Mapvalue
- A value for insertion in the Map, or null to insert empty Stringascending
- 'ascending' or 'descending' (defaults to ascending if other value is passed)public static java.util.Map getPropertiesMap(java.lang.String propertiesString)
propertiesString
- A Java Properties Stringpublic static int runCommand(java.lang.String command, java.lang.StringBuffer standardOutput, java.lang.StringBuffer errorOutput)
command
- The full command string including argumentserrorOutput
- A StringBuffer that will be pupulated with the normal output after execution, if
any, or null not to use itstandardOutput
- A StringBuffer that will be pupulated with the error output after execution, if
any, or null not to use itpublic static void print_char_values()
public static final java.lang.String URLEncoder(java.lang.String text) throws java.io.UnsupportedEncodingException
text
- Unencoded textjava.io.UnsupportedEncodingException
- If unable to encode using UTF-8.public static final java.lang.String RedirectEncoder(java.lang.String text) throws java.io.UnsupportedEncodingException
text
- Unencoded textjava.io.UnsupportedEncodingException
- If unable to encode using UTF-8.public static final java.lang.String ObjectInspector(java.lang.Object o)
o
- The Object to inspectpublic static final boolean matches(java.lang.String source, java.lang.String regEx)
source
- The source StringregEx
- A regular expressionString.matches(String regEx)
public static final java.lang.String replaceAll(java.lang.String source, java.lang.String regEx, java.lang.String replacement)
source
- The source StringregEx
- A regular expressionreplacement
- The replacement StringString.replaceAll(String regex, String replacement)
public static final java.lang.String replaceFirst(java.lang.String source, java.lang.String regEx, java.lang.String replacement)
source
- The source StringregEx
- A regular expressionreplacement
- The replacement StringString.replaceFirst(String regex, String replacement)
public static final java.util.Date luceneStringToDate(java.lang.String dateString)
dateString
- A Lucene String-encoded datepublic static final java.lang.String getLexicalDateString(java.lang.String dateString)
dateString
- A date Stringpublic static final java.util.ResourceBundle getPropertiesResourceBundle(java.lang.String propsFileName)
propsFileName
- The name of the properties filepublic static java.lang.String getDayOfWeekString(int dayOfWeek) throws java.lang.ArrayIndexOutOfBoundsException
dayOfWeek
- A Calenday.DAY_OF_WEEK field valuejava.lang.ArrayIndexOutOfBoundsException
- If the specified field is out of range (field < 0 || field >=
7)public static final java.lang.String[] split(java.lang.String source, java.lang.String regEx)
source
- The source StringregEx
- A regular expressionString.split(String regex)
public static final java.lang.String encodeToSearchTerm(java.lang.String string)
string
- A String to encodeSimpleLuceneIndex.encodeToTerm(String, boolean, boolean)
public static final java.lang.String encodeToSearchTerms(java.lang.String string)
string
- The String to encodeSimpleLuceneIndex.encodeToTerm(String, boolean, boolean)
public static final void printToSystemErr(java.lang.String s)
s
- String to ouptut.public static final void printToSystemOut(java.lang.String s)
s
- String to ouptut.public static long getUniqueID()