Class NumberInput


  • public final class NumberInput
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String NASTY_SMALL_DOUBLE
      Textual representation of a double constant that can cause nasty problems with JDK (see http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308).
    • Constructor Summary

      Constructors 
      Constructor Description
      NumberInput()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean inLongRange​(char[] digitChars, int offset, int len, boolean negative)
      Helper method for determining if given String representation of an integral number would fit in 64-bit Java long or not.
      static boolean inLongRange​(java.lang.String numberStr, boolean negative)
      Similar to inLongRange(char[],int,int,boolean), but with String argument
      static double parseAsDouble​(java.lang.String input, double defaultValue)  
      static int parseAsInt​(java.lang.String input, int defaultValue)  
      static long parseAsLong​(java.lang.String input, long defaultValue)  
      static double parseDouble​(java.lang.String numStr)  
      static int parseInt​(char[] digitChars, int offset, int len)
      Fast method for parsing integers that are known to fit into regular 32-bit signed int type.
      static int parseInt​(java.lang.String str)
      Helper method to (more) efficiently parse integer numbers from String values.
      static long parseLong​(char[] digitChars, int offset, int len)  
      static long parseLong​(java.lang.String str)  
      • Methods inherited from class java.lang.Object

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

      • NASTY_SMALL_DOUBLE

        public static final java.lang.String NASTY_SMALL_DOUBLE
        Textual representation of a double constant that can cause nasty problems with JDK (see http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308).
        See Also:
        Constant Field Values
    • Constructor Detail

      • NumberInput

        public NumberInput()
    • Method Detail

      • parseInt

        public static final int parseInt​(char[] digitChars,
                                         int offset,
                                         int len)
        Fast method for parsing integers that are known to fit into regular 32-bit signed int type. This means that length is between 1 and 9 digits (inclusive)

        Note: public to let unit tests call it

      • parseInt

        public static final int parseInt​(java.lang.String str)
        Helper method to (more) efficiently parse integer numbers from String values.
        Since:
        1.7
      • parseLong

        public static final long parseLong​(char[] digitChars,
                                           int offset,
                                           int len)
      • parseLong

        public static final long parseLong​(java.lang.String str)
      • inLongRange

        public static final boolean inLongRange​(char[] digitChars,
                                                int offset,
                                                int len,
                                                boolean negative)
        Helper method for determining if given String representation of an integral number would fit in 64-bit Java long or not. Note that input String must NOT contain leading minus sign (even if 'negative' is set to true).
        Parameters:
        negative - Whether original number had a minus sign (which is NOT passed to this method) or not
      • inLongRange

        public static final boolean inLongRange​(java.lang.String numberStr,
                                                boolean negative)
        Similar to inLongRange(char[],int,int,boolean), but with String argument
        Parameters:
        negative - Whether original number had a minus sign (which is NOT passed to this method) or not
        Since:
        1.5.0
      • parseAsInt

        public static int parseAsInt​(java.lang.String input,
                                     int defaultValue)
        Since:
        1.6
      • parseAsLong

        public static long parseAsLong​(java.lang.String input,
                                       long defaultValue)
        Since:
        1.6
      • parseAsDouble

        public static double parseAsDouble​(java.lang.String input,
                                           double defaultValue)
        Since:
        1.6
      • parseDouble

        public static final double parseDouble​(java.lang.String numStr)
                                        throws java.lang.NumberFormatException
        Throws:
        java.lang.NumberFormatException
        Since:
        1.8