redis.clients.jedis.util.DoublePrecision Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jedis_preview Show documentation
Show all versions of jedis_preview Show documentation
Jedis is a blazingly small and sane Redis java client.
The newest version!
package redis.clients.jedis.util;
public final class DoublePrecision {
private DoublePrecision() {
throw new InstantiationError("Must not instantiate this class");
}
public static Double parseFloatingPointNumber(String str) throws NumberFormatException {
if (str == null) return null;
try {
return Double.valueOf(str);
} catch (NumberFormatException e) {
switch (str) {
case "inf":
case "+inf":
return Double.POSITIVE_INFINITY;
case "-inf":
return Double.NEGATIVE_INFINITY;
case "nan":
case "-nan": // for some module commands // TODO: remove
return Double.NaN;
default:
throw e;
}
}
}
public static Double parseEncodedFloatingPointNumber(Object val) throws NumberFormatException {
if (val == null) return null;
else if (val instanceof Double) return (Double) val;
else return parseFloatingPointNumber((String) val);
}
}