serp.util
public class Strings extends java.lang.Object
Constructor and Description |
---|
Strings() |
Modifier and Type | Method and Description |
---|---|
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.
|
public static java.lang.String replace(java.lang.String str, java.lang.String from, java.lang.String to)
from
in str
with to
.str
- the candidate string to replacefrom
- the token to replaceto
- the new tokenpublic static java.lang.String[] split(java.lang.String str, java.lang.String token, int max)
String.split(String,int)
method, but does
not treat the given token as a regular expression.public static java.lang.String join(java.lang.Object[] strings, java.lang.String token)
public static java.lang.Class toClass(java.lang.String str, java.lang.ClassLoader loader)
java.lang.RuntimeException
- on load errorpublic static java.lang.Class toClass(java.lang.String str, boolean resolve, java.lang.ClassLoader loader)
java.lang.RuntimeException
- on load errorpublic static java.lang.String getClassName(java.lang.Class cls)
public static java.lang.String getClassName(java.lang.String fullName)
public static java.lang.String getPackageName(java.lang.Class cls)
public static java.lang.String getPackageName(java.lang.String fullName)
public static java.lang.Object parse(java.lang.String val, java.lang.Class type)
val
as the type specified by
type
. If type
is a primitive, the
primitive wrapper type is created and returned, and
null
s are converted to the Java default for the
primitive type.val
- The string value to parsetype
- The type to parse. This must be a primitive or a
primitive wrapper, or one of BigDecimal
,
BigInteger
, String
, Date
.java.lang.IllegalArgumentException
- if type
is not a
supported type, or if val
cannot be
converted into an instance of type type
.public static boolean canParse(java.lang.Class type)
parse(java.lang.String, java.lang.Class)
.