List of usage examples for java.lang Number doubleValue
public abstract double doubleValue();
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.tree.NumberArithmetic.java
/** * Returns the sign of the number.//from w w w .ja v a2 s. c o m * * @param a the number * @return the sign of the number * @see Long#signum(long) * @see Math#signum(double) */ public static Number sign(Number a) { if (isFloatingPoint(a)) { return Math.signum(a.doubleValue()); } else { return Long.signum(a.longValue()); } }
From source file:com.jeeframework.util.validate.GenericTypeValidator.java
/** * Checks if the value can safely be converted to a float primitive. * *@param value The value validation is being performed on. *@param locale The locale to use to parse the number (system default if * null)/* w w w . j av a2 s . co m*/ *@return the converted Float value. */ public static Float formatFloat(String value, Locale locale) { Float result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getInstance(locale); } else { formatter = NumberFormat.getInstance(Locale.getDefault()); } ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= (Float.MAX_VALUE * -1) && num.doubleValue() <= Float.MAX_VALUE) { result = new Float(num.floatValue()); } } } return result; }
From source file:com.jeeframework.util.validate.GenericTypeValidator.java
/** * Checks if the value can safely be converted to a double primitive. * *@param value The value validation is being performed on. *@param locale The locale to use to parse the number (system default if * null)//from w ww . j ava 2s . co m *@return the converted Double value. */ public static Double formatDouble(String value, Locale locale) { Double result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getInstance(locale); } else { formatter = NumberFormat.getInstance(Locale.getDefault()); } ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= (Double.MAX_VALUE * -1) && num.doubleValue() <= Double.MAX_VALUE) { result = new Double(num.doubleValue()); } } } return result; }
From source file:com.jeeframework.util.validate.GenericTypeValidator.java
/** * Checks if the value can safely be converted to a byte primitive. * *@param value The value validation is being performed on. *@param locale The locale to use to parse the number (system default if * null)//from w w w. ja va 2s . c o m *@return the converted Byte value. */ public static Byte formatByte(String value, Locale locale) { Byte result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getNumberInstance(locale); } else { formatter = NumberFormat.getNumberInstance(Locale.getDefault()); } formatter.setParseIntegerOnly(true); ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= Byte.MIN_VALUE && num.doubleValue() <= Byte.MAX_VALUE) { result = new Byte(num.byteValue()); } } } return result; }
From source file:com.jeeframework.util.validate.GenericTypeValidator.java
/** * Checks if the value can safely be converted to a short primitive. * *@param value The value validation is being performed on. *@param locale The locale to use to parse the number (system default if * null)vv/* w w w. j ava 2 s . co m*/ *@return the converted Short value. */ public static Short formatShort(String value, Locale locale) { Short result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getNumberInstance(locale); } else { formatter = NumberFormat.getNumberInstance(Locale.getDefault()); } formatter.setParseIntegerOnly(true); ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= Short.MIN_VALUE && num.doubleValue() <= Short.MAX_VALUE) { result = new Short(num.shortValue()); } } } return result; }
From source file:com.jeeframework.util.validate.GenericTypeValidator.java
/** * Checks if the value can safely be converted to an int primitive. * *@param value The value validation is being performed on. *@param locale The locale to use to parse the number (system default if * null)// w w w . j a v a 2 s. co m *@return the converted Integer value. */ public static Integer formatInt(String value, Locale locale) { Integer result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getNumberInstance(locale); } else { formatter = NumberFormat.getNumberInstance(Locale.getDefault()); } formatter.setParseIntegerOnly(true); ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= Integer.MIN_VALUE && num.doubleValue() <= Integer.MAX_VALUE) { result = new Integer(num.intValue()); } } } return result; }
From source file:com.jeeframework.util.validate.GenericTypeValidator.java
/** * Checks if the value can safely be converted to a long primitive. * *@param value The value validation is being performed on. *@param locale The locale to use to parse the number (system default if * null)/* w ww . j a v a 2 s . c om*/ *@return the converted Long value. */ public static Long formatLong(String value, Locale locale) { Long result = null; if (value != null) { NumberFormat formatter = null; if (locale != null) { formatter = NumberFormat.getNumberInstance(locale); } else { formatter = NumberFormat.getNumberInstance(Locale.getDefault()); } formatter.setParseIntegerOnly(true); ParsePosition pos = new ParsePosition(0); Number num = formatter.parse(value, pos); // If there was no error and we used the whole string if (pos.getErrorIndex() == -1 && pos.getIndex() == value.length()) { if (num.doubleValue() >= Long.MIN_VALUE && num.doubleValue() <= Long.MAX_VALUE) { result = new Long(num.longValue()); } } } return result; }
From source file:de.christianseipl.utilities.maputils.MapMath.java
/** * Addiert zu jedem Eintrag in der Map den Wert {@code _value} hinzu. * /*from w w w.ja v a2s. c o m*/ * @param <K> ein beliebiger Objekttyp * * @param _map * Die Ursprungsmap mit den Werten fr den ersten Summanden * @param _value * der zweite Summand * @return Eine neue Map deren Werte die Summe darstellen. */ public static <K> Map<K, Double> add(Map<? extends K, ? extends Number> _map, final double _value) { return operateOnMap(_map, new NumberTransformer<K, Double>() { @Override public Double transform(K _key, Number _number) { return _number.doubleValue() + _value; } }); }
From source file:de.christianseipl.utilities.maputils.MapMath.java
/** * Addiert zwei Maps und liefert eine neue Map mit der paarweisen * Addition der Werte./*from w ww . j av a 2 s. c o m*/ * * @param <K> ein beliebiger Objekttyp * @param _this Die Ursprungsmap mit den Werten fr den ersten Summanden * @param _that Die Ursprungsmap mit den Werten fr den zweiten Summanden * @return Eine neue Map mit den neuen Werten */ public static <K> Map<K, Double> add(Map<? extends K, ? extends Number> _this, final Map<? extends K, ? extends Number> _that) { return operateOnMap(_this, new NumberTransformer<K, Double>() { @Override public Double transform(K _key, Number _number) { return _number.doubleValue() + _that.get(_key).doubleValue(); } }); }
From source file:de.christianseipl.utilities.maputils.MapMath.java
/** * Es wird folgende Operation durchgefhrt: * <code>d - Math.floor(d)</code> * //from w w w .j ava 2s .c o m * Der Nachkommateil hat somit einen Wertebereich von [0;+1]. Ist d * negativ, so wird die Differenz zur nchsten kleineren ganzen Zahl * zurckgegeben. * * @param <K> ein beliebiger Objekttyp * * @param _map * Die Ursprungsmap * @return Eine neue Map mit den Nachkommaanteilen */ public static <K> Map<K, Double> frac(Map<? extends K, ? extends Number> _map) { return operateOnMap(_map, new NumberTransformer<K, Double>() { @Override public Double transform(K _key, Number _number) { return _number.doubleValue() - Math.floor(_number.doubleValue()); } }); }