Class NumberParser


  • public class NumberParser
    extends java.lang.Object
    Utility class for parsing strings into numbers.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean parseBoolean​(@NotNull java.lang.String str)
      Parses a boolean constant.
      static <T extends java.lang.Enum<T>>
      T
      parseEnum​(@NotNull java.lang.Class<T> class_, @NotNull java.lang.String name, @NotNull java.lang.String ident)
      Parses an enum constant.
      static float parseFloat​(@NotNull java.lang.String str)
      Parses a float constant.
      static int parseInt​(@NotNull java.lang.String string, int defaultValue)
      Converts a string into an int value.
      static int parseInt​(@NotNull java.lang.String string, int defaultValue, int minValue, int maxValue)
      Converts a string into an int value in the given bounds.
      static long parseLong​(@NotNull java.lang.String string, long defaultValue)
      Converts a string into a long value.
      • Methods inherited from class java.lang.Object

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

      • parseInt

        public static int parseInt​(@NotNull
                                   @NotNull java.lang.String string,
                                   int defaultValue)
        Converts a string into an int value.
        Parameters:
        string - the string to convert
        defaultValue - the value to return if the number is not a string
        Returns:
        the int value
      • parseInt

        public static int parseInt​(@NotNull
                                   @NotNull java.lang.String string,
                                   int defaultValue,
                                   int minValue,
                                   int maxValue)
        Converts a string into an int value in the given bounds.
        Parameters:
        string - the string to convert
        defaultValue - the value to return if the number is not a string or not within bounds
        minValue - the bound's minimum value
        maxValue - the bound's maximum value
        Returns:
        the int value
      • parseLong

        public static long parseLong​(@NotNull
                                     @NotNull java.lang.String string,
                                     long defaultValue)
        Converts a string into a long value.
        Parameters:
        string - the string to convert
        defaultValue - the value to return if the number is not a string
        Returns:
        the long value
      • parseFloat

        public static float parseFloat​(@NotNull
                                       @NotNull java.lang.String str)
                                throws java.io.IOException
        Parses a float constant.
        Parameters:
        str - the floating constant string to parse
        Returns:
        the floating value
        Throws:
        java.io.IOException - if a parsing error occurs
      • parseBoolean

        public static boolean parseBoolean​(@NotNull
                                           @NotNull java.lang.String str)
                                    throws java.io.IOException
        Parses a boolean constant.
        Parameters:
        str - the boolean constant string to parse
        Returns:
        the boolean value
        Throws:
        java.io.IOException - if a parsing error occurs
      • parseEnum

        @NotNull
        public static <T extends java.lang.Enum<T>> T parseEnum​(@NotNull
                                                                @NotNull java.lang.Class<T> class_,
                                                                @NotNull
                                                                @NotNull java.lang.String name,
                                                                @NotNull
                                                                @NotNull java.lang.String ident)
                                                         throws java.io.IOException
        Parses an enum constant.
        Type Parameters:
        T - the enum class
        Parameters:
        class_ - the enum class the enum constant belongs to
        name - the enum constant to parse
        ident - the description of the enum class for building error messages
        Returns:
        the enum constant
        Throws:
        java.io.IOException - if the enum constant does not exist