Class Utils


  • public class Utils
    extends Object
    • Method Detail

      • checkNotNull

        public static <T> T checkNotNull​(T ref,
                                         String message)
      • getSystemPropertyOrEnvVar

        public static String getSystemPropertyOrEnvVar​(String systemPropertyName,
                                                       String envVarName,
                                                       String defaultValue)
      • convertSystemPropertyNameToEnvVar

        public static String convertSystemPropertyNameToEnvVar​(String systemPropertyName)
      • getSystemPropertyOrEnvVar

        public static String getSystemPropertyOrEnvVar​(String systemPropertyName,
                                                       String defaultValue)
      • getSystemPropertyOrEnvVar

        public static String getSystemPropertyOrEnvVar​(String systemPropertyName)
      • getSystemPropertyOrEnvVar

        public static boolean getSystemPropertyOrEnvVar​(String systemPropertyName,
                                                        Boolean defaultValue)
      • getSystemPropertyOrEnvVar

        public static int getSystemPropertyOrEnvVar​(String systemPropertyName,
                                                    int defaultValue)
      • join

        public static String join​(Object[] array,
                                  char separator)
      • waitUntilReady

        public static boolean waitUntilReady​(BlockingQueue<Object> queue,
                                             long amount,
                                             TimeUnit timeUnit)
        Wait until an other thread signals the completion of a task. If an exception is passed, it will be propagated to the caller.
        Parameters:
        queue - The communication channel.
        amount - The amount of time to wait.
        timeUnit - The time unit.
        Returns:
        a boolean value indicating resource is ready or not.
      • shutdownExecutorService

        public static boolean shutdownExecutorService​(ExecutorService executorService)
        Closes the specified ExecutorService.
        Parameters:
        executorService - The executorService.
        Returns:
        True if shutdown is complete.
      • closeQuietly

        public static void closeQuietly​(Closeable... closeables)
        Closes and flushes the specified Closeable items.
        Parameters:
        closeables - An array of Closeable items.
      • coalesce

        public static String coalesce​(String... items)
      • randomString

        public static String randomString​(int length)
      • randomString

        public static String randomString​(String prefix,
                                          int length)
      • filePath

        public static String filePath​(URL path)
      • replaceAllWithoutRegex

        public static String replaceAllWithoutRegex​(String text,
                                                    String from,
                                                    String to)
        Replaces all occurrences of the from text with to text without any regular expressions
        Parameters:
        text - text string
        from - from string
        to - to string
        Returns:
        returns processed string
      • isNullOrEmpty

        public static boolean isNullOrEmpty​(String str)
      • isNotNullOrEmpty

        public static boolean isNotNullOrEmpty​(Map map)
      • isNotNullOrEmpty

        public static boolean isNotNullOrEmpty​(String str)
      • isNotNullOrEmpty

        public static boolean isNotNullOrEmpty​(String[] array)
      • isNotNull

        public static <T> boolean isNotNull​(T... refList)
      • getNonNullOrElse

        public static <T> T getNonNullOrElse​(T obj,
                                             T defaultObj)
      • toUrlEncoded

        public static String toUrlEncoded​(String str)
        Converts string to URL encoded string.
        Parameters:
        str - Url as string
        Returns:
        returns encoded string
      • getPluralFromKind

        public static String getPluralFromKind​(String kind)
        todo: we should unify this with Pluralize
      • isResourceNamespaced

        public static boolean isResourceNamespaced​(Class kubernetesResourceType)
        Reads @Namespaced annotation in resource class to check whether resource is namespaced or not
        Parameters:
        kubernetesResourceType - class for resource
        Returns:
        boolean value indicating it's namespaced or not
      • getAnnotationValue

        public static String getAnnotationValue​(Class kubernetesResourceType,
                                                Class annotationClass)
      • interpolateString

        public static String interpolateString​(String templateInput,
                                               Map<String,​String> valuesMap)
        Interpolates a String containing variable placeholders with the values provided in the valuesMap.

        This method is intended to interpolate templates loaded from YAML and JSON files.

        Placeholders are indicated by the dollar sign and curly braces (${VARIABLE_KEY}).

        Placeholders can also be indicated by the dollar sign and double curly braces (${{VARIABLE_KEY}}), when this notation is used, the resulting value will be unquoted (if applicable), expected values should be JSON compatible.

        Parameters:
        valuesMap - to interpolate in the String
        templateInput - raw input containing a String with placeholders ready to be interpolated
        Returns:
        the interpolated String
        See Also:
        OpenShift Templates
      • isWindowsOperatingSystem

        public static boolean isWindowsOperatingSystem()
        Check whether platform is windows or not
        Returns:
        boolean value indicating whether OS is Windows or not.
      • getSystemPathVariable

        public static String getSystemPathVariable()
        Get system PATH variable
        Returns:
        a string containing value of PATH
      • getCommandPlatformPrefix

        public static List<String> getCommandPlatformPrefix()
        Returns prefixes needed to invoke specified command in a subprocess.
        Returns:
        a list of strings containing prefixes