Package serp.util

# Class Strings

java.lang.Object
serp.util.Strings

public class Strings extends Object
String utiltity methods.

Author:
  Abe White

## Constructor Summary

Constructors
Constructor
Description
`Strings()`

## Method Summary

Modifier and Type
Method
Description
`static boolean`
`canParse(Class type)`
Whether the given type is parsable via `parse(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`
`join(Object[] strings, String token)`
Joins the given strings, placing the given token between them.
`static Object`
`parse(String val, Class type)`
Return `val` as the type specified by `type`.
`static String`
`replace(String str, String from, String to)`
Replace all instances of `from` in `str` with `to`.
`static String[]`
`split(String str, String token, int max)`
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.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### Strings

public Strings()

## Method Details

### replace

public static String replace(String str, String from, 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 String[] split(String str, 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 String join(Object[] strings, String token)
Joins the given strings, placing the given token between them.

### toClass

public static Class toClass(String str, 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:
  `RuntimeException` - on load error

### toClass

public static Class toClass(String str, boolean resolve, 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:
  `RuntimeException` - on load error

### getClassName

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

### getClassName

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

### getPackageName

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

### getPackageName

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

### parse

public static Object parse(String val, Class type)
Return `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.

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:
  `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(Class type)
Whether the given type is parsable via `parse(java.lang.String, java.lang.Class)`.