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 String
capitalize(String s)
Capitalizes the given string.static boolean
contains(String string, String substring)
Returns true if substring is indeed a substring of string.static boolean
containsIgnoreCase(String string, String substring)
Returns true if substring is indeed a substring of string.static String
currentMethodName()
static String
escapeHTML(String s)
static String
format(double d, int decimals)
Returns d as a string truncated to the specified number of decimal placesstatic List
fromCommaDelimitedString(String s)
Converts the comma-delimited string into a List of trimmed strings.static String
getStackTrace(Throwable t)
Returns an throwable's stack tracestatic String
getStackTrace(Throwable t, int depth)
static String
getTimeString(long milliseconds)
Converts the milliseconds value into a String of the form "9d 22h 15m 8s".static String
indent(String original, int spaces)
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.static boolean
isInteger(String s)
Returns true if s can be converted to an int.static String
leftPad(String original, int length, char padChar)
Pads the String with the given character until it has the given length.static String
removeConsecutiveDuplicates(String s)
Replaces consecutive instances of characters with single instances.static String
removeFromEnd(String s, String strToRemove)
static String
removeVowels(String s)
Removes vowels from the string.static String
removeVowelsSkipStarts(String s)
Removes vowels from the string except those that start words.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.static String
replace(String str, char oldChar, String newStr)
Returns a string with all occurrences of oldChar replaced by newStrstatic String
replace(String original, String oldSubstring, String newSubstring, boolean all)
Returns original with occurrences of oldSubstring replaced by newSubstring.static String
replaceAll(String original, String oldSubstring, String newSubstring)
Returns original with all occurrences of oldSubstring replaced by newSubstringstatic String
replaceFirst(String original, String oldSubstring, String newSubstring)
Returns original with the first occurrenc of oldSubstring replaced by newSubstringstatic String
rightPad(String original, int length, char padChar)
Pads the String with the given character until it has the given length.static String
stringOfChar(char ch, int count)
Returns a String of the given length consisting entirely of the given characterstatic String
stripHTMLTags(String original)
Removes the HTML tags from the given String, inserting line breaks at appropriate places.static String
toCommaDelimitedString(Collection c)
Returns the elements of c separated by commas. c must not be empty.static String
toCommaDelimitedStringInQuotes(Collection c)
Returns the elements of c separated by commas and enclosed in single-quotesstatic Vector
toLowerCase(List v)
Returns the elements of v in lowercasestatic String
toStringNeverNull(Object o)
If s is null, returns "null"; otherwise, returns s.static Vector
toUpperCase(Vector v)
Returns the elements of v in uppercasestatic String
wrap(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()
-
-