public final class Util extends Object
Modifier and Type | Method and Description |
---|---|
static void |
closeQuietly(Closeable closeable)
Closes an instance of Closeable and suppress all possible raised Exceptions.
|
static boolean |
equals(Object a,
Object b)
Returns
true if the arguments are equal to each other
and false otherwise. |
static boolean |
isNullOrEmpty(String string)
Returns
true if the given string is null or is the empty string. |
static Double |
parseDouble(String value,
Double defaultValue)
Parses the provided string value into a double value.
|
static Map<String,String> |
parseExtra(String extrasString)
Parses the provided extras string into a Map of String -> String.
|
static Set<String> |
parseExtraTags(String extraTagsString)
Deprecated.
prefer
parseMdcTags(String) |
static Integer |
parseInteger(String value,
Integer defaultValue)
Parses the provided string value into an integer value.
|
static Long |
parseLong(String value,
Long defaultValue)
Parses the provided string value into a long value.
|
static Set<String> |
parseMdcTags(String mdcTagsString)
Parses the provided Strings into a Set of Strings.
|
static Map<String,String> |
parseTags(String tagsString)
Parses the provided tags string into a Map of String -> String.
|
static boolean |
safelyRemoveShutdownHook(Thread shutDownHook)
Try to remove the shutDownHook, handling the case where the VM is in shutdown process.
|
static String |
trimString(String string,
int maxMessageLength)
Trims a String, ensuring that the maximum length isn't reached.
|
public static boolean equals(Object a, Object b)
true
if the arguments are equal to each other
and false
otherwise.
Consequently, if both arguments are null
, true
is returned and if exactly one argument is null
, false
is returned. Otherwise, equality is determined by using
the equals
method of the first
argument.a
- an objectb
- an object to be compared with a
for equalitytrue
if the arguments are equal to each other
and false
otherwiseObject.equals(Object)
public static boolean isNullOrEmpty(String string)
true
if the given string is null or is the empty string.string
- a string reference to checktrue
if the string is null or is the empty stringpublic static Map<String,String> parseTags(String tagsString)
tagsString
- comma-delimited key-value pairs, e.g. "tag1:value1,tag2:value2".public static Map<String,String> parseExtra(String extrasString)
extrasString
- comma-delimited key-value pairs, e.g. "extra1:value1,extra2:value2".@Deprecated public static Set<String> parseExtraTags(String extraTagsString)
parseMdcTags(String)
extraTagsString
- comma-delimited tagspublic static Set<String> parseMdcTags(String mdcTagsString)
mdcTagsString
- comma-delimited tagspublic static Integer parseInteger(String value, Integer defaultValue)
If the string is null or empty this returns the default value.
value
- value to parsedefaultValue
- default valuepublic static Long parseLong(String value, Long defaultValue)
If the string is null or empty this returns the default value.
value
- value to parsedefaultValue
- default valuepublic static Double parseDouble(String value, Double defaultValue)
If the string is null or empty this returns the default value.
value
- value to parsedefaultValue
- default valuepublic static String trimString(String string, int maxMessageLength)
string
- string to trimmaxMessageLength
- maximum length of the stringpublic static boolean safelyRemoveShutdownHook(Thread shutDownHook)
shutDownHook
- the shutDownHook to removepublic static void closeQuietly(Closeable closeable)
closeable
- an instance that needs to be closed. null value is supported.Copyright © 2012–2020. All rights reserved.