public class Util
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Util.IConverter<T1,T2> |
static interface |
Util.IMatcher<T> |
static interface |
Util.ListElementWrapper<T>
A ListElementWrapper is responsible for wrapping (or transforming) each
element of a List when the element is retrieved from the list.
|
static interface |
Util.ListFilter<T>
Interface that is used with filter(List
|
static class |
Util.ParseException
A runtime exception that is thrown when decoding fails.
|
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
APPLICATION_HOME
The system property that indicates our "home" directory.
|
static long |
MILLI_IN_DAY |
static long |
MILLI_IN_HOUR |
static long |
MILLI_IN_MINUTE |
static long |
MILLI_IN_MONTH |
static long |
MILLI_IN_SECOND |
static long |
MILLI_IN_WEEK |
static long |
MILLI_IN_YEAR |
static long |
MILLIS_PER_DAY |
| Constructor and Description |
|---|
Util() |
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.List<T> |
arrayToList(T[] array)
Given an array, returns a list.
|
static java.util.List |
asList(java.lang.Object o)
Return a List with the given object.
|
static boolean |
atob(java.lang.String a) |
static float |
atof(java.lang.String a) |
static int |
atoi(java.lang.String a)
Convert a String value into a primitive integer value.
|
static int |
atoi(java.lang.String a,
int def)
Convert a String value into a primitive integer value.
|
static long |
atol(java.lang.String a) |
static java.util.Date |
baselineDate(java.util.Date src) |
static java.util.Date |
baselineDate(java.util.Date src,
java.util.TimeZone timeZone)
Get the baseline date for the source date.
|
static java.lang.String |
bytesToString(byte[] bytes) |
static java.lang.String |
capitalize(java.lang.String str)
Capitalizes the first letter in the given String
Example: hElLo becomes HElLo
|
static java.lang.String |
capitalizeAndNormalize(java.lang.String str)
Capitalizes the first letter in the given String and lowercases
the rest of the String
Example: hElLo becomes Hello
|
static <T> T |
caseInsensitiveKeyValue(java.util.Map<java.lang.String,T> map,
java.lang.String key)
Will search for the key in a case insensitive fashion.
|
static java.lang.String |
compressWhiteSpace(java.lang.String str)
This method strips leading and trailing whitespace and guarantees that there is
at most one space between characters in the output.
|
static java.lang.String |
computeDifference(java.util.Date start,
java.util.Date end) |
static long |
computeDifferenceMilli(java.util.Date start,
java.util.Date end) |
static boolean |
containsAny(java.util.Collection c1,
java.util.Collection c2)
Return whether c1 contains any elements found in c2.
|
static <T extends java.lang.Comparable<? super T>> |
containsComparable(java.util.List<T> list,
T toFind,
boolean sorted)
Return whether the given list of comparable items contains the give item
according to the Comparable interface.
|
static <T1,T2> java.util.List<T2> |
convert(java.util.List<T1> list1,
Util.IConverter<T1,T2> converter)
Converts a list of one type into another, IConverter defines the function
that is used for the conversion
|
static void |
copyFile(java.lang.String src,
java.lang.String dest)
Copies one file to another.
|
static int |
countChars(java.lang.String sourceString,
char lookFor)
Look through a source string looking for the number
of occurrences of a given character.
|
static java.lang.Object |
createObjectByClassName(java.lang.String name)
Create a new instance of an object by classname.
|
static java.lang.String[] |
csvToArray(java.lang.String src) |
static java.util.List<java.lang.String> |
csvToList(java.lang.String src)
Convert a comma delimited string into a List of strings.
|
static java.util.List<java.lang.String> |
csvToList(java.lang.String src,
boolean filterEmpty) |
static java.util.Set<java.lang.String> |
csvToSet(java.lang.String src,
boolean filterEmpty) |
static java.util.Date |
dateBetween(java.util.Date startDate,
java.util.Date endDate) |
static java.lang.String |
dateToString(java.util.Date src)
Format a Date value as a String, using the usual "American"
format with the current time zone.
|
static java.lang.String |
dateToString(java.util.Date src,
java.lang.Integer dateFormat,
java.lang.Integer timeFormat) |
static java.lang.String |
dateToString(java.util.Date src,
java.lang.Integer dateFormat,
java.lang.Integer timeFormat,
java.util.TimeZone timeZone,
java.util.Locale locale) |
static java.lang.String |
dateToString(java.util.Date src,
java.lang.String format) |
static java.lang.String |
dateToString(java.util.Date src,
java.lang.String format,
java.util.TimeZone tz) |
static java.lang.String |
decodeJavaIdentifier(java.lang.String s)
Decode the given encoded java identifier to remove any encoded invalid
characters and replace them with their original values.
|
static java.lang.String |
deleteWhitespace(java.lang.String src)
Deletes any whitespace from the string
|
static java.util.List<java.lang.String> |
delimToList(java.lang.String delim,
java.lang.String src,
boolean filterEmpty) |
static long |
dottedQuadToLong(java.lang.String ipaddr) |
static void |
dumpProperties()
Prints the current system properties to the system output device.
|
static void |
dumpProperties(java.io.PrintWriter out)
Prints the current system properties to a writer object.
|
static java.lang.String |
encodeJavaIdentifier(java.lang.String s)
Encode the given string into a valid java identifier (for example - does not start
with a number, does not include spaces, commas, etc...) by replacing any
invalid characters with the ASCII code of the character surrounded by
double underscores.
|
static java.lang.String |
escapeHTMLNewlines(java.lang.String src)
Escape newlines from the string into the HTML escaped newline and
carriage return.
|
static java.lang.String |
escapeNewlines(java.lang.String src)
Process a string to escape newline characters.
|
static java.lang.String |
escapeNewlines(java.lang.String src,
java.lang.String nRepl,
java.lang.String rRepl)
Process a string to escape newline characters.
|
static java.lang.String |
expandVariables(java.lang.String src,
java.util.Map<java.lang.String,java.lang.Object> variables)
Process a string which may contain references to variables
and substitute the values of those variables.
|
static <T> java.util.List<T> |
filter(java.util.List<T> list,
Util.ListFilter<T> filter)
Return a filtered copy of the given list with any elements that match
the given ListFilter not included.
|
static <T> java.util.List<T> |
filterNulls(java.util.List<T> src)
Remove nulls from a list.
|
static <T> T |
find(java.util.List<T> list,
T t,
java.util.Comparator<T> comparator)
Find the requested object in the given list using the given comparator.
|
static <T> T |
find(java.util.List<T> values,
Util.IMatcher<T> matcher)
Looks through the list and returns an item
which matches the IMatcher interface.
|
static <T extends java.lang.Comparable<? super T>> |
findComparable(java.util.List<T> list,
T toFind,
boolean sorted)
Return a matching object from the given list.
|
static java.lang.String |
findFile(java.lang.String name) |
static java.lang.String |
findFile(java.lang.String property,
java.lang.String name) |
static java.lang.String |
findFile(java.lang.String property,
java.lang.String name,
boolean searchClasspath)
Attempt to derive the absolute path of a file.
|
static java.lang.String |
findOutputFile(java.lang.String name)
Build an absolute path name for a file.
|
static void |
flushIterator(java.util.Iterator i)
Exhaust the remainder of the iterator so that Hibernate will properly
close the cursor associated with it.
|
static java.lang.String |
ftoa(float i) |
static java.lang.Object |
get(java.util.Map map,
java.lang.String name) |
static java.lang.String |
getApplicationHome()
Returns the filesystem path for the application home.
|
static java.util.Date |
getBeginningOfDay(java.util.Date day) |
static boolean |
getBoolean(java.util.Map map,
java.lang.String name) |
static java.lang.String |
getClasspathDirectory(int idx)
Return the nth item on the CLASSPATH.
|
static java.util.Date |
getDate(java.util.Map map,
java.lang.String name) |
static java.util.Date |
getDate(java.lang.Object o)
Try to derive a Date from a random object.
|
static int |
getDaysDifference(java.util.Date d1,
java.util.Date d2)
Return the number of days difference between the two given dates.
|
static java.util.Date |
getEndOfDay(java.util.Date day) |
static java.lang.String |
getFullname(java.lang.String first,
java.lang.String last)
Return a fullname constructed from the given first and last names.
|
static java.lang.String |
getHostName() |
static java.util.ResourceBundle |
getIIQHelpMessages(java.util.Locale locale) |
static java.util.ResourceBundle |
getIIQMessages(java.util.Locale locale) |
static int |
getInt(java.util.Map map,
java.lang.String name) |
static java.lang.String |
getJsonSafeKey(java.lang.String key)
cannot have '.' in json key names change them to '-'
|
static java.lang.String |
getKeyFromJsonSafeKey(java.lang.String jsonSafeKey)
Does the opposite of @link {getJsonSafeKey}
|
static long |
getLongDifference(java.util.Date d1,
java.util.Date d2) |
static java.lang.String |
getMachineUser()
Get the name of the user that is logged in to the host machine.
|
static java.lang.String |
getMemoryStats()
Return a String that contains the free, allocated, max and totalFree (free+(max-allocated))
|
static java.lang.String |
getMessage(java.util.ResourceBundle bundle,
java.lang.String keyName)
Wrap ResourceBundle.getString() so it does not throw an exception if the
key cannot be found.
|
static java.lang.String |
getMessage(java.util.ResourceBundle bundle,
java.lang.String keyName,
boolean returnKey) |
static int |
getPercentage(int x,
int y)
Returns percentage given two numbers.
|
static java.util.ResourceBundle |
getResourceBundle(java.lang.String bundleBaseName,
java.util.Locale locale)
Wrap ResourceBundle.getBundle() so it does not throw an exception of the
bundle cannot be found.
|
static java.lang.String |
getResourcePath(java.lang.String name)
Attempts to determine the absolute pathname of a resource file.
|
static java.lang.String |
getString(java.util.Map map,
java.lang.String name)
Return a map value as a string.
|
static java.lang.String |
getString(java.lang.String s)
Return the given String or null (if the given String is null or
zero-length).
|
static java.util.HashMap |
hashtableToMap(java.util.Hashtable hash)
Convert a Hashtable into a HashMap.
|
static java.lang.String |
htmlify(java.lang.String src)
Take a string that can contain formatting characters typical
for hand-edited XML and simplify it for rendering as HTML
or within an Ext component.
|
static java.util.Date |
incrementDateByDays(java.util.Date date,
long duration) |
static java.util.Date |
incrementDateByMinutes(java.util.Date date,
int minutes) |
static java.util.Date |
incrementDateBySeconds(java.util.Date date,
int seconds) |
static boolean |
isAlreadyExistsException(java.lang.Throwable t)
Return true if the exception means that an attempt was made
to save an object with a name that was already in use.
|
static boolean |
isAnyNullOrEmpty(java.lang.String... vals) |
static boolean |
isDateAfter(java.util.Date testDate,
java.util.Date startDate)
Determine whether the testDate is greater than or equal to the startDate
|
static boolean |
isDateAfterToday(java.util.Date date) |
static boolean |
isEmpty(java.util.Collection collection) |
static boolean |
isEmpty(java.util.Iterator i)
Return true if the specified Iterator is empty.
|
static boolean |
isEmpty(java.util.Map map) |
static boolean |
isEmpty(java.lang.String csv) |
static boolean |
isFirstElement(java.lang.Object o,
java.lang.Iterable i)
Return true if the given object is the first element of the given
Iterable.
|
static boolean |
isInt(java.lang.String str) |
static boolean |
isLastElement(java.lang.Object o,
java.lang.Iterable i) |
static boolean |
isNothing(java.lang.String str) |
static boolean |
isNotNullOrEmpty(java.lang.String str)
Negative of isNullOrEmpty
Its simply there for easier to read code.
|
static boolean |
isNullOrEmpty(java.lang.String str) |
static boolean |
isWindows() |
static <T> java.lang.Iterable<T> |
iterate(java.lang.Iterable<T> iterable)
Alternate name that's easier to remember.
|
static <T> java.util.List<T> |
iteratorToList(java.util.Iterator<T> iterator)
Return a List with the elements returned by the given iterator.
|
static java.util.List<java.util.Map<java.lang.String,java.lang.Object>> |
iteratorToMaps(java.util.Iterator<java.lang.Object[]> iterator,
java.lang.String... keys)
Return a List of maps that have the object arrays in the given iterator
keyed by the given list of keys.
|
static java.lang.String |
itoa(int i)
Convert an primitive integer value into a String.
|
static java.lang.String |
join(java.util.Collection c,
java.lang.String delimiter)
Join the items in a collection into a String just as the Perl join
function does.
|
static java.lang.String |
leftPadZeros(int toValue,
int padding)
Takes an integer value and left pads it with 0s.
|
static java.lang.String |
listToCsv(java.util.List list)
Convert a list of strings into a comma delimited list.
|
static java.lang.String |
listToCsv(java.util.List list,
boolean filterEmpty) |
static java.lang.String |
listToPipeDelimited(java.util.List list)
Return a pipe (|) delimited string with all values in the given list.
|
static java.lang.String |
listToQuotedCsv(java.util.List list,
java.lang.Character quoteChar,
boolean filterEmpty)
Convert a list of strings into a comma delimited list of Strings wrapped in the specified
type of quote.
|
static java.lang.String |
listToQuotedCsv(java.util.List list,
java.lang.Character quoteChar,
boolean filterEmpty,
boolean conditionallyQuote)
This is similar to listToQuoteCsv but allows the specification
of the conditionally quoted individual values in a csv that have
embedded commas.
|
static java.lang.String |
listToRfc4180Csv(java.util.List<?> list) |
static java.lang.String |
longToDottedQuad(long inaddr) |
static java.lang.String |
ltoa(long i) |
static void |
main(java.lang.String[] args) |
static <T> java.util.List<T> |
mapKeys(java.util.Map<T,?> map)
Return a list of the keys in a Map
|
static java.lang.String |
mapToString(java.util.Map map)
Convert the given Map to a String.
|
static java.lang.String |
memoryFormat(long size)
Converts number of bytes to a human readable format.
|
static long[] |
mergeAndSortArrays(long[] array1,
long[] array2)
Merge the contents of two arrays of longs into a newly created sorted array
|
static java.lang.Object |
nullify(java.lang.Object obj)
Collapse a value to null if it is logically null.
|
static boolean |
nullsafeBoolean(java.lang.Boolean val) |
static boolean |
nullSafeCaseInsensitiveEq(java.lang.String o1,
java.lang.String o2)
This method performs a null-safe equality comparison between the two strings.
|
static <T extends java.lang.Comparable> |
nullSafeCompareTo(T o1,
T o2)
Return the compareTo() value for two objects that may be null.
|
static boolean |
nullSafeContains(java.util.List list,
java.lang.Object o)
Check a list for the given object, checking for
null on the list.
|
static boolean |
nullSafeContains(java.lang.String csv,
java.lang.Object o)
Check a csv-based list for the given object, checking for
null on the list.
|
static boolean |
nullSafeEq(java.lang.Object o1,
java.lang.Object o2)
This method performs a null-safe equality comparison between the two
given objects.
|
static boolean |
nullSafeEq(java.lang.Object o1,
java.lang.Object o2,
boolean nullsEq)
This method performs a null-safe equality comparison between the two
given objects.
|
static boolean |
nullSafeEq(java.lang.Object o1,
java.lang.Object o2,
boolean nullsEq,
boolean emptyStringToNull)
This method performs a null-safe equality comparison between the two
given objects.
|
static int |
nullSafeHashCode(java.lang.Object o)
Return the hashcode of the given object, or -1 if the given object is
null.
|
static long |
nullsafeLong(java.lang.Long val) |
static <T> boolean |
orderInsensitiveEquals(java.util.List<T> l1,
java.util.List<T> l2)
Check if the two given Lists contain all of the same elements.
|
static java.lang.String |
otoa(java.lang.Object o) |
static boolean |
otob(java.lang.Object o) |
static int |
otoi(java.lang.Object o) |
static java.util.List<java.lang.String> |
otol(java.lang.Object o)
Convert an object to a List of Strings.
|
static java.lang.String |
otos(java.lang.Object o)
Convert an object to its string representation.
|
static java.lang.String |
padID(java.lang.String strId) |
static int |
rand(int low,
int high)
Generate a random number between a low a high value inclusive.
|
static byte[] |
readBinaryFile(java.io.File f) |
static byte[] |
readBinaryFile(java.lang.String name)
Read the contents of a file and return it as a byte array.
|
static byte[] |
readBinaryInputStream(java.io.InputStream inputStream) |
static java.lang.String |
readFile(java.io.File f) |
static java.lang.String |
readFile(java.lang.String name)
Read the contents of a file and return it as a String.
|
static java.lang.String |
readInputStream(java.io.InputStream inputStream) |
static java.lang.Object |
readSerializedObject(byte[] bytes)
Reconstitute a serialized object from a byte array.
|
static <T> void |
removeDuplicates(java.util.List<T> list) |
static <T> java.lang.Iterable<T> |
safeIterable(java.lang.Iterable<T> iterable)
Constructs a null-safe iterable for use with for-each loops to avoid null
checking.
|
static byte[] |
serializableObjectToBytes(java.lang.Object toWrite)
Convert a Serializable Object into a byte array.
|
static java.lang.String |
setToCsv(java.util.Set<?> set) |
static java.lang.String[] |
shiftArray(java.lang.String[] input)
Return a copy of the array with the first element removed.
|
static int |
size(java.util.Collection c)
Return the size of the given collection.
|
static void |
sleep(int millis)
Pause for reflection, catching the usual silly exception.
|
static boolean |
smellsLikeMessageKey(java.lang.String key)
Does the given string look like a message key?
|
static java.lang.String |
splitCamelCase(java.lang.String str)
Takes a camel case string, splits the words out of it
and capitalizes each one.
|
static java.lang.StringBuffer |
sprintf(java.lang.String format,
java.lang.String[] args)
A marginally functional attempt to provide "sprintf" in Java.
|
static java.lang.String |
stackToString(java.lang.Throwable th)
Converts the stack trace of an exception to a String
|
static java.util.Date |
stringToDate(java.lang.String src)
Convert the string representation for a date into a Date object.
|
static java.util.List |
stringToList(java.lang.String value)
Note: Why don't we return List
|
static java.util.Map |
stringToMap(java.lang.String value)
Convert the string representation for a map into a Map object
|
static java.util.Date |
stringToTime(java.lang.String src)
Convert the string representation for a date into a Date object.
|
static java.lang.String |
stripLeadingChar(java.lang.String s,
char c)
Strip all occurrences of the given character off the front of the
given string.
|
static java.lang.String |
strstr(java.lang.String inString,
java.lang.String delimeter)
Returns the last token in a string of tokens
separated by delimiter argument.
|
static java.lang.String |
trimnull(java.lang.String str)
Like nullify but we don't have to cast the return
|
static java.lang.String |
trimWhitespace(java.lang.String src)
Trims trailing whitespace from a string.
|
static java.lang.String |
truncate(java.lang.String s,
int maxLength)
Truncate the given string if it is longer than maxLength - if so, the
last 3 characters are replaced with an ellipsis (...).
|
static java.lang.String |
truncatedJoin(java.util.Collection c,
java.lang.String delimiter,
int maxChars)
First joins the list of string values using the specified delimiter,
then truncates the resulting string to the specified character
maximum.
|
static java.lang.String |
truncateFront(java.lang.String s,
int maxLength)
Similar to truncate(), but if truncation is necessary the beginning of
the string is trimmed rather than the end.
|
static java.lang.String |
unxml(java.lang.String src)
Remove "xml garbage" from a string that might have started out
life in an XML element.
|
static java.lang.String |
uuid()
Generate a unique identifier.
|
static <T> java.util.List<T> |
wrappedList(java.util.List<T> list,
Util.ListElementWrapper<T> wrapper)
Returns a List backed by the given list that wraps each element that is
returned using the given wrapper.
|
static void |
writeFile(java.lang.String name,
byte[] contents)
Store the contents of a byte array to a file.
|
static void |
writeFile(java.lang.String name,
java.lang.String contents)
Store the contents of a String in a file.
|
static void |
writeTestFile(java.lang.String name,
byte[] contents) |
static void |
writeTestFile(java.lang.String name,
java.lang.String contents) |
public static final long MILLIS_PER_DAY
public static final long MILLI_IN_SECOND
public static final long MILLI_IN_MINUTE
public static final long MILLI_IN_HOUR
public static final long MILLI_IN_DAY
public static final long MILLI_IN_WEEK
public static final long MILLI_IN_MONTH
public static final long MILLI_IN_YEAR
public static final java.lang.String APPLICATION_HOME
public static void sleep(int millis)
public static java.lang.String leftPadZeros(int toValue,
int padding)
public static java.lang.String uuid()
public static java.lang.String getHostName()
public static boolean nullSafeEq(java.lang.Object o1,
java.lang.Object o2)
o1 - The first object to compare.o2 - The second object to compare.public static boolean nullSafeEq(java.lang.Object o1,
java.lang.Object o2,
boolean nullsEq)
o1 - The first object to compare.o2 - The second object to compare.nullsEq - Whether two null objects should be considered equal.public static boolean nullSafeEq(java.lang.Object o1,
java.lang.Object o2,
boolean nullsEq,
boolean emptyStringToNull)
public static boolean nullSafeCaseInsensitiveEq(java.lang.String o1,
java.lang.String o2)
public static <T extends java.lang.Comparable> int nullSafeCompareTo(T o1,
T o2)
public static int nullSafeHashCode(java.lang.Object o)
public static boolean nullSafeContains(java.util.List list,
java.lang.Object o)
list - o - public static boolean nullSafeContains(java.lang.String csv,
java.lang.Object o)
csv - List of objects in CSV formo - Object to check for in the listpublic static int rand(int low,
int high)
public static <T> java.util.List<T> filterNulls(java.util.List<T> src)
public static java.lang.String getJsonSafeKey(java.lang.String key)
public static java.lang.String getKeyFromJsonSafeKey(java.lang.String jsonSafeKey)
public static <T> java.util.List<T> filter(java.util.List<T> list,
Util.ListFilter<T> filter)
throws GeneralException
list - The List to filter.filter - The ListFilter to apply to each element to determine if
it should be in the copy or not.GeneralExceptionpublic static <T> T find(java.util.List<T> values,
Util.IMatcher<T> matcher)
public static <T> java.util.List<T> wrappedList(java.util.List<T> list,
Util.ListElementWrapper<T> wrapper)
list - The List to wrap.wrapper - The ListElementWrapper to use to wrap the elements when
retrieved from the list.Util.ListElementWrapperpublic static java.util.List asList(java.lang.Object o)
o - The object to return as a list.public static boolean isFirstElement(java.lang.Object o,
java.lang.Iterable i)
o - The object to check as the first element.i - The Iterable to check.public static boolean isLastElement(java.lang.Object o,
java.lang.Iterable i)
public static boolean isEmpty(java.util.Iterator i)
i - Iterator being checkedpublic static void flushIterator(java.util.Iterator i)
i - Iterator being exhaustedpublic static <T> boolean orderInsensitiveEquals(java.util.List<T> l1,
java.util.List<T> l2)
l1 - The first List to compare.l2 - The second List to compare.public static <T> T find(java.util.List<T> list,
T t,
java.util.Comparator<T> comparator)
list - The list in which to search for a match to t.t - The object to look for using the comparator in the list.comparator - The Comparator to use to compare t to the list elements.public static <T extends java.lang.Comparable<? super T>> T findComparable(java.util.List<T> list,
T toFind,
boolean sorted)
list - The list of comparable items.toFind - The item to find.sorted - Whether the list is already sorted.public static <T extends java.lang.Comparable<? super T>> boolean containsComparable(java.util.List<T> list,
T toFind,
boolean sorted)
list - The list of comparable items.toFind - The item to find.sorted - Whether the list is already sorted.public static <T> java.util.List<T> arrayToList(T[] array)
array - Array to copy to a listpublic static java.lang.String[] shiftArray(java.lang.String[] input)
input - The array to shift.public static long[] mergeAndSortArrays(long[] array1,
long[] array2)
array1 - First array to mergearray2 - Second array to mergepublic static <T> java.util.List<T> iteratorToList(java.util.Iterator<T> iterator)
iterator - The Iterator from which to create the List.public static <T> java.lang.Iterable<T> safeIterable(java.lang.Iterable<T> iterable)
iterable - The iterable to use.public static <T> java.lang.Iterable<T> iterate(java.lang.Iterable<T> iterable)
public static java.util.List<java.util.Map<java.lang.String,java.lang.Object>> iteratorToMaps(java.util.Iterator<java.lang.Object[]> iterator,
java.lang.String... keys)
iterator - The Iterator from which to create the List of Maps.keys - The keys for the maps that are being created. The
number of keys must match the number of objects in each
Object[] in the iterator. Note that this can be a
single string that has a comma-separated list of keys.public static int size(java.util.Collection c)
c - The possibly-null collection to get the size of.public static boolean isEmpty(java.util.Collection collection)
public static boolean isEmpty(java.util.Map map)
public static boolean isEmpty(java.lang.String csv)
csv - CSV that is being checked for emptinesspublic static <T> java.util.List<T> mapKeys(java.util.Map<T,?> map)
map - Map containing keyspublic static boolean containsAny(java.util.Collection c1,
java.util.Collection c2)
c1 - The first collection to compare.c2 - The second collection to compare.public static java.lang.String getString(java.util.Map map,
java.lang.String name)
public static boolean getBoolean(java.util.Map map,
java.lang.String name)
public static int getInt(java.util.Map map,
java.lang.String name)
public static java.util.Date getDate(java.util.Map map,
java.lang.String name)
public static java.lang.Object get(java.util.Map map,
java.lang.String name)
public static java.lang.String htmlify(java.lang.String src)
public static java.lang.String getFullname(java.lang.String first,
java.lang.String last)
public static java.lang.String getString(java.lang.String s)
s - The String to filter.public static java.lang.Object nullify(java.lang.Object obj)
public static java.lang.String trimnull(java.lang.String str)
public static java.lang.String capitalize(java.lang.String str)
str - string in need of some capitalizationpublic static java.lang.String capitalizeAndNormalize(java.lang.String str)
str - string in need of helppublic static java.lang.String truncate(java.lang.String s,
int maxLength)
s - The string to truncate.maxLength - The maximum length.public static java.lang.String truncateFront(java.lang.String s,
int maxLength)
s - The string to truncate.maxLength - The maximum length.public static java.lang.String stripLeadingChar(java.lang.String s,
char c)
public static java.lang.String splitCamelCase(java.lang.String str)
public static java.lang.String encodeJavaIdentifier(java.lang.String s)
s - The string to convert to a valid java identifier.public static java.lang.String decodeJavaIdentifier(java.lang.String s)
throws Util.ParseException
s - The string to decode.Util.ParseException - If the given string is not a valid encoded java identifier. The
method encodeJavaIdentifier() should always produce valid identifiers
that will not throw this exception.public static java.lang.String itoa(int i)
public static java.lang.String ltoa(long i)
public static java.lang.String ftoa(float i)
public static int atoi(java.lang.String a)
public static int atoi(java.lang.String a,
int def)
public static long atol(java.lang.String a)
public static float atof(java.lang.String a)
public static boolean atob(java.lang.String a)
public static java.lang.String otoa(java.lang.Object o)
public static boolean otob(java.lang.Object o)
public static int otoi(java.lang.Object o)
public static java.lang.String otos(java.lang.Object o)
o - The object to convert to a string.public static java.util.List<java.lang.String> otol(java.lang.Object o)
o - Either a Listpublic static java.lang.String trimWhitespace(java.lang.String src)
public static java.lang.String deleteWhitespace(java.lang.String src)
public static java.lang.String compressWhiteSpace(java.lang.String str)
"What does this do?"becomes
"What does this do?"
str - string in need of compressionpublic static java.lang.String unxml(java.lang.String src)
public static java.lang.String strstr(java.lang.String inString,
java.lang.String delimeter)
public static java.lang.String expandVariables(java.lang.String src,
java.util.Map<java.lang.String,java.lang.Object> variables)
If a variable is not defined, it silently expands to nothing.
A variable is referenced with the syntax "$(x)" where "x" is the name of the variable. Values for variables are supplied through a Map.
public static java.lang.String escapeNewlines(java.lang.String src)
Ordinarilly done if you want to store a string as a value in a property file, where the newline marks the end of the value.
public static java.lang.String escapeHTMLNewlines(java.lang.String src)
public static java.lang.String escapeNewlines(java.lang.String src,
java.lang.String nRepl,
java.lang.String rRepl)
public static java.util.List<java.lang.String> delimToList(java.lang.String delim,
java.lang.String src,
boolean filterEmpty)
public static java.util.List<java.lang.String> csvToList(java.lang.String src)
public static java.util.List<java.lang.String> csvToList(java.lang.String src,
boolean filterEmpty)
public static java.lang.String[] csvToArray(java.lang.String src)
public static java.util.Set<java.lang.String> csvToSet(java.lang.String src,
boolean filterEmpty)
public static java.lang.String setToCsv(java.util.Set<?> set)
public static java.lang.String listToCsv(java.util.List list)
public static java.lang.String listToCsv(java.util.List list,
boolean filterEmpty)
public static java.lang.String listToQuotedCsv(java.util.List list,
java.lang.Character quoteChar,
boolean filterEmpty)
list - List of objects to be converted into a list of stringsquoteChar - Quote character in which to wrap the strings. Can be ', ", or null.
If null is specified no quotes will be appliedfilterEmpty - True to filter blank strings out of the list. False to include thempublic static java.lang.String listToQuotedCsv(java.util.List list,
java.lang.Character quoteChar,
boolean filterEmpty,
boolean conditionallyQuote)
listToQuotedCsv(List, Character, boolean)public static java.lang.String listToRfc4180Csv(java.util.List<?> list)
public static java.lang.String listToPipeDelimited(java.util.List list)
list - The List to convert to a pipe delimited string.public static java.lang.String join(java.util.Collection c,
java.lang.String delimiter)
c - the Collection to joindelimiter - the delimeter to place between the collection elementspublic static java.lang.String truncatedJoin(java.util.Collection c,
java.lang.String delimiter,
int maxChars)
c - The collection to join.delimiter - The join character.maxChars - The maximum characters after truncation.public static byte[] readBinaryFile(java.lang.String name)
throws GeneralException
GeneralExceptionpublic static byte[] readBinaryInputStream(java.io.InputStream inputStream)
throws GeneralException
GeneralExceptionpublic static byte[] readBinaryFile(java.io.File f)
throws GeneralException
GeneralExceptionpublic static java.lang.String readInputStream(java.io.InputStream inputStream)
throws GeneralException
GeneralExceptionpublic static java.lang.String readFile(java.lang.String name)
throws GeneralException
GeneralExceptionpublic static java.lang.String readFile(java.io.File f)
throws GeneralException
GeneralExceptionpublic static java.lang.String bytesToString(byte[] bytes)
throws GeneralException
GeneralExceptionpublic static void writeFile(java.lang.String name,
byte[] contents)
throws GeneralException
GeneralExceptionpublic static void writeTestFile(java.lang.String name,
byte[] contents)
public static void writeFile(java.lang.String name,
java.lang.String contents)
throws GeneralException
GeneralExceptionpublic static void writeTestFile(java.lang.String name,
java.lang.String contents)
public static void copyFile(java.lang.String src,
java.lang.String dest)
throws GeneralException,
java.io.IOException
I'm sort of suprised the JDK doesn't have something to do this. If this were used with large files, we'd want to do iterate over a fixed block size.
GeneralExceptionjava.io.IOExceptionpublic static java.lang.String getMachineUser()
public static java.util.Date getDate(java.lang.Object o)
public static java.lang.String dateToString(java.util.Date src)
public static java.lang.String dateToString(java.util.Date src,
java.lang.String format)
public static java.lang.String dateToString(java.util.Date src,
java.lang.String format,
java.util.TimeZone tz)
public static java.util.Date incrementDateByDays(java.util.Date date,
long duration)
public static java.util.Date incrementDateByMinutes(java.util.Date date,
int minutes)
public static java.util.Date incrementDateBySeconds(java.util.Date date,
int seconds)
public static java.util.Date getBeginningOfDay(java.util.Date day)
public static java.util.Date getEndOfDay(java.util.Date day)
public static java.lang.String dateToString(java.util.Date src,
java.lang.Integer dateFormat,
java.lang.Integer timeFormat)
public static java.lang.String dateToString(java.util.Date src,
java.lang.Integer dateFormat,
java.lang.Integer timeFormat,
java.util.TimeZone timeZone,
java.util.Locale locale)
public static java.util.Date baselineDate(java.util.Date src)
public static java.util.Date baselineDate(java.util.Date src,
java.util.TimeZone timeZone)
src - Date to baselinetimeZone - Optional. Timezone to use when getting day of month.public static java.util.Date dateBetween(java.util.Date startDate,
java.util.Date endDate)
public static boolean isDateAfter(java.util.Date testDate,
java.util.Date startDate)
testDate - Date that we want to teststartDate - Beginning of the test intervalpublic static java.util.List stringToList(java.lang.String value)
public static java.lang.String mapToString(java.util.Map map)
public static java.util.Map stringToMap(java.lang.String value)
public static java.util.Date stringToDate(java.lang.String src)
throws java.text.ParseException
java.text.ParseExceptionpublic static java.util.Date stringToTime(java.lang.String src)
throws java.text.ParseException
java.text.ParseExceptionpublic static int getDaysDifference(java.util.Date d1,
java.util.Date d2)
public static boolean isDateAfterToday(java.util.Date date)
public static long getLongDifference(java.util.Date d1,
java.util.Date d2)
public static int getPercentage(int x,
int y)
x - number to dividey - number to divide bypublic static long computeDifferenceMilli(java.util.Date start,
java.util.Date end)
throws GeneralException
GeneralExceptionpublic static java.lang.String computeDifference(java.util.Date start,
java.util.Date end)
throws GeneralException
GeneralExceptionpublic static java.lang.StringBuffer sprintf(java.lang.String format,
java.lang.String[] args)
public static java.lang.String getResourcePath(java.lang.String name)
public static java.lang.String getClasspathDirectory(int idx)
public static java.lang.String findFile(java.lang.String property,
java.lang.String name,
boolean searchClasspath)
public static java.lang.String findFile(java.lang.String property,
java.lang.String name)
public static java.lang.String findFile(java.lang.String name)
public static java.lang.String findOutputFile(java.lang.String name)
public static java.lang.String getApplicationHome()
throws GeneralException
GeneralExceptionpublic static void dumpProperties(java.io.PrintWriter out)
public static void dumpProperties()
public static java.util.HashMap hashtableToMap(java.util.Hashtable hash)
public static java.lang.String stackToString(java.lang.Throwable th)
public static boolean isAlreadyExistsException(java.lang.Throwable t)
public static byte[] serializableObjectToBytes(java.lang.Object toWrite)
throws java.io.IOException
toWrite - The Object to serialize to bytes.java.io.IOExceptionpublic static java.lang.Object readSerializedObject(byte[] bytes)
throws java.io.IOException,
java.lang.ClassNotFoundException
bytes - The byte array containing the serialized object.java.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic static void main(java.lang.String[] args)
public static java.lang.String longToDottedQuad(long inaddr)
public static long dottedQuadToLong(java.lang.String ipaddr)
public static boolean isWindows()
public static java.lang.Object createObjectByClassName(java.lang.String name)
throws GeneralException
This method calls Class.forname and then creates a default instance using the newInstance() method on the Class object. This means the object must have a no argument constructor for this method to work properly.
GeneralExceptionpublic static java.lang.String memoryFormat(long size)
size - number of bytespublic static java.util.ResourceBundle getIIQMessages(java.util.Locale locale)
public static java.util.ResourceBundle getIIQHelpMessages(java.util.Locale locale)
public static java.util.ResourceBundle getResourceBundle(java.lang.String bundleBaseName,
java.util.Locale locale)
public static java.lang.String getMessage(java.util.ResourceBundle bundle,
java.lang.String keyName)
public static java.lang.String getMessage(java.util.ResourceBundle bundle,
java.lang.String keyName,
boolean returnKey)
public static java.lang.String getMemoryStats()
public static boolean isNullOrEmpty(java.lang.String str)
public static boolean isNotNullOrEmpty(java.lang.String str)
public static boolean isAnyNullOrEmpty(java.lang.String... vals)
public static boolean isNothing(java.lang.String str)
public static boolean isInt(java.lang.String str)
public static boolean smellsLikeMessageKey(java.lang.String key)
public static int countChars(java.lang.String sourceString,
char lookFor)
public static <T1,T2> java.util.List<T2> convert(java.util.List<T1> list1,
Util.IConverter<T1,T2> converter)
throws GeneralException
GeneralExceptionpublic static long nullsafeLong(java.lang.Long val)
public static boolean nullsafeBoolean(java.lang.Boolean val)
public static java.lang.String padID(java.lang.String strId)
public static <T> void removeDuplicates(java.util.List<T> list)
public static <T> T caseInsensitiveKeyValue(java.util.Map<java.lang.String,T> map,
java.lang.String key)
T - type of map valuesmap - The map.key - The string key