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

Commit d81705a

Browse files
frauzufallimagejan
authored andcommitted
Making guessParser less error-prone
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..
1 parent 2cc51f6 commit d81705a

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/main/java/org/scijava/table/DefaultTableIOPlugin.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,17 +248,12 @@ private GenericTable open(final Location source, TableIOOptions.Values options)
248248
}
249249

250250
static Function<String, Object> guessParser(String content) {
251-
try {
252-
Integer.valueOf(content);
253-
return Integer::valueOf;
254-
} catch(NumberFormatException ignored) {}
255-
try {
256-
Long.valueOf(content);
257-
return Long::valueOf;
258-
} catch(NumberFormatException ignored) {}
259251
try {
260252
Double.valueOf(content);
261-
return Double::valueOf;
253+
return s -> Double.valueOf(s
254+
.replace("infinity", "Infinity")
255+
.replace("Nan", "NaN")
256+
);
262257
} catch(NumberFormatException ignored) {}
263258
if(content.equalsIgnoreCase("true")||content.equalsIgnoreCase("false")) {
264259
return Boolean::valueOf;

0 commit comments

Comments
 (0)