| 889 | } |
| 890 | |
| 891 | private static double toDouble(Object o) { |
| 892 | if (o instanceof Double) return (Double) o; |
| 893 | if (o instanceof Float) return ((Float) o).doubleValue(); |
| 894 | if (o instanceof Long) return ((Long) o).doubleValue(); |
| 895 | if (o instanceof Integer) return ((Integer) o).doubleValue(); |
| 896 | if (o instanceof BigDecimal) return ((BigDecimal) o).doubleValue(); |
| 897 | if (o instanceof String) { |
| 898 | try { return Double.parseDouble((String) o); } catch (NumberFormatException ex) { return 0.0; } |
| 899 | } |
| 900 | // Mirror TS's silent-NaN-or-default semantics: returning 0.0 instead of |
| 901 | // throwing keeps a single misuse (e.g. passing a Map to `sum`) from |
| 902 | // killing the whole WS connection. See Generic.toDouble for the same |
| 903 | // rationale and test coverage. |
| 904 | try { return Double.parseDouble(String.valueOf(o)); } catch (NumberFormatException ex) { return 0.0; } |
| 905 | } |
| 906 | |
| 907 | private static float toFloat(Object o) { |
| 908 | if (o instanceof Float) return (Float) o; |