Class Utils

java.lang.Object
org.metricshub.winrm.Utils

public class Utils extends Object
  • Field Details

  • Constructor Details

    • Utils

      public Utils()
  • 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
    • 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
    • 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
    • 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
    • getComputerName

      public static String getComputerName()
      Returns:
      the name of the local computer (or "localhost" if it can't be determined)
    • sleep

      public static void sleep(long millis) throws InterruptedException
      Wrapper for Thread.sleep(millis)
      Parameters:
      millis - Time to sleep (in milliseconds)
      Throws:
      InterruptedException
    • 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
    • getCurrentTimeMillis

      public static long getCurrentTimeMillis()
      Get the current time in Milliseconds.
      Returns:
      the current time in Milliseconds.
    • 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
    • execute

      public static <T> T execute(Callable<T> callable, long timeout) throws InterruptedException, ExecutionException, TimeoutException
      Run the given Callable using the passed timeout in seconds.
      Type Parameters:
      T -
      Parameters:
      callable -
      timeout -
      Returns:
      Utils result returned by the callable
      Throws:
      InterruptedException
      ExecutionException
      TimeoutException
    • 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