/** * Checks if the given string is a double string that can be converted to a * double value. * * @param sStr * The string to check. May be <code>null</code>. * @return <code>true</code> if the value can be converted to a valid value */ public static boolean isDouble (@Nullable final String sStr) { return !Double.isNaN (parseDouble (sStr, Double.NaN)); }
/** * Parse the given {@link String} as {@link Double}. Note: both the locale * independent form of a double can be parsed here (e.g. 4.523) as well as a * localized form using the comma as the decimal separator (e.g. the German * 4,523). * * @param sStr * The string to parse. May be <code>null</code>. * @param aDefault * The default value to be returned if the parsed string cannot be * converted to a double. May be <code>null</code>. * @return <code>aDefault</code> if the object does not represent a valid * value. */ @Nullable public static Double parseDoubleObj (@Nullable final String sStr, @Nullable final Double aDefault) { final double dValue = parseDouble (sStr, Double.NaN); return Double.isNaN (dValue) ? aDefault : Double.valueOf (dValue); }
public static double getAsDouble (@Nullable final String sParamName, @Nullable final Object aValue, final double dDefault) { if (aValue == null) return dDefault; if (aValue instanceof Number) return ((Number) aValue).doubleValue (); // Interpret as String final String sValue = getAsString (sParamName, aValue, null); return StringParser.parseDouble (sValue, dDefault); }
/** * Parse the given {@link Object} as double. Note: both the locale independent * form of a double can be parsed here (e.g. 4.523) as well as a localized * form using the comma as the decimal separator (e.g. the German 4,523). * * @param aObject * The object to parse. May be <code>null</code>. * @param dDefault * The default value to be returned if the passed object could not be * converted to a valid value. * @return The default value if the object does not represent a valid value. */ public static double parseDouble (@Nullable final Object aObject, final double dDefault) { if (aObject == null) return dDefault; if (aObject instanceof Number) return ((Number) aObject).doubleValue (); return parseDouble (aObject.toString (), dDefault); }
/** * Parse the given {@link Object} as {@link Double}. Note: both the locale * independent form of a double can be parsed here (e.g. 4.523) as well as a * localized form using the comma as the decimal separator (e.g. the German * 4,523). * * @param aObject * The object to parse. May be <code>null</code>. * @param aDefault * The default value to be returned if the parsed object cannot be * converted to a double. May be <code>null</code>. * @return <code>aDefault</code> if the object does not represent a valid * value. */ @Nullable public static Double parseDoubleObj (@Nullable final Object aObject, @Nullable final Double aDefault) { final double dValue = parseDouble (aObject, Double.NaN); return Double.isNaN (dValue) ? aDefault : Double.valueOf (dValue); }
@Nullable public ICSSValue createSpecialValue (@Nonnull final ICSSProperty aProperty, @Nonnull @Nonempty final String sValue, final boolean bIsImportant) { final double dValue = StringParser.parseDouble (sValue, Double.NaN); if (!Double.isNaN (dValue)) { final int nPerc = (int) (dValue * 100); return new CSSValueList (ECSSProperty.OPACITY, new ICSSProperty [] { new CSSPropertyFree (ECSSProperty._MS_FILTER), new CSSPropertyFree (ECSSProperty.FILTER), aProperty.getClone (ECSSProperty._MOZ_OPACITY), aProperty.getClone (ECSSProperty._WEBKIT_OPACITY), aProperty }, new String [] { "\"progid:DXImageTransform.Microsoft.Alpha(Opacity=" + nPerc + ")\"", "alpha(opacity=" + nPerc + ")", sValue, sValue, sValue }, bIsImportant); } return null; } }
@Nullable public ICSSValue createSpecialValue (@Nonnull final ICSSProperty aProperty, @Nonnull @Nonempty final String sValue, final boolean bIsImportant) { final double dValue = StringParser.parseDouble (sValue, Double.NaN); if (!Double.isNaN (dValue)) { final int nPerc = (int) (dValue * 100); return new CSSValueList (ECSSProperty.OPACITY, new ICSSProperty [] { new CSSPropertyFree (ECSSProperty._MS_FILTER), new CSSPropertyFree (ECSSProperty.FILTER), aProperty.getClone (ECSSProperty._MOZ_OPACITY), aProperty.getClone (ECSSProperty._WEBKIT_OPACITY), aProperty }, new String [] { "\"progid:DXImageTransform.Microsoft.Alpha(Opacity=" + nPerc + ")\"", "alpha(opacity=" + nPerc + ")", sValue, sValue, sValue }, bIsImportant); } return null; } }