Class Utils


  • public class Utils
    extends Object
    • Method Detail

      • sum

        public static int sum​(int[] arr)
      • roundUp

        public static int roundUp​(int v,
                                  int quant)
      • throwableToString

        public static String throwableToString​(Throwable t)
      • unmarshalIntArray

        public static int[] unmarshalIntArray​(String src)
      • marshalIntArray

        public static String marshalIntArray​(int[] arr)
      • figureOutHotCPUs

        public static int figureOutHotCPUs()
        Warm up the CPU schedulers, bring all the CPUs online to get the reasonable estimate of the system capacity. Some systems, notably embedded Linuxes, power down the idle CPUs and so availableProcessors() may report lower CPU count than would be present after the load-up.
        Returns:
        max CPU count
      • guessConsoleEncoding

        public static Charset guessConsoleEncoding()
      • reflow

        public static void reflow​(PrintWriter pw,
                                  String src,
                                  int width,
                                  int indent)
      • check

        public static void check​(Class<?> klass,
                                 String... fieldNames)
      • check

        public static void check​(Class<?> klass,
                                 String fieldName)
      • getOffset

        public static long getOffset​(Class<?> klass,
                                     String fieldName)
      • isWindows

        public static boolean isWindows()
      • getCurrentJvm

        public static String getCurrentJvm()
      • getCurrentJvmVersion

        public static String getCurrentJvmVersion()
      • getCurrentOSVersion

        public static String getCurrentOSVersion()
      • getPid

        public static long getPid()
        Gets PID of the current JVM.
        Returns:
        PID.
      • getPid

        public static long getPid​(Process process)
        Gets the PID of the target process.
        Parameters:
        process - to poll
        Returns:
        PID, or zero if no PID is found
      • getRecordedSystemProperties

        public static Properties getRecordedSystemProperties()
        We don't access the complete system properties via System.getProperties() because this would require read/write permissions to the properties. Just copy the properties we want to record in the result.
        Returns:
        Copy of system properties we want to record in the results.
      • readPropertiesFromCommand

        public static Properties readPropertiesFromCommand​(List<String> cmd)
      • adaptForLoop

        public static <T> Iterable<T> adaptForLoop​(Iterator<T> it)
        Adapts Iterator for Iterable. Can be iterated only once!
        Type Parameters:
        T - element type
        Parameters:
        it - iterator
        Returns:
        iterable for given iterator