public class CommonUtils extends Object
Constructor and Description |
---|
CommonUtils() |
Modifier and Type | Method and Description |
---|---|
static <T> T |
convertObjectToType(Object object,
Class<T> type)
Utility method to convert an object to a given type
|
static <T> T |
convertStringToType(String value,
Class<T> type)
Utility method to convert a String value to a given type
|
static String |
findPropOrEnv(String key,
String defaultValue) |
static String |
formattedTimeDiff(long startNanos,
long endNanos)
Utility method to format the difference between the given time values
|
static <T> boolean |
isObjectConvertibleToType(Object object,
Class<T> type)
Utility method to check if an Object can be converted to a given type
|
static <T> boolean |
isStringConvertibleToType(String value,
Class<T> type)
Utility method to check if a String value can be converted to a given type
|
static void |
registerMBean(Object mbeanInstance,
String objectName)
Utility method to register a MBean instance with given name
|
static void |
unregisterMBean(String objectName)
Utility method to unregister a MBean instance with given name
|
public static void registerMBean(Object mbeanInstance, String objectName)
mbeanInstance
- bean to be registeredobjectName
- bean namepublic static void unregisterMBean(String objectName)
objectName
- name of the bean to be unregisteredpublic static String formattedTimeDiff(long startNanos, long endNanos)
startNanos
- start time value in nanosecondsendNanos
- end time value in nanosecondsIllegalArgumentException
- if startNanos
value is larger than endNanos
valuepublic static <T> boolean isStringConvertibleToType(String value, Class<T> type)
T
- the expected converted typevalue
- String to be checked for convertibilitytype
- expected typepublic static <T> T convertStringToType(String value, Class<T> type)
T
- the type to which the given string value will be convertedvalue
- String to be convertedtype
- expected typetype
IllegalArgumentException
- if the String cannot be converted to the given typepublic static <T> boolean isObjectConvertibleToType(Object object, Class<T> type)
T
- the expected converted typeobject
- to be checked for convertibilitytype
- expected typepublic static <T> T convertObjectToType(Object object, Class<T> type)
T
- the type to which the given object will be convertedobject
- object to be convertedtype
- expected typetype
IllegalArgumentException
- if the object cannot be converted to the given typeCopyright © 2016–2019 AdroitLogic. All rights reserved.