public final class Utils extends Object
Modifier and Type | Field and Description |
---|---|
static String |
EMPTY_STRING |
static String |
HTTP |
static String |
HTTPS |
static String |
UTF_8 |
Modifier and Type | Method and Description |
---|---|
static void |
checkUrl(String pattern,
String url)
Check if the url matches the pattern.
|
static String |
followGoogleRedirectIfNeeded(String url)
If the provided url is a Google search redirect, then the actual url is extracted from the
url= query value and returned, otherwise the original url is returned. |
static String |
getBaseUrl(String url) |
static String |
getQueryValue(URL url,
String parameterName)
Get the value of a URL-query by name.
|
static String |
getStringResultFromRegexArray(String input,
Pattern[] regexes)
Find the result of an array of
Pattern s inside an input on the first group
(0 ). |
static String |
getStringResultFromRegexArray(String input,
Pattern[] regexes,
int group)
Find the result of an array of
Pattern s inside an input on a specific
group. |
static String |
getStringResultFromRegexArray(String input,
String[] regexes)
Find the result of an array of string regular expressions inside an input on the first
group (
0 ). |
static String |
getStringResultFromRegexArray(String input,
String[] regexes,
int group)
Find the result of an array of string regular expressions inside an input on a specific
group.
|
static boolean |
isBlank(String string) |
static boolean |
isHTTP(URL url) |
static boolean |
isNullOrEmpty(Collection<?> collection)
Checks if a collection is null or empty.
|
static <K,V> boolean |
isNullOrEmpty(Map<K,V> map)
Checks if a
map is null or empty. |
static boolean |
isNullOrEmpty(String str) |
static boolean |
isWhitespace(int c) |
static String |
join(CharSequence delimiter,
Iterable<? extends CharSequence> elements) |
static String |
join(String delimiter,
String mapJoin,
Map<? extends CharSequence,? extends CharSequence> elements) |
static long |
mixedNumberWordToLong(String numberWord)
Convert a mixed number word to a long.
|
static String |
nonEmptyAndNullJoin(CharSequence delimiter,
String[] elements)
Concatenate all non-null, non-empty and strings which are not equal to
"null" . |
static String |
removeMAndWWWFromUrl(String url) |
static String |
removeNonDigitCharacters(String toRemove)
Remove all non-digit characters from a string.
|
static String |
removeUTF8BOM(String s) |
static String |
replaceHttpWithHttps(String url) |
static URL |
stringToURL(String url)
Convert a string to a
URL object . |
public static final String HTTP
public static final String HTTPS
public static final String UTF_8
public static final String EMPTY_STRING
@Nonnull public static String removeNonDigitCharacters(@Nonnull String toRemove)
Examples:
toRemove
- string to remove non-digit charspublic static long mixedNumberWordToLong(String numberWord) throws NumberFormatException, ParsingException
Examples:
numberWord
- string to be converted to a longNumberFormatException
ParsingException
public static void checkUrl(String pattern, String url) throws ParsingException
pattern
- the pattern that will be used to check the urlurl
- the url to be testedParsingException
@Nullable public static String getQueryValue(@Nonnull URL url, String parameterName)
If an url-query is give multiple times, only the value of the first query is returned.
url
- the url to be usedparameterName
- the pattern that will be used to check the urlnull
if nothing
was found@Nonnull public static URL stringToURL(String url) throws MalformedURLException
URL object
.
Defaults to HTTP if no protocol is given.
url
- the string to be converted to a URL-ObjectURL object
containing the urlMalformedURLException
@Nonnull public static String getBaseUrl(String url) throws ParsingException
ParsingException
public static String followGoogleRedirectIfNeeded(String url)
url=
query value and returned, otherwise the original url is returned.url
- the url which can possibly be a Google search redirectpublic static boolean isNullOrEmpty(String str)
public static boolean isNullOrEmpty(Collection<?> collection)
This method can be also used for JsonArray
s.
collection
- the collection on which check if it's null or emptypublic static <K,V> boolean isNullOrEmpty(Map<K,V> map)
map
is null or empty.
This method can be also used for JsonObject
s.
public static boolean isWhitespace(int c)
public static boolean isBlank(String string)
@Nonnull public static String join(CharSequence delimiter, @Nonnull Iterable<? extends CharSequence> elements)
@Nonnull public static String join(String delimiter, String mapJoin, @Nonnull Map<? extends CharSequence,? extends CharSequence> elements)
@Nonnull public static String nonEmptyAndNullJoin(CharSequence delimiter, String[] elements)
"null"
.@Nonnull public static String getStringResultFromRegexArray(@Nonnull String input, @Nonnull String[] regexes) throws Parser.RegexException
0
).input
- the input on which using the regular expressionsregexes
- the string array of regular expressionsParser.RegexException
- if none of the patterns match the input@Nonnull public static String getStringResultFromRegexArray(@Nonnull String input, @Nonnull Pattern[] regexes) throws Parser.RegexException
Pattern
s inside an input on the first group
(0
).input
- the input on which using the regular expressionsregexes
- the Pattern
arrayParser.RegexException
- if none of the patterns match the input@Nonnull public static String getStringResultFromRegexArray(@Nonnull String input, @Nonnull String[] regexes, int group) throws Parser.RegexException
input
- the input on which using the regular expressionsregexes
- the string array of regular expressionsgroup
- the group to matchParser.RegexException
- if none of the patterns match the input, or at least in the
specified group@Nonnull public static String getStringResultFromRegexArray(@Nonnull String input, @Nonnull Pattern[] regexes, int group) throws Parser.RegexException
Pattern
s inside an input on a specific
group.input
- the input on which using the regular expressionsregexes
- the Pattern
arraygroup
- the group to matchParser.RegexException
- if none of the patterns match the input, or at least in the
specified group