Package com.ocs.dynamo.utils
Class NumberUtils
- java.lang.Object
-
- com.ocs.dynamo.utils.NumberUtils
-
public final class NumberUtils extends Object
Utility methods for dealing with numbers- Author:
- bas.rutten
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringbigDecimalToString(boolean currency, boolean percentage, boolean useGrouping, int precision, BigDecimal value, Locale locale, String currencySymbol)* Converts a BigDecimal value to a Stringstatic StringdoubleToString(boolean currency, boolean percentage, boolean useGrouping, int precision, Double value, Locale locale, String currencySymbol)Converts a double to a Stringstatic Stringformat(Object value)Formats a valuestatic StringfractionalToString(boolean currency, boolean percentage, boolean useGrouping, int precision, Number value, Locale locale, String currencySymbol)Converts a fractional value to a Stringstatic StringintegerToString(boolean grouping, boolean percentage, Integer value, Locale locale)Converts an Integer to a String, using the Vaadin convertersstatic booleanisDouble(Class<?> clazz)Checks whether a class is a double (either wrapper or primitive)static booleanisDouble(Object value)Checks if an object is a double (either wrapper or primitive)static booleanisFloat(Class<?> clazz)Checks if a class is a float (either wrapper or primitive)static booleanisInteger(Class<?> clazz)Checks if a class is an integer (either wrapper or primitive)static booleanisInteger(Object value)Checks if an object is an integer (either wrapper or primitive)static booleanisLong(Class<?> clazz)Checks if a class is a long (either wrapper or primitive)static booleanisLong(Object value)Checks if an object is a Long (either primitive or wrapper)static booleanisNumeric(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 frameworkstatic StringlongToString(boolean grouping, boolean percentage, Long value, Locale locale)Converts an Long to a String, using the Vaadin convertersstatic <T> StringnumberToString(AttributeModel am, T value, boolean grouping, Locale locale, String currencySymbol)Converts a number to a String
-
-
-
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 currencypercentage- whether the value represents a percentageuseGrouping- whether to use a thousand groupingvalue- the valuecurrencySymbol- the currency symbollocale- 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 symbolpercentage- whether to include a percentage signuseGrouping- whether to use a thousands grouping separatorprecision- the desired precisionvalue- the value to convertcurrencySymbol- the currency symbol to uselocale- 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 symbolpercentage- whether to include a percentage signuseGrouping- whether to use a thousands grouping separatorprecision- the desired precisionvalue- the value to convertcurrencySymbol- the currency symbol to uselocale- 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 usedvalue- the value to convertlocale- 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 usedvalue- the value to convertlocale- 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 convertvalue- the value to convertgrouping-locale-currencySymbol-- Returns:
-
-