Package org.metricshub.wmi
Class Utils
java.lang.Object
org.metricshub.wmi.Utils
Utility Class (static), to be used anywhere in Matsya, including in
standalone JARs (in CLI mode)
- Author:
- Bertrand
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckArgumentNotZeroOrNegative(long argument, String name) Check if the required argument is not negative or zero.static voidcheckNonBlank(String argument, String name) Check if the required argument is not blank (null or empty).static <T> voidcheckNonNull(T argument, String name) Check if the required argument is not null.static <T> voidcheckNonNullField(T field, String name) Check if the required field is not null.static OffsetDateTimeconvertCimDateTime(String stringValue) Convert a String holding a CIM_DATETIME (i.e. a string in the form ofyyyymmddHHMMSS.mmmmmmsUUU) to an OffsetDateTime objectstatic Stringstatic longGet the current time in Milliseconds.static booleanstatic booleanstatic booleanisNotBlank(String value) static StringRead the content of the specified file.static voidsleep(long millis) Wrapper for Thread.sleep(millis)
-
Field Details
-
EMPTY
- See Also:
-
NEW_LINE
- See Also:
-
DEFAULT_ARRAY_SEPARATOR
Default separator for array values- See Also:
-
DEFAULT_COLUMN_SEPARATOR
- See Also:
-
STATUS_SUCCESS
- See Also:
-
STATUS_ERROR
- See Also:
-
WBEM_CIM_DATETIME_FORMATTER
Formatter/Parser of the first part of CIM_DATETIME
-
-
Method Details
-
checkNonNull
Check if the required argument is not null.- Parameters:
argument-name-- Throws:
IllegalArgumentException- if the argument is null
-
checkNonBlank
Check if the required argument is not blank (null or empty).- Parameters:
argument-name-- Throws:
IllegalArgumentException- if the argument is null
-
checkArgumentNotZeroOrNegative
Check if the required argument is not negative or zero.- Parameters:
argument-name-- Throws:
IllegalArgumentException- if the argument is null
-
checkNonNullField
Check if the required field is not null.- Parameters:
field-name-- Throws:
IllegalStateException- if the argument is null
-
convertCimDateTime
Convert a String holding a CIM_DATETIME (i.e. a string in the form ofyyyymmddHHMMSS.mmmmmmsUUU) to an OffsetDateTime object- Parameters:
stringValue- String value with a CIM_DATETIME- Returns:
- OffsetDateTime instance
-
getComputerName
- Returns:
- the name of the local computer (or "localhost" if it can't be determined)
-
getCurrentTimeMillis
public static long getCurrentTimeMillis()Get the current time in Milliseconds.- Returns:
- the current time in Milliseconds.
-
isBlank
- Parameters:
value- The value to check- Returns:
- whether the value is null, empty or contains only blank chars
-
isNotBlank
- Parameters:
value- The value to check- Returns:
- whether the value is not null, nor empty nor contains only blank chars
-
isEmpty
- Parameters:
value- The value to check- Returns:
- whether the value is empty of non-blank chars
- Throws:
NullPointerException- if value is null
-
readText
Read the content of the specified file. End-of-lines are normalized as\n. Non-existent or non-readable files will simply return an empty string.- Parameters:
filePath- Path of the file to restcharset- The encoding charset- Returns:
- The content of the file, as a String, or empty string if file doesn't exist
-
sleep
Wrapper for Thread.sleep(millis)- Parameters:
millis- Time to sleep (in milliseconds)- Throws:
InterruptedException
-