io.sirix.service.json.JsonNumber Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sirix-core Show documentation
Show all versions of sirix-core Show documentation
SirixDB is a hybrid on-disk and in-memory document oriented, versioned database system. It has a lightweight buffer manager, stores everything in a huge persistent and durable tree and allows efficient reconstruction of every revision. Furthermore, SirixDB implements change tracking, diffing and supports time travel queries.
package io.sirix.service.json;
import java.math.BigDecimal;
import java.math.BigInteger;
public final class JsonNumber {
private JsonNumber() {
}
private static Number stringDecimal(String stringValue) {
Number number;
Number n1 = Float.MAX_VALUE;
try {
if (stringValue.contains("E") || stringValue.contains("e")) {
number = Double.valueOf(stringValue);
if (number.doubleValue() <= n1.doubleValue()) {
number = Float.valueOf(stringValue);
}
} else {
number = new BigDecimal(stringValue);
}
} catch (final NumberFormatException eeeeee) {
throw new IllegalStateException(eeeeee);
}
return number;
}
public static Number stringToNumber(String stringValue) {
Number number;
if (stringValue.contains(".")) {
number = stringDecimal(stringValue);
} else {
try {
number = Integer.valueOf(stringValue);
} catch (final NumberFormatException e) {
try {
number = Long.valueOf(stringValue);
} catch (final NumberFormatException ee) {
try {
number = new BigInteger(stringValue);
} catch (final NumberFormatException eee) {
throw new IllegalStateException(eee);
}
}
}
}
return number;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy