|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.core.StringUtil
public class StringUtil
Utility methods that will make it easier to implement data validation for string attributes.
Constructor Summary | |
---|---|
StringUtil()
|
Method Summary | |
---|---|
static String |
getCommonPrefix(Collection<String> strings)
Find the longest common prefix for a collection of strings. |
static boolean |
isEqualOrNull(String s1,
String s2)
Check if two strings are equal or both are null. |
static boolean |
isEqualOrNull(String s1,
String s2,
boolean caseInsensitive)
Check if two strings are equal or both are null. |
static String |
join(Collection<?> values,
String deliminator,
boolean skipNull)
Join a collection of values to a string, using the specified delimiator. |
static String |
setNotNullString(String value,
String name,
int maxLength)
Trim and check the length of a string. |
static String |
setNullableString(String value,
String name,
int maxLength)
Trim and check the length of a string. |
static String[] |
tokenize(String s,
String regexp,
boolean notInsideQuotes)
Tokenize a string by splitting it at positions matching the regular expression, optionally ignoring matches that are inside quotes. |
static String[] |
tokenize(String s,
String regexp,
boolean notInsideQuotes,
boolean removeQuotes)
Tokenize a string by splitting it at positions matching the regular expression. |
static String |
trimString(String s,
int length)
Trim a string to a maximum length. |
static String |
trimStringMiddle(String s,
int length)
Trim a string to a maximum length. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public StringUtil()
Method Detail |
---|
public static String setNullableString(String value, String name, int maxLength) throws StringTooLongException
value
- The string to checkname
- The name of the attribute to use if an exception is thrownmaxLength
- The maximum length of the string
StringTooLongException
- If the string is too longpublic static String setNotNullString(String value, String name, int maxLength) throws InvalidUseOfNullException, StringTooLongException
value
- The string to checkname
- The name of the attribute to use if an exception is thrownmaxLength
- The maximum length of the string
StringTooLongException
- If the string is too long
InvalidUseOfNullException
- If the string is nullpublic static boolean isEqualOrNull(String s1, String s2)
s1
- The first strings2
- The second string
public static boolean isEqualOrNull(String s1, String s2, boolean caseInsensitive)
s1
- The first strings2
- The second stringcaseInsensitive
- TRUE if the comparison should ignore case, FALSE
otherwise
public static final String join(Collection<?> values, String deliminator, boolean skipNull)
values
- The values to joindeliminator
- The deliminator between the valuesskipNull
- If null values should be skipper or not
public static final String trimString(String s, int length)
s
- The string to trimlength
- The maximum length of the string
public static final String trimStringMiddle(String s, int length)
s
- The string to trimlength
- The maximum length of the string
public static final String[] tokenize(String s, String regexp, boolean notInsideQuotes)
s
- The string to tokenizeregexp
- The regular expression for matching split sitesnotInsideQuotes
- If TRUE, the regexp is not matched inside quotes
public static final String[] tokenize(String s, String regexp, boolean notInsideQuotes, boolean removeQuotes)
s
- The string to tokenizeregexp
- The regular expression for matching split sitesnotInsideQuotes
- If TRUE, the regexp is not matched inside quotesremoveQuotes
- If TRUE, remove quotes from all elements before returning the
result
public static final String getCommonPrefix(Collection<String> strings)
strings
- A collection of string objects
String.startsWith(String)
returns true for all strings in the given collection
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |