public BigDecimal convert (@Nonnull final Object aSource) { return StringParser.parseBigDecimal (aSource.toString (), (BigDecimal) null); } });
/** * Parse the given {@link String} as int with radix {@value #DEFAULT_RADIX}. * * @param sStr * The String to parse. May be <code>null</code>. * @param nDefault * The value to be returned if the string cannot be converted to a * valid value. * @return The passed default parameter if the string does not represent a * valid value. */ public static int parseInt (@Nullable final String sStr, final int nDefault) { return parseInt (sStr, DEFAULT_RADIX, nDefault); }
/** * 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)); }
m_nMajor = StringParser.parseInt (aParts[0], 0); else m_nMajor = 0; if (aParts.length > 1) m_nMinor = StringParser.parseInt (aParts[1], 0); else m_nMinor = 0; if (aParts.length > 2) m_nMicro = StringParser.parseInt (aParts[2], 0); else m_nMicro = 0; aMajor = StringParser.parseIntObj (aParts[0]); if (aMajor == null && StringHelper.hasText (aParts[0])) aMinor = StringParser.parseIntObj (aParts[0]); if (aMinor == null && StringHelper.hasText (aParts[0])) aMicro = StringParser.parseIntObj (aParts[0]); if (aMicro == null && StringHelper.hasText (aParts[0]))
public Integer convert (@Nonnull final Object aSource) { return StringParser.parseIntObj (aSource, (Integer) null); } });
final boolean bZeroVATAllowed = StringParser.parseBool (sZeroVATAllowed); final BigDecimal aPercentage = StringParser.parseBigDecimal (sPercentage, null); if (aPercentage == null) final boolean bDeprecated = sDeprecated != null && StringParser.parseBool (sDeprecated);
public Double convert (@Nonnull final Object aSource) { return StringParser.parseDoubleObj (aSource, (Double) null); } });
/** * Parse the given {@link String} as byte with radix {@value #DEFAULT_RADIX}. * * @param sStr * The String to parse. May be <code>null</code>. * @param nDefault * The value to be returned if the string cannot be converted to a * valid value. * @return The passed default parameter if the string does not represent a * valid value. */ public static byte parseByte (@Nullable final String sStr, final byte nDefault) { return parseByte (sStr, DEFAULT_RADIX, nDefault); }
/** * Try to interpret the passed object as boolean. This works only if the * passed object is either a {@link String} or a {@link Boolean}. * * @param aObject * The object to be interpreted. May be <code>null</code>. * @return <code>false</code> if the passed object cannot be interpreted as a * boolean. */ public static boolean parseBool (@Nullable final Object aObject) { return parseBool (aObject, false); }
public static boolean isNumberValue (@Nullable final String sCSSValue) { final String sRealValue = StringHelper.trim (sCSSValue); return StringHelper.hasText (sRealValue) && StringParser.isDouble (sRealValue); }
/** * Parse the given {@link String} as {@link Integer} with radix * {@value #DEFAULT_RADIX}. * * @param sStr * The string to parse. May be <code>null</code>. * @return <code>null</code> if the string does not represent a valid value. */ @Nullable public static Integer parseIntObj (@Nullable final String sStr) { return parseIntObj (sStr, DEFAULT_RADIX, null); }
/** * 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>. * @return <code>null</code> if the object does not represent a valid value. */ @Nullable public static Double parseDoubleObj (@Nullable final Object aObject) { return parseDoubleObj (aObject, null); }
/** * Parse the given {@link Object} as byte with radix {@value #DEFAULT_RADIX}. * * @param aObject * The Object to parse. May be <code>null</code>. * @param nDefault * The default value to be returned if the passed object could not be * converted to a valid value. * @return The default value if the string does not represent a valid value. */ public static byte parseByte (@Nullable final Object aObject, final byte nDefault) { return parseByte (aObject, DEFAULT_RADIX, nDefault); }
/** * Try to interpret the passed object as boolean. This works only if the * passed object is either a {@link String} or a {@link Boolean}. * * @param aObject * The object to be interpreted. May be <code>null</code>. * @param bDefault * The default value to be returned, if the object cannot be * interpreted. * @return The boolean representation or the default value if the passed * object cannot be interpreted as a boolean. */ public static boolean parseBool (@Nullable final Object aObject, final boolean bDefault) { if (aObject instanceof Boolean) return ((Boolean) aObject).booleanValue (); if (aObject instanceof String) return parseBool ((String) aObject); return bDefault; }
public static boolean isNumberValue (@Nullable final String sCSSValue) { final String sRealValue = StringHelper.trim (sCSSValue); return StringHelper.hasText (sRealValue) && StringParser.isDouble (sRealValue); }
/** * Parse the given {@link Object} as int with radix {@link #DEFAULT_RADIX}. * * @param aObject * The Object to parse. May be <code>null</code>. * @param nDefault * The default value to be returned if the passed object could not be * converted to a valid value. * @return The default value if the string does not represent a valid value. */ public static int parseInt (@Nullable final Object aObject, final int nDefault) { return parseInt (aObject, DEFAULT_RADIX, nDefault); }
/** * Parse the given {@link String} as {@link BigDecimal}. * * @param sStr * The String to parse. May be <code>null</code>. * @return <code>null</code> if the string does not represent a valid value. */ @Nullable public static BigDecimal parseBigDecimal (@Nullable final String sStr) { return parseBigDecimal (sStr, null); }
@Nullable public Integer convert (@Nullable final String sInput) { return StringParser.parseIntObj (sInput, m_aDefaultValue); } }
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 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>. * @return <code>null</code> if the object does not represent a valid value. */ @Nullable public static Double parseDoubleObj (@Nullable final String sStr) { return parseDoubleObj (sStr, null); }