|
DLESE Tools v1.6.0 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.dlese.dpc.util.Utils
public class Utils
This class holds a number of handy static methods for generating unique ids, random numbers within a given range, parsing dates, executing command-line processes, and others.
| Constructor Summary | |
|---|---|
Utils()
|
|
| Method Summary | |
|---|---|
static boolean |
contains(Object target,
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 String |
convertDateToString(Date date,
String dateFormat)
Converts a Java Date that into a formatted String. |
static Date |
convertLongToDate(long milliseconds)
Converts a long representation of time to a Date. |
static String |
convertMillisecondsToTime(long milliseconds)
Converts a long that represents time in milliseconds to a String that displays the time in minutes and seconds. |
static Date |
convertStringToDate(String dateString,
String dateFormat)
Converts a String that contains a recognizable date/time to a Java Date object. |
static String |
encodeToSearchTerm(String string)
Encodes a String to a single term for searching over fields that have been indexed encoded. |
static String |
encodeToSearchTerms(String string)
Encodes a String to a String for searching over fields that have been indexed encoded. |
static String |
getDayOfWeekString(int dayOfWeek)
Gets a String representation of the Calendar.DAY_OF_WEEK field. |
static String |
getLexicalDateString(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 Map |
getPropertiesMap(String propertiesString)
Gets the Map from a String in the Java properties format of the form property=value one per line. |
static ResourceBundle |
getPropertiesResourceBundle(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 String |
getRandomAlphaString(int length)
Generates a random alpha string of the given length. |
static 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 Date |
luceneStringToDate(String dateString)
Converts a Lucene String-encoded date to a Date Object. |
static Map |
map(Map myMap,
String key,
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 Map |
mapSortByValue(Map myMap,
String key,
String value,
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(String source,
String regEx)
Tells whether or not the source string matches the given regular expression. |
static String |
ObjectInspector(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(String msg,
Date start,
Date end)
Print the elapsed time that occured beween two points of time as recorded in java Date objects. |
static void |
printToSystemErr(String s)
Sends the string to System-err-println. |
static void |
printToSystemOut(String s)
* Sends the string to System-out-println. |
static String |
RedirectEncoder(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 String |
replaceAll(String source,
String regEx,
String replacement)
Replaces each substring of this string that matches the given regular expression with the given replacement. |
static String |
replaceFirst(String source,
String regEx,
String replacement)
Replaces the first substring of this string that matches the given regular expression with the given replacement. |
static int |
runCommand(String command,
StringBuffer standardOutput,
StringBuffer errorOutput)
Runs the given command-line command. |
static String[] |
split(String source,
String regEx)
Splits this string around matches of the given regular expression. |
static String |
URLEncoder(String text)
Encodes a String for use in a URL using UTF-8 character encoding. |
| 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 final Date convertStringToDate(String dateString,
String dateFormat)
throws 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'.
ParseException - If unable to interpret the date String using the given format specifier.
public static final String convertDateToString(Date date,
String dateFormat)
throws 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'.
ParseException - If unable to interpret the date Date using the given format specifier.public static final Date convertLongToDate(long milliseconds)
milliseconds - Time in milliseconds
public static void printElapsedTime(String msg,
Date start,
Date end)
start - The start Date.end - The end Date.msg - A message inserted in front of the elapsed time string.public static String convertMillisecondsToTime(long milliseconds)
milliseconds - Time in millisoconds.
public static String getRandomAlphaString(int length)
length - The length of the String to generate
public static int getRandomIntBetween(int low,
int high)
low - Smallest possible valuehigh - Highest possible value
public static String getRandomCharsString(int length)
length - The length of the String
public static final boolean contains(Object target,
Object subject)
Implements a more versitile version of the regular JSTL contains function.
target - The target Objectsubject - The subject Object for comparison
public static Map map(Map myMap,
String key,
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 String
public static Map mapSortByValue(Map myMap,
String key,
String value,
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 Map getPropertiesMap(String propertiesString)
propertiesString - A Java Properties String
public static int runCommand(String command,
StringBuffer standardOutput,
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 it
public static void print_char_values()
public static final String URLEncoder(String text)
throws UnsupportedEncodingException
text - Unencoded text
UnsupportedEncodingException - If unable to encode using UTF-8.
public static final String RedirectEncoder(String text)
throws UnsupportedEncodingException
text - Unencoded text
UnsupportedEncodingException - If unable to encode using UTF-8.public static final String ObjectInspector(Object o)
o - The Object to inspect
public static final boolean matches(String source,
String regEx)
source - The source StringregEx - A regular expression
String.matches(String regEx)
public static final String replaceAll(String source,
String regEx,
String replacement)
source - The source StringregEx - A regular expressionreplacement - The replacement String
String.replaceAll(String regex, String replacement)
public static final String replaceFirst(String source,
String regEx,
String replacement)
source - The source StringregEx - A regular expressionreplacement - The replacement String
String.replaceFirst(String regex, String replacement)public static final Date luceneStringToDate(String dateString)
dateString - A Lucene String-encoded date
public static final String getLexicalDateString(String dateString)
dateString - A date String
public static final ResourceBundle getPropertiesResourceBundle(String propsFileName)
propsFileName - The name of the properties file
public static String getDayOfWeekString(int dayOfWeek)
throws ArrayIndexOutOfBoundsException
dayOfWeek - A Calenday.DAY_OF_WEEK field value
ArrayIndexOutOfBoundsException - If the specified field is out of range (field < 0 || field >=
7)
public static final String[] split(String source,
String regEx)
source - The source StringregEx - A regular expression
String.split(String regex)public static final String encodeToSearchTerm(String string)
string - A String to encode
SimpleLuceneIndex.encodeToTerm(String, boolean, boolean)public static final String encodeToSearchTerms(String string)
string - The String to encode
SimpleLuceneIndex.encodeToTerm(String, boolean, boolean)public static final void printToSystemErr(String s)
s - String to ouptut.public static final void printToSystemOut(String s)
s - String to ouptut.public static long getUniqueID()
|
DLESE Tools v1.6.0 |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||