mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 20:29:20 +00:00
31 lines
No EOL
917 B
Java
31 lines
No EOL
917 B
Java
package com.earth2me.essentials.utils;
|
|
|
|
/**
|
|
* parseFloat and parseDouble proxies that are protected against non-finite values.
|
|
*/
|
|
public class FloatUtil {
|
|
private FloatUtil() {
|
|
}
|
|
|
|
public static float parseFloat(String s) throws NumberFormatException {
|
|
float f = Float.parseFloat(s);
|
|
if (Float.isNaN(f)) {
|
|
throw new NumberFormatException("NaN is not valid");
|
|
}
|
|
if (Float.isInfinite(f)) {
|
|
throw new NumberFormatException("Infinity is not valid");
|
|
}
|
|
return f;
|
|
}
|
|
|
|
public static double parseDouble(String s) throws NumberFormatException {
|
|
double d = Double.parseDouble(s);
|
|
if (Double.isNaN(d)) {
|
|
throw new NumberFormatException("NaN is not valid");
|
|
}
|
|
if (Double.isInfinite(d)) {
|
|
throw new NumberFormatException("Infinity is not valid");
|
|
}
|
|
return d;
|
|
}
|
|
} |