Package org.locationtech.jtstest.util
Class StringUtil
- java.lang.Object
-
- org.locationtech.jtstest.util.StringUtil
-
public class StringUtil extends Object
Useful string utilities- Version:
- 1.7
- Author:
- jaquino
-
-
Constructor Summary
Constructors Constructor Description StringUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringcapitalize(String s)Capitalizes the given string.static booleancontains(String string, String substring)Returns true if substring is indeed a substring of string.static booleancontainsIgnoreCase(String string, String substring)Returns true if substring is indeed a substring of string.static StringcurrentMethodName()static StringescapeHTML(String s)static Stringformat(double d, int decimals)Returns d as a string truncated to the specified number of decimal placesstatic ListfromCommaDelimitedString(String s)Converts the comma-delimited string into a List of trimmed strings.static StringgetStackTrace(Throwable t)Returns an throwable's stack tracestatic StringgetStackTrace(Throwable t, int depth)static StringgetTimeString(long milliseconds)Converts the milliseconds value into a String of the form "9d 22h 15m 8s".static Stringindent(String original, int spaces)static intindexOfIgnoreParentheses(char c, String s, int start)Returns the position of the first occurrence of the given character found in s starting at start.static booleanisInteger(String s)Returns true if s can be converted to an int.static StringleftPad(String original, int length, char padChar)Pads the String with the given character until it has the given length.static StringremoveConsecutiveDuplicates(String s)Replaces consecutive instances of characters with single instances.static StringremoveFromEnd(String s, String strToRemove)static StringremoveVowels(String s)Removes vowels from the string.static StringremoveVowelsSkipStarts(String s)Removes vowels from the string except those that start words.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 str, char oldChar, String newStr)Returns a string with all occurrences of oldChar replaced by newStrstatic 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 StringreplaceFirst(String original, String oldSubstring, String newSubstring)Returns original with the first occurrenc of oldSubstring replaced by newSubstringstatic StringrightPad(String original, int length, char padChar)Pads the String with the given character until it has the given length.static StringstringOfChar(char ch, int count)Returns a String of the given length consisting entirely of the given characterstatic StringstripHTMLTags(String original)Removes the HTML tags from the given String, inserting line breaks at appropriate places.static StringtoCommaDelimitedString(Collection c)Returns the elements of c separated by commas. c must not be empty.static StringtoCommaDelimitedStringInQuotes(Collection c)Returns the elements of c separated by commas and enclosed in single-quotesstatic VectortoLowerCase(List v)Returns the elements of v in lowercasestatic StringtoStringNeverNull(Object o)If s is null, returns "null"; otherwise, returns s.static VectortoUpperCase(Vector v)Returns the elements of v in uppercasestatic Stringwrap(String s, int n)Line-wraps a string s by inserting CR-LF instead of the first space after the nth columns.
-
-
-
Field Detail
-
newLine
public static final String newLine
-
-
Method Detail
-
capitalize
public static String capitalize(String s)
Capitalizes the given string.- Parameters:
s- the string to capitalize- Returns:
- the capitalized string
-
isInteger
public static boolean isInteger(String s)
Returns true if s can be converted to an int.
-
getTimeString
public static String getTimeString(long milliseconds)
Converts the milliseconds value into a String of the form "9d 22h 15m 8s".
-
containsIgnoreCase
public static boolean containsIgnoreCase(String string, String substring)
Returns true if substring is indeed a substring of string. Case-insensitive.
-
contains
public static boolean contains(String string, String substring)
Returns true if substring is indeed a substring of string.
-
replace
public static String replace(String str, char oldChar, String newStr)
Returns a string with all occurrences of oldChar replaced by newStr
-
stringOfChar
public static String stringOfChar(char ch, int count)
Returns a String of the given length consisting entirely of the given character
-
toCommaDelimitedStringInQuotes
public static String toCommaDelimitedStringInQuotes(Collection c)
Returns the elements of c separated by commas and enclosed in single-quotes
-
toCommaDelimitedString
public static String toCommaDelimitedString(Collection c)
Returns the elements of c separated by commas. c must not be empty.
-
fromCommaDelimitedString
public static List fromCommaDelimitedString(String s)
Converts the comma-delimited string into a List of trimmed strings.
-
toStringNeverNull
public static String toStringNeverNull(Object o)
If s is null, returns "null"; otherwise, returns s.
-
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
-
replaceAll
public static String replaceAll(String original, String oldSubstring, String newSubstring)
Returns original with all occurrences of oldSubstring replaced by newSubstring
-
replaceFirst
public static String replaceFirst(String original, String oldSubstring, String newSubstring)
Returns original with the first occurrenc of oldSubstring replaced by newSubstring
-
leftPad
public static String leftPad(String original, int length, char padChar)
Pads the String with the given character until it has the given length. If original is longer than the given length, returns original.
-
rightPad
public static String rightPad(String original, int length, char padChar)
Pads the String with the given character until it has the given length. If original is longer than the given length, returns original.
-
stripHTMLTags
public static String stripHTMLTags(String original)
Removes the HTML tags from the given String, inserting line breaks at appropriate places. Needs a little work.
-
format
public static String format(double d, int decimals)
Returns d as a string truncated to the specified number of decimal places
-
wrap
public static String wrap(String s, int n)
Line-wraps a string s by inserting CR-LF instead of the first space after the nth columns.
-
removeVowels
public static String removeVowels(String s)
Removes vowels from the string. Case-insensitive.
-
removeVowelsSkipStarts
public static String removeVowelsSkipStarts(String s)
Removes vowels from the string except those that start words. Case-insensitive.
-
removeConsecutiveDuplicates
public static String removeConsecutiveDuplicates(String s)
Replaces consecutive instances of characters with single instances. Case-insensitive.
-
indexOfIgnoreParentheses
public static int indexOfIgnoreParentheses(char c, String s, int start)Returns the position of the first occurrence of the given character found in s starting at start. Ignores text within pairs of parentheses. Returns -1 if no occurrence is found.
-
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.
-
currentMethodName
public static String currentMethodName()
-
-