Class Utils


  • public final class Utils
    extends Object
    Collection of utilities for general java related tasks.
    • Method Detail

      • getJavaVersion

        public static int getJavaVersion()
        Get the current version of Java running in this JVM.
        Returns:
        the java version number
      • currentTimeNanos

        public static long[] currentTimeNanos()
        Get the current time in mills and nanoseconds from epoch

        Long will wrap when the date exceeds Saturday, 12 April 2262 00:47:16.854 GMT+01:00 DST

        Returns:
        the epoch time in mills and nanos
      • newMap

        public static <T> Map<String,​T> newMap​(Map<String,​T> map)
        Create a new map from the input.
        Type Parameters:
        T - the key type
        Parameters:
        map - the input map
        Returns:
        a new map with the same values are the input, or a new empty map
      • endsWithIgnoreCase

        public static boolean endsWithIgnoreCase​(String str,
                                                 String suffix)
        Check if a string ends with a value, ignoring the case.
        Parameters:
        str - the string to search
        suffix - the value to serch for
        Returns:
        true if str ends with suffix, disregarding case sensitivity
        See Also:
        Source
      • valueOf

        public static String valueOf​(Object obj)
        This will create a string representation of the object passed in.
        Parameters:
        obj - the value to create a string from
        Returns:
        the string form of the object
      • trimPrefix

        public static String trimPrefix​(String str,
                                        String prefix)
        Trim a string from another string.
        Parameters:
        str - the target string
        prefix - the value to remove from the string
        Returns:
        the new string
      • truncate

        public static Utils.ITrimResult truncate​(String str,
                                                 int maxLength)
        Trim a string to a specified length.
        Parameters:
        str - the target string
        maxLength - the max length to make the string
        Returns:
        a Utils.ITrimResult, so we can know if the string was trimmed
      • throwableToString

        public static String throwableToString​(Throwable t)
        Convert a throwable into a loggable string.
        Parameters:
        t - the throwable to convert
        Returns:
        the string to log