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 boolean
Whether the given type is parsable viaparse(java.lang.String, java.lang.Class)
.static String
getClassName
(Class cls) Return only the class name, without package.static String
getClassName
(String fullName) Return only the class name.static String
getPackageName
(Class cls) Return only the package, or empty string if none.static String
getPackageName
(String fullName) Return only the package, or empty string if none.static String
Joins the given strings, placing the given token between them.static Object
Returnval
as the type specified bytype
.static String
Replace all instances offrom
instr
withto
.static String[]
Splits the given string on the given token.static Class
toClass
(String str, boolean resolve, ClassLoader loader) Return the class for the given string, correctly handling primitive types.static Class
toClass
(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 offrom
instr
withto
.- 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
Returnval
as the type specified bytype
. Iftype
is a primitive, the primitive wrapper type is created and returned, andnull
s 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
- iftype
is not a supported type, or ifval
cannot be converted into an instance of typetype
.
-
canParse
Whether the given type is parsable viaparse(java.lang.String, java.lang.Class)
.
-