serp.util
Class Strings

java.lang.Object
  extended by serp.util.Strings

public class Strings
extends java.lang.Object

String utiltity methods.


Constructor Summary
Strings()
           
 
Method Summary
static boolean canParse(java.lang.Class type)
          Whether the given type is parsable via parse(java.lang.String, java.lang.Class).
static java.lang.String getClassName(java.lang.Class cls)
          Return only the class name, without package.
static java.lang.String getClassName(java.lang.String fullName)
          Return only the class name.
static java.lang.String getPackageName(java.lang.Class cls)
          Return only the package, or empty string if none.
static java.lang.String getPackageName(java.lang.String fullName)
          Return only the package, or empty string if none.
static java.lang.String join(java.lang.Object[] strings, java.lang.String token)
          Joins the given strings, placing the given token between them.
static java.lang.Object parse(java.lang.String val, java.lang.Class type)
          Return val as the type specified by type.
static java.lang.String replace(java.lang.String str, java.lang.String from, java.lang.String to)
          Replace all instances of from in str with to.
static java.lang.String[] split(java.lang.String str, java.lang.String token, int max)
          Splits the given string on the given token.
static java.lang.Class toClass(java.lang.String str, boolean resolve, java.lang.ClassLoader loader)
          Return the class for the given string, correctly handling primitive types.
static java.lang.Class toClass(java.lang.String str, java.lang.ClassLoader loader)
          Return the class for the given string, correctly handling primitive types.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strings

public Strings()
Method Detail

replace

public static java.lang.String replace(java.lang.String str,
                                       java.lang.String from,
                                       java.lang.String to)
Replace all instances of from in str with to.

Parameters:
str - the candidate string to replace
from - the token to replace
to - the new token
Returns:
the string with all the replacements made

split

public static java.lang.String[] split(java.lang.String str,
                                       java.lang.String token,
                                       int max)
Splits the given string on the given token. Follows the semantics of the Java 1.4 String.split(String,int) method, but does not treat the given token as a regular expression.


join

public static java.lang.String join(java.lang.Object[] strings,
                                    java.lang.String token)
Joins the given strings, placing the given token between them.


toClass

public static java.lang.Class toClass(java.lang.String str,
                                      java.lang.ClassLoader loader)
Return the class for the given string, correctly handling primitive types. If the given class loader is null, the context loader of the current thread will be used.

Throws:
java.lang.RuntimeException - on load error

toClass

public static java.lang.Class toClass(java.lang.String str,
                                      boolean resolve,
                                      java.lang.ClassLoader loader)
Return the class for the given string, correctly handling primitive types. If the given class loader is null, the context loader of the current thread will be used.

Throws:
java.lang.RuntimeException - on load error

getClassName

public static java.lang.String getClassName(java.lang.Class cls)
Return only the class name, without package.


getClassName

public static java.lang.String getClassName(java.lang.String fullName)
Return only the class name.


getPackageName

public static java.lang.String getPackageName(java.lang.Class cls)
Return only the package, or empty string if none.


getPackageName

public static java.lang.String getPackageName(java.lang.String fullName)
Return only the package, or empty string if none.


parse

public static java.lang.Object parse(java.lang.String val,
                                     java.lang.Class type)
Return val as the type specified by type. If type is a primitive, the primitive wrapper type is created and returned, and nulls are converted to the Java default for the primitive type.

Parameters:
val - The string value to parse
type - The type to parse. This must be a primitive or a primitive wrapper, or one of BigDecimal, BigInteger, String, Date.
Throws:
java.lang.IllegalArgumentException - if type is not a supported type, or if val cannot be converted into an instance of type type.

canParse

public static boolean canParse(java.lang.Class type)
Whether the given type is parsable via parse(java.lang.String, java.lang.Class).