Package com.vividsolutions.jump.util
Class StringUtil
- java.lang.Object
-
- com.vividsolutions.jump.util.StringUtil
-
public class StringUtil extends Object
Useful String-related utilities.
-
-
Constructor Summary
Constructors Constructor Description StringUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<String>blankStringList(int size)Returns a List of empty Strings.static Stringcapitalize(String word)static StringclassNameWithoutPackageQualifiers(String className)static StringclassNameWithoutQualifiers(String className)static StringfillString(int len, char ch)static StringfriendlyName(Class c)static List<String>fromCommaDelimitedString(String s)Converts the comma-delimited string into a List of trimmed strings.static Stringhead(String s, int lines)static Stringies(int n)Warning: hinders internationalizationstatic StringinsertSpaces(String s)static booleanisEmpty(String value)static booleanisNumber(String token)static StringlimitLength(String s, int maxLength)static Stringrepeat(char c, int n)static voidreplace(StringBuffer orig, String o, String n, boolean all)Replaces all instances of the String o with the String n in the StringBuffer orig if all is true, or only the first instance if all is false.static Stringreplace(String original, String oldSubstring, String newSubstring, boolean all)Returns original with occurrences of oldSubstring replaced by newSubstring.static StringreplaceAll(String original, String oldSubstring, String newSubstring)Returns original with all occurrences of oldSubstring replaced by newSubstringstatic Strings(int n)Warning: hinders internationalizationstatic Stringsplit(String s, int n)Line-wraps s by inserting a newline instead of the first space after the nth column.static StringstackTrace(Throwable t)Returns an throwable's stack tracestatic Stringsubstitute(String string, Object[] substitutions)static StringtoCommaDelimitedString(Collection<?> c)Returns the elements of c separated by commas.static StringtoDelimitedString(Collection<?> c, String delimiter)static StringtoFriendlyName(String className)static StringtoFriendlyName(String className, String substringToRemove)static StringtoString(double d)format Doubles to a String representation, cutting zeroes from the decimal end the minimum number of decimals is one, hinting the decimal nature of this number the maximimum number of decimal is hardcoded 12 and will be rounded eg.static StringtoTimeString(long milliseconds)static Stringuncapitalize(String word)
-
-
-
Method Detail
-
s
public static String s(int n)
Warning: hinders internationalization
-
ies
public static String ies(int n)
Warning: hinders internationalization
-
classNameWithoutPackageQualifiers
public static String classNameWithoutPackageQualifiers(String className)
-
repeat
public static String repeat(char c, int n)
-
split
public static String split(String s, int n)
Line-wraps s by inserting a newline instead of the first space after the nth column. Word-wraps.
-
fromCommaDelimitedString
public static List<String> fromCommaDelimitedString(String s)
Converts the comma-delimited string into a List of trimmed strings.- Parameters:
s- a String with comma-delimited values- Returns:
- a List of the Strings that were delimited by commas
-
blankStringList
public static List<String> blankStringList(int size)
Returns a List of empty Strings.- Parameters:
size- the size of the List to create- Returns:
- a List of blank Strings
-
toCommaDelimitedString
public static String toCommaDelimitedString(Collection<?> c)
Returns the elements of c separated by commas. If c is empty, an empty String will be returned.- Parameters:
c- a Collection of objects to convert to Strings and delimit by commas- Returns:
- a String containing c's elements, delimited by commas
-
replaceAll
public static String replaceAll(String original, String oldSubstring, String newSubstring)
Returns original with all occurrences of oldSubstring replaced by newSubstring
-
replace
public static String replace(String original, String oldSubstring, String newSubstring, boolean all)
Returns original with occurrences of oldSubstring replaced by newSubstring. Set all to true to replace all occurrences, or false to replace the first occurrence only.
-
replace
public static void replace(StringBuffer orig, String o, String n, boolean all)
Replaces all instances of the String o with the String n in the StringBuffer orig if all is true, or only the first instance if all is false. Posted by Steve Chapelon UseNet
-
isNumber
public static boolean isNumber(String token)
-
toDelimitedString
public static String toDelimitedString(Collection<?> c, String delimiter)
-
toTimeString
public static String toTimeString(long milliseconds)
-
isEmpty
public static boolean isEmpty(String value)
-
fillString
public static String fillString(int len, char ch)
-
toString
public static String toString(double d)
format Doubles to a String representation, cutting zeroes from the decimal end the minimum number of decimals is one, hinting the decimal nature of this number the maximimum number of decimal is hardcoded 12 and will be rounded eg. 1234.000 -> "1234.0", 1234.5600 -> "1234.56"- Parameters:
d- double value to format- Returns:
- a formatted (rounded) string representation of the double
-
-