Package serp.util
Class Strings
java.lang.Object
serp.util.Strings
String utiltity methods.
- Author:
- Abe White
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanWhether the given type is parsable viaparse(java.lang.String, java.lang.Class).static StringgetClassName(Class cls) Return only the class name, without package.static StringgetClassName(String fullName) Return only the class name.static StringgetPackageName(Class cls) Return only the package, or empty string if none.static StringgetPackageName(String fullName) Return only the package, or empty string if none.static StringJoins the given strings, placing the given token between them.static ObjectReturnvalas the type specified bytype.static StringReplace all instances offrominstrwithto.static String[]Splits the given string on the given token.static ClasstoClass(String str, boolean resolve, ClassLoader loader) Return the class for the given string, correctly handling primitive types.static ClasstoClass(String str, ClassLoader loader) Return the class for the given string, correctly handling primitive types.
-
Constructor Details
-
Strings
public Strings()
-
-
Method Details
-
replace
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
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
Joins the given strings, placing the given token between them. -
toClass
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:
RuntimeException- on load error
-
toClass
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:
RuntimeException- on load error
-
getClassName
Return only the class name, without package. -
getClassName
Return only the class name. -
getPackageName
Return only the package, or empty string if none. -
getPackageName
Return only the package, or empty string if none. -
parse
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:
IllegalArgumentException- iftypeis not a supported type, or ifvalcannot be converted into an instance of typetype.
-
canParse
Whether the given type is parsable viaparse(java.lang.String, java.lang.Class).
-