Class Util


  • public class Util
    extends java.lang.Object
    Author:
    William Pugh
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static boolean LOGGING  
    • Constructor Summary

      Constructors 
      Constructor Description
      Util()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void closeSilently​(java.io.InputStream in)  
      static void closeSilently​(java.io.OutputStream out)  
      static void closeSilently​(java.io.Reader in)  
      static void closeSilently​(java.sql.Connection c)  
      static java.lang.String commonPrefix​(java.lang.String s1, java.lang.String s2)  
      static int compare​(int x, int y)
      return sign of x - y
      static int compare​(long x, long y)
      return sign of x - y
      static <T> java.util.Set<T> emptyOrNonnullSingleton​(T t)  
      static <E> E first​(java.lang.Iterable<E> i)  
      static java.lang.String getFileExtension​(java.io.File f)  
      static java.io.Reader getFileReader​(java.io.File filename)  
      static java.io.Reader getFileReader​(java.lang.String filename)  
      static java.io.Writer getFileWriter​(java.lang.String filename)  
      static java.io.Reader getReader​(java.io.InputStream in)  
      static java.io.Writer getWriter​(java.io.OutputStream out)  
      static java.lang.String getXMLType​(java.io.InputStream in)  
      static <K,​V>
      java.util.Map<K,​V>
      immutableMap​(java.util.Map<K,​V> map)  
      static java.io.IOException makeIOException​(java.lang.String msg, java.lang.Throwable cause)  
      static <T extends java.lang.Comparable<? super T>>
      int
      nullSafeCompareTo​(T o1, T o2)  
      static <T> boolean nullSafeEquals​(T o1, T o2)  
      static int nullSafeHashcode​(java.lang.Object o)  
      static java.lang.String repeat​(java.lang.String s, int number)  
      static void runLogAtShutdown​(java.lang.Runnable r)  
      static java.lang.Iterable<java.lang.Integer> setBitIteratable​(java.util.BitSet b)  
      static java.util.Iterator<java.lang.Integer> setBitIterator​(java.util.BitSet b)  
      static void throwIOException​(java.lang.String msg, java.lang.Throwable cause)  
      • Methods inherited from class java.lang.Object

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

      • LOGGING

        public static final boolean LOGGING
    • Constructor Detail

      • Util

        public Util()
    • Method Detail

      • compare

        public static int compare​(int x,
                                  int y)
        return sign of x - y
        Parameters:
        x -
        y -
        Returns:
      • compare

        public static int compare​(long x,
                                  long y)
        return sign of x - y
        Parameters:
        x -
        y -
        Returns:
      • setBitIteratable

        public static java.lang.Iterable<java.lang.Integer> setBitIteratable​(java.util.BitSet b)
      • setBitIterator

        public static java.util.Iterator<java.lang.Integer> setBitIterator​(java.util.BitSet b)
      • repeat

        public static java.lang.String repeat​(java.lang.String s,
                                              int number)
      • runLogAtShutdown

        public static void runLogAtShutdown​(java.lang.Runnable r)
      • emptyOrNonnullSingleton

        public static <T> java.util.Set<T> emptyOrNonnullSingleton​(T t)
      • immutableMap

        public static <K,​V> java.util.Map<K,​V> immutableMap​(java.util.Map<K,​V> map)
      • nullSafeHashcode

        public static int nullSafeHashcode​(@CheckForNull
                                           java.lang.Object o)
      • nullSafeCompareTo

        public static <T extends java.lang.Comparable<? super T>> int nullSafeCompareTo​(@CheckForNull
                                                                                        T o1,
                                                                                        @CheckForNull
                                                                                        T o2)
      • getReader

        public static java.io.Reader getReader​(@WillCloseWhenClosed
                                               java.io.InputStream in)
                                        throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
      • getFileReader

        public static java.io.Reader getFileReader​(java.lang.String filename)
                                            throws java.io.UnsupportedEncodingException,
                                                   java.io.FileNotFoundException
        Throws:
        java.io.UnsupportedEncodingException
        java.io.FileNotFoundException
      • getFileReader

        public static java.io.Reader getFileReader​(java.io.File filename)
                                            throws java.io.UnsupportedEncodingException,
                                                   java.io.FileNotFoundException
        Throws:
        java.io.UnsupportedEncodingException
        java.io.FileNotFoundException
      • getWriter

        public static java.io.Writer getWriter​(@WillCloseWhenClosed
                                               java.io.OutputStream out)
                                        throws java.io.UnsupportedEncodingException,
                                               java.io.FileNotFoundException
        Throws:
        java.io.UnsupportedEncodingException
        java.io.FileNotFoundException
      • getFileWriter

        public static java.io.Writer getFileWriter​(java.lang.String filename)
                                            throws java.io.UnsupportedEncodingException,
                                                   java.io.FileNotFoundException
        Throws:
        java.io.UnsupportedEncodingException
        java.io.FileNotFoundException
      • closeSilently

        public static void closeSilently​(@WillClose
                                         java.sql.Connection c)
      • closeSilently

        public static void closeSilently​(@WillClose
                                         java.io.InputStream in)
      • closeSilently

        public static void closeSilently​(@WillClose
                                         java.io.Reader in)
      • closeSilently

        public static void closeSilently​(@WillClose
                                         java.io.OutputStream out)
      • getXMLType

        public static java.lang.String getXMLType​(@WillNotClose
                                                  java.io.InputStream in)
                                           throws java.io.IOException
        Throws:
        java.io.IOException
      • makeIOException

        public static java.io.IOException makeIOException​(java.lang.String msg,
                                                          java.lang.Throwable cause)
      • getFileExtension

        public static java.lang.String getFileExtension​(java.io.File f)
      • throwIOException

        public static void throwIOException​(java.lang.String msg,
                                            java.lang.Throwable cause)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • first

        public static <E> E first​(java.lang.Iterable<E> i)
        Parameters:
        i - the Iterable whose first element is to be retrieved
        Returns:
        first element of iterable
      • commonPrefix

        public static java.lang.String commonPrefix​(java.lang.String s1,
                                                    java.lang.String s2)