|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objecterland.util.StringUtil
public class StringUtil
A helper class for various String and StringBuffer methods
Constructor Summary | |
---|---|
StringUtil()
|
Method Summary | |
---|---|
static void |
addFixLength(StringBuffer sb,
long number,
int length)
Converts a number to string with a specified length and append it to a StringBuffer, if the number is shorter than the specified length it will be filled out with 0 in the beginning |
static void |
addFixLength(StringBuffer sb,
String str,
int length,
boolean fillAtEnd)
Converts a String to a String with specified length and append it to a StringBuffer object, if the string is shorter you can choose if it should be filled with spaces in the end or in the beginning |
static Boolean |
asBoolean(String value,
Boolean defaultValue)
|
static Date |
asDate(String value,
Date defaultValue)
|
static Date |
asDate(String value,
Date defaultValue,
DateFormat format)
|
static Date |
asDate(String value,
Date defaultValue,
Locale locale)
|
static Double |
asDouble(String value,
Double defaultValue)
|
static String |
asEmpty(String str)
Returns "" if string is null |
static Float |
asFloat(String value,
Float defaultValue)
|
static Integer |
asInteger(String value,
Integer defaultValue)
|
static Long |
asLong(String value,
Long defaultValue)
|
static String |
asNull(String str)
Returns null if string is null or if String.trim().length()==0 |
static String |
asString(Boolean value,
String defaultValue)
|
static String |
asString(Date value,
String defaultValue)
|
static String |
asString(Date value,
String defaultValue,
DateFormat format)
|
static String |
asString(Date value,
String defaultValue,
Locale locale)
|
static String |
asString(Double value,
String defaultValue)
|
static String |
asString(Float value,
String defaultValue)
|
static String |
asString(Integer value,
String defaultValue)
|
static String |
asString(Long value,
String defaultValue)
|
static String |
beanToString(Object object,
String exclude,
Class excludeFrom,
boolean shortNames)
Generates a string with all properties of an object which has a getXXX or isXXX method In the case that the methods return a value that is not a String it will be converted to a String by using the toString() method of the object |
static String |
getFixLength(long number,
int length)
Converts a number to a String with specified length, if the number is shorter than the specified length it will be filled out with 0 in the beginning |
static String |
getFixLength(String str,
int length,
boolean fillAtEnd)
Converts a String to a String with specified length, if the string is shorter you can choose if it should be filled with spaces in the end or in the beginning |
static long |
getNumber(String str)
Converts a string to a number |
static long |
getNumber(StringBuffer sb)
Converts a string to a number |
static long |
getNumber(StringBuffer sb,
int beginIndex,
int endIndex)
Converts a sub string between a start and end position to a number |
static long |
getNumber(String str,
int beginIndex,
int endIndex)
Converts a sub string between a start and end position to a number |
static String |
objectToString(Object object,
String exclude,
Class excludeFrom,
boolean shortNames)
Generates a string with all attributes of an object In the case that the methods return a value that is not a String it will be converted to a String by using the toString() method of the object |
static StringBuffer |
replaceChar(StringBuffer sb,
char oldChar,
char newChar)
Replace all occurrances of a specifiec character in a StringBuffer with another character |
static StringBuffer |
trim(StringBuffer sb)
Removes space and newline characters in the beginning and end of a StringBuffer |
static String |
wordWrap(String str,
int width)
|
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 getFixLength(long number, int length)
number
- The number to convertlength
- The string length requested
public static void addFixLength(StringBuffer sb, long number, int length)
sb
- The StringBuffer to append the converted number tonumber
- The number to convertlength
- The string length requestedpublic static String getFixLength(String str, int length, boolean fillAtEnd)
str
- The string to convertlength
- The string length requestedfillAtEnd
- Indicates that the string should be filled at end. True = filled at end, False = filled at begining
public static void addFixLength(StringBuffer sb, String str, int length, boolean fillAtEnd)
sb
- The StringBuffer to append the string tostr
- The string to convertlength
- The string length requestedfillAtEnd
- Indicates that the string should be filled at end. True = filled at end, False = filled at beginingpublic static long getNumber(String str)
str
- The string containing the number
public static long getNumber(String str, int beginIndex, int endIndex)
str
- The string containg the numberbeginIndex
- The start position of the sub stringendIndex
- The end position of the sub string
public static long getNumber(StringBuffer sb)
sb
- The StringBuffer containing the number
public static long getNumber(StringBuffer sb, int beginIndex, int endIndex)
sb
- The StringBuffer containg the numberbeginIndex
- The start position of the sub stringendIndex
- The end position of the sub string
public static StringBuffer replaceChar(StringBuffer sb, char oldChar, char newChar)
sb
- The StringBuffer containing the stringoldChar
- The character to replacenewChar
- The new character to insert
public static StringBuffer trim(StringBuffer sb)
sb
- StringBuffer to trim
public static String asNull(String str)
str
- The string to check
public static String asEmpty(String str)
str
- The string to check
public static String beanToString(Object object, String exclude, Class excludeFrom, boolean shortNames)
object
- The object to printexclude
- A regular expression, if a getXXX or isXXX method matches this it will not be printedexcludeFrom
- If the getXXX or isXXX method is declared in this class or a subclass of this class it will not be printedshortNames
- Indicates that short class names should be used instead of full names which include the package
public static String objectToString(Object object, String exclude, Class excludeFrom, boolean shortNames)
object
- The object to printexclude
- A regular expression, if an attribute name matches this it will not be printedexcludeFrom
- If the attribute is declared in this class or a subclass of this class it will not be printedshortNames
- Indicates that short class names should be used instead of full names which include the package
public static Boolean asBoolean(String value, Boolean defaultValue)
public static Integer asInteger(String value, Integer defaultValue)
public static Long asLong(String value, Long defaultValue)
public static Double asDouble(String value, Double defaultValue)
public static Float asFloat(String value, Float defaultValue)
public static Date asDate(String value, Date defaultValue)
public static Date asDate(String value, Date defaultValue, Locale locale)
public static Date asDate(String value, Date defaultValue, DateFormat format)
public static String asString(Integer value, String defaultValue)
public static String asString(Long value, String defaultValue)
public static String asString(Boolean value, String defaultValue)
public static String asString(Float value, String defaultValue)
public static String asString(Double value, String defaultValue)
public static String asString(Date value, String defaultValue)
public static String asString(Date value, String defaultValue, Locale locale)
public static String asString(Date value, String defaultValue, DateFormat format)
public static String wordWrap(String str, int width)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |