Package serp.util
Class Strings
- java.lang.Object
-
- serp.util.Strings
-
public class Strings extends java.lang.ObjectString utiltity methods.- Author:
- Abe White
-
-
Constructor Summary
Constructors Constructor Description Strings()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancanParse(java.lang.Class type)Whether the given type is parsable viaparse(java.lang.String, java.lang.Class).static java.lang.StringgetClassName(java.lang.Class cls)Return only the class name, without package.static java.lang.StringgetClassName(java.lang.String fullName)Return only the class name.static java.lang.StringgetPackageName(java.lang.Class cls)Return only the package, or empty string if none.static java.lang.StringgetPackageName(java.lang.String fullName)Return only the package, or empty string if none.static java.lang.Stringjoin(java.lang.Object[] strings, java.lang.String token)Joins the given strings, placing the given token between them.static java.lang.Objectparse(java.lang.String val, java.lang.Class type)Returnvalas the type specified bytype.static java.lang.Stringreplace(java.lang.String str, java.lang.String from, java.lang.String to)Replace all instances offrominstrwithto.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.ClasstoClass(java.lang.String str, boolean resolve, java.lang.ClassLoader loader)Return the class for the given string, correctly handling primitive types.static java.lang.ClasstoClass(java.lang.String str, java.lang.ClassLoader loader)Return the class for the given string, correctly handling primitive types.
-
-
-
Method Detail
-
replace
public static java.lang.String replace(java.lang.String str, java.lang.String from, java.lang.String to)Replace all instances offrominstrwithto.- Parameters:
str- the candidate string to replacefrom- the token to replaceto- 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.4String.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)Returnvalas the type specified bytype. Iftypeis a primitive, the primitive wrapper type is created and returned, andnulls are converted to the Java default for the primitive type.- Parameters:
val- The string value to parsetype- The type to parse. This must be a primitive or a primitive wrapper, or one ofBigDecimal,BigInteger,String,Date.- Throws:
java.lang.IllegalArgumentException- iftypeis not a supported type, or ifvalcannot be converted into an instance of typetype.
-
canParse
public static boolean canParse(java.lang.Class type)
Whether the given type is parsable viaparse(java.lang.String, java.lang.Class).
-
-