Class NumberUtils


  • public final class NumberUtils
    extends Object
    Utility methods for dealing with numbers
    Author:
    bas.rutten
    • Method Detail

      • bigDecimalToString

        public static String bigDecimalToString​(boolean currency,
                                                boolean percentage,
                                                boolean useGrouping,
                                                int precision,
                                                BigDecimal value,
                                                Locale locale,
                                                String currencySymbol)
        * Converts a BigDecimal value to a String
        Parameters:
        currency - whether the value represents a currency
        percentage - whether the value represents a percentage
        useGrouping - whether to use a thousand grouping
        value - the value
        currencySymbol - the currency symbol
        locale - the locale to use
        Returns:
      • format

        public static String format​(Object value)
        Formats a value
        Parameters:
        value - the value to format
        Returns:
      • doubleToString

        public static String doubleToString​(boolean currency,
                                            boolean percentage,
                                            boolean useGrouping,
                                            int precision,
                                            Double value,
                                            Locale locale,
                                            String currencySymbol)
        Converts a double to a String
        Parameters:
        currency - whether to include a currency symbol
        percentage - whether to include a percentage sign
        useGrouping - whether to use a thousands grouping separator
        precision - the desired precision
        value - the value to convert
        currencySymbol - the currency symbol to use
        locale - the locale to use
        Returns:
      • fractionalToString

        public static String fractionalToString​(boolean currency,
                                                boolean percentage,
                                                boolean useGrouping,
                                                int precision,
                                                Number value,
                                                Locale locale,
                                                String currencySymbol)
        Converts a fractional value to a String
        Parameters:
        currency - whether to include a currency symbol
        percentage - whether to include a percentage sign
        useGrouping - whether to use a thousands grouping separator
        precision - the desired precision
        value - the value to convert
        currencySymbol - the currency symbol to use
        locale - the locale to use
        Returns:
      • integerToString

        public static String integerToString​(boolean grouping,
                                             boolean percentage,
                                             Integer value,
                                             Locale locale)
        Converts an Integer to a String, using the Vaadin converters
        Parameters:
        grouping - indicates whether grouping separators must be used
        value - the value to convert
        locale - the locale
        Returns:
      • isDouble

        public static boolean isDouble​(Class<?> clazz)
        Checks whether a class is a double (either wrapper or primitive)
        Parameters:
        clazz -
        Returns:
      • isDouble

        public static boolean isDouble​(Object value)
        Checks if an object is a double (either wrapper or primitive)
        Parameters:
        value -
        Returns:
      • isFloat

        public static boolean isFloat​(Class<?> clazz)
        Checks if a class is a float (either wrapper or primitive)
        Parameters:
        clazz - the class to check
        Returns:
      • isInteger

        public static boolean isInteger​(Class<?> clazz)
        Checks if a class is an integer (either wrapper or primitive)
        Parameters:
        clazz - the class to check
        Returns:
      • isInteger

        public static boolean isInteger​(Object value)
        Checks if an object is an integer (either wrapper or primitive)
        Parameters:
        value - the value to check
        Returns:
      • isLong

        public static boolean isLong​(Class<?> clazz)
        Checks if a class is a long (either wrapper or primitive)
        Parameters:
        clazz - the class to check
        Returns:
      • isLong

        public static boolean isLong​(Object value)
        Checks if an object is a Long (either primitive or wrapper)
        Parameters:
        value - the value to check
        Returns:
      • isNumeric

        public static boolean isNumeric​(Class<?> clazz)
        Indicates whether a certain class is a numeric class (either a primitive or a wrapper that extends the Number class) that is supported by the framework
        Parameters:
        clazz -
        Returns:
      • longToString

        public static String longToString​(boolean grouping,
                                          boolean percentage,
                                          Long value,
                                          Locale locale)
        Converts an Long to a String, using the Vaadin converters
        Parameters:
        grouping - indicates whether grouping separators must be used
        value - the value to convert
        locale - the locale
        Returns:
      • numberToString

        public static <T> String numberToString​(AttributeModel am,
                                                T value,
                                                boolean grouping,
                                                Locale locale,
                                                String currencySymbol)
        Converts a number to a String
        Parameters:
        am - the attribute model of the attribute to convert
        value - the value to convert
        grouping -
        locale -
        currencySymbol -
        Returns: