org.base.apps.util
Class Util

java.lang.Object
  extended by org.base.apps.util.Util

public class Util
extends Object

General utility methods.

Author:
Kevan Simpson

Method Summary
static String concat(Object... objs)
          Concatenates the specified parameters into a single string.
static String format(String msg, Object... tkns)
          Formats the given parameters via MessageFormat.format(String, Object...), passing back the parameters as a concatenated string if formatting fails.
static String formatDate(Date dt)
          Formats the given date with the pattern: "MM/dd/yyyy".
static String formatDate(Date dt, String pattern)
          Formats the given date with the specified pattern.
static Class<?> getClass(String type)
          Attempts to fetch a class by name and, if unsuccessful, will manipulate the given type to determine if it's an inner class (which will subsequently be fetched instead).
static String join(String delim, Object... objs)
          Concatenates the specified parameters, inserting the given delimiter between each parameter.
static Date parseDate(String str, String... patterns)
          Attempts to parse the given text with one of the specified patterns.
static
<T extends Enum<T>>
T
valueOf(Class<T> enumClass, CharSequence expr)
          Invokes null-safe version of the Enum.valueOf(Class, String) method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

formatDate

public static String formatDate(Date dt)
Formats the given date with the pattern: "MM/dd/yyyy".

Parameters:
dt - The date to format
Returns:
The formatted date or "--/--/----" if the date is null.

formatDate

public static String formatDate(Date dt,
                                String pattern)
Formats the given date with the specified pattern.

Parameters:
dt - The date to format
pattern - The pattern with which to format the date
Returns:
The formatted date or "--/--/----" if the date is null.

parseDate

public static Date parseDate(String str,
                             String... patterns)
Attempts to parse the given text with one of the specified patterns. Each pattern will be applied against the given text, in argument order sequence, until the text is successfully parsed or the set of patterns is exhausted.

If no patterns are specified, the pattern "MM/dd/yyyy" will be applied.

Parameters:
str - The text to parse
patterns - Zero or more patterns with which to parse the given text.
Returns:
The parsed date or null, if parsing was unsuccessful.

concat

public static String concat(Object... objs)
Concatenates the specified parameters into a single string.

Parameters:
objs - The parameters to concatenate.
Returns:
A concatenated string.
See Also:
StringUtils.join(Object[])

format

public static String format(String msg,
                            Object... tkns)
Formats the given parameters via MessageFormat.format(String, Object...), passing back the parameters as a concatenated string if formatting fails.

Parameters:
msg - The formatted message
tkns - The tokens to insert in the message
Returns:
The formatted text or, if formatting fails, the given parameters concatenated.

getClass

public static Class<?> getClass(String type)
Attempts to fetch a class by name and, if unsuccessful, will manipulate the given type to determine if it's an inner class (which will subsequently be fetched instead).

Parameters:
type - The class type
Returns:
The loaded class, an inner class (if one was requested), or null
Throws:
RuntimeException - if the given type does not match any known class

join

public static String join(String delim,
                          Object... objs)
Concatenates the specified parameters, inserting the given delimiter between each parameter.

Parameters:
delim - A delimiter inserted between parameters.
objs - The parameters to join.
Returns:
A joined string.

valueOf

public static <T extends Enum<T>> T valueOf(Class<T> enumClass,
                                            CharSequence expr)
Invokes null-safe version of the Enum.valueOf(Class, String) method.

Type Parameters:
T - The generic type of the enum.
Parameters:
enumClass - The class of the enum.
expr - The name of the enum as a sequence of characters.
Returns:
An enum with the given name and type or null.

Please visit Base Apps, hosted on Sourceforge.net.

Copyright 2011, Blue Agate Software Entity (BASE)