All Downloads are FREE. Search and download functionalities are using the official Maven repository.

external.org.apache.commons.lang3.NumberUtils Maven / Gradle / Ivy

Go to download

ratel api,used for developer on ratel system,an extension for xposed framewrok,ratel api compatable with original xposed framework

There is a newer version: 1.3.6
Show newest version
package external.org.apache.commons.lang3;

public class NumberUtils {
    /**
     * 

Convert a String to a double, returning * 0.0d if the conversion fails.

* *

If the string str is null, * 0.0d is returned.

* *
     *   NumberUtils.toDouble(null)   = 0.0d
     *   NumberUtils.toDouble("")     = 0.0d
     *   NumberUtils.toDouble("1.5")  = 1.5d
     * 
* * @param str the string to convert, may be null * @return the double represented by the string, or 0.0d * if conversion fails * @since 2.1 */ public static double toDouble(final String str) { return toDouble(str, 0.0d); } /** *

Convert a String to a double, returning a * default value if the conversion fails.

* *

If the string str is null, the default * value is returned.

* *
     *   NumberUtils.toDouble(null, 1.1d)   = 1.1d
     *   NumberUtils.toDouble("", 1.1d)     = 1.1d
     *   NumberUtils.toDouble("1.5", 0.0d)  = 1.5d
     * 
* * @param str the string to convert, may be null * @param defaultValue the default value * @return the double represented by the string, or defaultValue * if conversion fails * @since 2.1 */ public static double toDouble(final String str, final double defaultValue) { if (str == null) { return defaultValue; } try { return Double.parseDouble(str); } catch (final NumberFormatException nfe) { return defaultValue; } } /** *

Convert a String to an int, returning * zero if the conversion fails.

* *

If the string is null, zero is returned.

* *
     *   NumberUtils.toInt(null) = 0
     *   NumberUtils.toInt("")   = 0
     *   NumberUtils.toInt("1")  = 1
     * 
* * @param str the string to convert, may be null * @return the int represented by the string, or zero if * conversion fails * @since 2.1 */ public static int toInt(final String str) { return toInt(str, 0); } /** *

Convert a String to an int, returning a * default value if the conversion fails.

* *

If the string is null, the default value is returned.

* *
     *   NumberUtils.toInt(null, 1) = 1
     *   NumberUtils.toInt("", 1)   = 1
     *   NumberUtils.toInt("1", 0)  = 1
     * 
* * @param str the string to convert, may be null * @param defaultValue the default value * @return the int represented by the string, or the default if conversion fails * @since 2.1 */ public static int toInt(final String str, final int defaultValue) { if (str == null) { return defaultValue; } try { return Integer.parseInt(str); } catch (final NumberFormatException nfe) { return defaultValue; } } public static long toLong(final String str, final int defaultValue) { if (str == null) { return defaultValue; } try { return Long.parseLong(str); } catch (final NumberFormatException nfe) { return defaultValue; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy