Class Utils


  • public class Utils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.lang.Iterable<T> adaptForLoop​(java.util.Iterator<T> it)
      Adapts Iterator for Iterable.
      static void check​(java.lang.Class<?> klass, java.lang.String fieldName)  
      static void check​(java.lang.Class<?> klass, java.lang.String... fieldNames)  
      static java.lang.String[] concat​(java.lang.String[] t1, java.lang.String[] t2)  
      static java.util.Collection<java.lang.String> destroy​(java.lang.Process process)  
      static int figureOutHotCPUs()
      Warm up the CPU schedulers, bring all the CPUs online to get the reasonable estimate of the system capacity.
      static java.lang.String getCurrentJvm()  
      static java.lang.String getCurrentJvmVersion()  
      static java.lang.String getCurrentOSVersion()  
      static long getOffset​(java.lang.Class<?> klass, java.lang.String fieldName)  
      static long getPid()
      Gets PID of the current JVM.
      static java.util.Properties getRecordedSystemProperties()
      We don't access the complete system properties via System.getProperties() because this would require read/write permissions to the properties.
      static java.nio.charset.Charset guessConsoleEncoding()  
      static boolean isWindows()  
      static java.lang.String join​(java.lang.String[] src, java.lang.String delim)  
      static java.lang.String join​(java.util.Collection<java.lang.String> src, java.lang.String delim)  
      static java.util.regex.Pattern lazyCompile​(java.lang.String pattern)  
      static java.lang.String marshalIntArray​(int[] arr)  
      static <T extends java.lang.Comparable<T>>
      T
      max​(java.util.Collection<T> ts)  
      static <T extends java.lang.Comparable<T>>
      T
      min​(java.util.Collection<T> ts)  
      static java.util.Properties readPropertiesFromCommand​(java.util.List<java.lang.String> cmd)  
      static void reflow​(java.io.PrintWriter pw, java.lang.String src, int width, int indent)  
      static java.util.Collection<java.lang.String> rewrap​(java.lang.String lines)  
      static int roundUp​(int v, int quant)  
      static java.lang.Process runAsync​(java.lang.String... cmd)  
      static java.util.Collection<java.lang.String> runWith​(java.util.List<java.lang.String> cmd)  
      static java.util.Collection<java.lang.String> splitQuotedEscape​(java.lang.String src)  
      static int sum​(int[] arr)  
      static java.lang.String throwableToString​(java.lang.Throwable t)  
      static java.util.Collection<java.lang.String> tryWith​(java.lang.String... cmd)  
      static int[] unmarshalIntArray​(java.lang.String src)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • lazyCompile

        public static java.util.regex.Pattern lazyCompile​(java.lang.String pattern)
      • min

        public static <T extends java.lang.Comparable<T>> T min​(java.util.Collection<T> ts)
      • max

        public static <T extends java.lang.Comparable<T>> T max​(java.util.Collection<T> ts)
      • concat

        public static java.lang.String[] concat​(java.lang.String[] t1,
                                                java.lang.String[] t2)
      • join

        public static java.lang.String join​(java.util.Collection<java.lang.String> src,
                                            java.lang.String delim)
      • join

        public static java.lang.String join​(java.lang.String[] src,
                                            java.lang.String delim)
      • splitQuotedEscape

        public static java.util.Collection<java.lang.String> splitQuotedEscape​(java.lang.String src)
      • sum

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

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

        public static java.lang.String throwableToString​(java.lang.Throwable t)
      • unmarshalIntArray

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

        public static java.lang.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 java.nio.charset.Charset guessConsoleEncoding()
      • reflow

        public static void reflow​(java.io.PrintWriter pw,
                                  java.lang.String src,
                                  int width,
                                  int indent)
      • rewrap

        public static java.util.Collection<java.lang.String> rewrap​(java.lang.String lines)
      • check

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

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

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

        public static boolean isWindows()
      • getCurrentJvm

        public static java.lang.String getCurrentJvm()
      • getCurrentJvmVersion

        public static java.lang.String getCurrentJvmVersion()
      • getCurrentOSVersion

        public static java.lang.String getCurrentOSVersion()
      • getPid

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

        public static java.util.Collection<java.lang.String> tryWith​(java.lang.String... cmd)
      • runAsync

        public static java.lang.Process runAsync​(java.lang.String... cmd)
      • destroy

        public static java.util.Collection<java.lang.String> destroy​(java.lang.Process process)
      • runWith

        public static java.util.Collection<java.lang.String> runWith​(java.util.List<java.lang.String> cmd)
      • getRecordedSystemProperties

        public static java.util.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 java.util.Properties readPropertiesFromCommand​(java.util.List<java.lang.String> cmd)
      • adaptForLoop

        public static <T> java.lang.Iterable<T> adaptForLoop​(java.util.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