Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Making guessParser less error-prone
Browse files Browse the repository at this point in the history
When auto detecting the column type of such a column, the previous
guessParser implementation produced exceptions:

-1
0
-1.0
1.0
0.0
infinity
-infinity
+Nan
NaN
-NaN
1.23e7
13.8f
57269d

Therefore, now the only number format which will be guessed by
guessParser is Double. Also, when testing this with imagej-server, the
Strings "infinity" and "Nan" where used which are not compatible with
Double::valueOf, therefore they are replaced with the compatible
capitalization. Maybe there is a better way to  do this..
  • Loading branch information
frauzufall authored and imagejan committed Aug 14, 2020
1 parent 2cc51f6 commit d81705a
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/main/java/org/scijava/table/DefaultTableIOPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,12 @@ private GenericTable open(final Location source, TableIOOptions.Values options)
}

static Function<String, Object> guessParser(String content) {
try {
Integer.valueOf(content);
return Integer::valueOf;
} catch(NumberFormatException ignored) {}
try {
Long.valueOf(content);
return Long::valueOf;
} catch(NumberFormatException ignored) {}
try {
Double.valueOf(content);
return Double::valueOf;
return s -> Double.valueOf(s
.replace("infinity", "Infinity")
.replace("Nan", "NaN")
);
} catch(NumberFormatException ignored) {}
if(content.equalsIgnoreCase("true")||content.equalsIgnoreCase("false")) {
return Boolean::valueOf;
Expand Down

0 comments on commit d81705a

Please sign in to comment.