Class Utils

java.lang.Object
org.metricshub.wmi.Utils

public class Utils extends Object
Utility Class (static), to be used anywhere in Matsya, including in standalone JARs (in CLI mode)
Author:
Bertrand
  • Field Details

  • Method Details

    • checkNonNull

      public static <T> void checkNonNull(T argument, String name)
      Check if the required argument is not null.
      Parameters:
      argument -
      name -
      Throws:
      IllegalArgumentException - if the argument is null
    • checkNonBlank

      public static void checkNonBlank(String argument, String name)
      Check if the required argument is not blank (null or empty).
      Parameters:
      argument -
      name -
      Throws:
      IllegalArgumentException - if the argument is null
    • checkArgumentNotZeroOrNegative

      public static void checkArgumentNotZeroOrNegative(long argument, String name)
      Check if the required argument is not negative or zero.
      Parameters:
      argument -
      name -
      Throws:
      IllegalArgumentException - if the argument is null
    • checkNonNullField

      public static <T> void checkNonNullField(T field, String name)
      Check if the required field is not null.
      Parameters:
      field -
      name -
      Throws:
      IllegalStateException - if the argument is null
    • convertCimDateTime

      public static OffsetDateTime convertCimDateTime(String stringValue)
      Convert a String holding a CIM_DATETIME (i.e. a string in the form of yyyymmddHHMMSS.mmmmmmsUUU) to an OffsetDateTime object
      Parameters:
      stringValue - String value with a CIM_DATETIME
      Returns:
      OffsetDateTime instance
    • getComputerName

      public static String 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

      public static boolean isBlank(String value)
      Parameters:
      value - The value to check
      Returns:
      whether the value is null, empty or contains only blank chars
    • isNotBlank

      public static boolean isNotBlank(String value)
      Parameters:
      value - The value to check
      Returns:
      whether the value is not null, nor empty nor contains only blank chars
    • isEmpty

      public static boolean isEmpty(String value)
      Parameters:
      value - The value to check
      Returns:
      whether the value is empty of non-blank chars
      Throws:
      NullPointerException - if value is null
    • readText

      public static String readText(Path filePath, Charset charset)
      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 rest
      charset - The encoding charset
      Returns:
      The content of the file, as a String, or empty string if file doesn't exist
    • sleep

      public static void sleep(long millis) throws InterruptedException
      Wrapper for Thread.sleep(millis)
      Parameters:
      millis - Time to sleep (in milliseconds)
      Throws:
      InterruptedException