Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refact(core): support Infinity & NaN number in float/double property #1578

Merged
merged 4 commits into from
Sep 16, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.baidu.hugegraph.util.Bytes;
import com.baidu.hugegraph.util.DateUtil;
import com.baidu.hugegraph.util.StringEncoding;
import com.google.common.collect.ImmutableSet;

public enum DataType implements SerialEnum {

Expand All @@ -49,12 +50,11 @@ public enum DataType implements SerialEnum {
private final byte code;
private final String name;
private final Class<?> clazz;
private final static String POSITIVE_INFINITY = "Infinity";
private final static String NEGATIVE_INFINITY = "-Infinity";
private final static String NaN = "NaN";
private final static ImmutableSet<String> specialNums;
imbajin marked this conversation as resolved.
Show resolved Hide resolved

static {
SerialEnum.register(DataType.class);
specialNums = ImmutableSet.of("-Infinity", "Infinity", "NaN");
}

DataType(int code, String name, Class<?> clazz) {
Expand Down Expand Up @@ -108,9 +108,7 @@ public boolean isUUID() {
}

private static <V> boolean isInfinityOrNaN(V value) {
return value instanceof String &&
(POSITIVE_INFINITY.equals(value) ||
NEGATIVE_INFINITY.equals(value) || NaN.equals(value));
return value instanceof String && specialNums.contains(value);
imbajin marked this conversation as resolved.
Show resolved Hide resolved
}

public <V> Number valueToNumber(V value) {
Expand Down