public final class StringUtil extends Object
Modifier and Type | Field and Description |
---|---|
private static int |
MaxCachedBuilderSize |
(package private) static String[] |
padding |
private static ThreadLocal<StringBuilder> |
stringLocal |
Constructor and Description |
---|
StringUtil() |
Modifier and Type | Method and Description |
---|---|
static void |
appendNormalisedWhitespace(StringBuilder accum,
String string,
boolean stripLeading)
After normalizing the whitespace within a string, appends it to a string builder.
|
static boolean |
in(String needle,
String... haystack) |
static boolean |
inSorted(String needle,
String[] haystack) |
static boolean |
isActuallyWhitespace(int c)
Tests if a code point is "whitespace" as defined by what it looks like.
|
static boolean |
isBlank(String string)
Tests if a string is blank: null, empty, or only whitespace (" ", \r\n, \t, etc)
|
static boolean |
isNumeric(String string)
Tests if a string is numeric, i.e. contains only digit characters
|
static boolean |
isWhitespace(int c)
Tests if a code point is "whitespace" as defined in the HTML spec.
|
static String |
join(Collection strings,
String sep)
Join a collection of strings by a separator
|
static String |
join(Iterator strings,
String sep)
Join a collection of strings by a separator
|
static String |
join(String[] strings,
String sep)
Join an array of strings by a separator
|
static String |
normaliseWhitespace(String string)
Normalise the whitespace within this string; multiple spaces collapse to a single, and all whitespace characters
(e.g. newline, tab) convert to a simple space
|
static String |
padding(int width)
Returns space padding
|
static String |
resolve(String baseUrl,
String relUrl)
Create a new absolute URL, from a provided existing absolute URL and a relative URL component.
|
static URL |
resolve(URL base,
String relUrl)
Create a new absolute URL, from a provided existing absolute URL and a relative URL component.
|
static StringBuilder |
stringBuilder()
Maintains a cached StringBuilder, to minimize new StringBuilder GCs.
|
private static final int MaxCachedBuilderSize
private static final ThreadLocal<StringBuilder> stringLocal
public StringUtil()
public static String join(Collection strings, String sep)
strings
- collection of string objectssep
- string to place between stringspublic static String join(Iterator strings, String sep)
strings
- iterator of string objectssep
- string to place between stringspublic static String join(String[] strings, String sep)
strings
- collection of string objectssep
- string to place between stringspublic static String padding(int width)
width
- amount of padding desiredpublic static boolean isBlank(String string)
string
- string to testpublic static boolean isNumeric(String string)
string
- string to testpublic static boolean isWhitespace(int c)
c
- code point to testisActuallyWhitespace(int)
public static boolean isActuallyWhitespace(int c)
c
- code point to testpublic static String normaliseWhitespace(String string)
string
- content to normalisepublic static void appendNormalisedWhitespace(StringBuilder accum, String string, boolean stripLeading)
accum
- builder to append tostring
- string to normalize whitespace withinstripLeading
- set to true if you wish to remove any leading whitespacepublic static URL resolve(URL base, String relUrl) throws MalformedURLException
base
- the existing absolute base URLrelUrl
- the relative URL to resolve. (If it's already absolute, it will be returned)MalformedURLException
- if an error occurred generating the URLpublic static String resolve(String baseUrl, String relUrl)
baseUrl
- the existing absolute base URLrelUrl
- the relative URL to resolve. (If it's already absolute, it will be returned)public static StringBuilder stringBuilder()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses