diff --git a/src/main/java/org/scijava/table/DefaultTableIOPlugin.java b/src/main/java/org/scijava/table/DefaultTableIOPlugin.java index aceaab3..85bb5ef 100644 --- a/src/main/java/org/scijava/table/DefaultTableIOPlugin.java +++ b/src/main/java/org/scijava/table/DefaultTableIOPlugin.java @@ -247,18 +247,14 @@ private GenericTable open(final Location source, TableIOOptions.Values options) return options.parser(); } - static Function guessParser(String content) { + static Function 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; + Function function = s -> Double.valueOf(s + .replace("infinity", "Infinity") + .replace("Nan", "NaN") + ); + function.apply(content); + return function; } catch(NumberFormatException ignored) {} if(content.equalsIgnoreCase("true")||content.equalsIgnoreCase("false")) { return Boolean::valueOf; diff --git a/src/test/java/org/scijava/table/DefaultTableIOPluginTest.java b/src/test/java/org/scijava/table/DefaultTableIOPluginTest.java index cdbc084..6a72835 100644 --- a/src/test/java/org/scijava/table/DefaultTableIOPluginTest.java +++ b/src/test/java/org/scijava/table/DefaultTableIOPluginTest.java @@ -111,7 +111,7 @@ public void testDefaultOptions() throws IOException { } /** - * Tests if quoting works in different senarios. + * Tests if quoting works in different scenarios. */ @Test public void testQuote() { @@ -160,7 +160,7 @@ public void testQuote() { } /** - * Tests if samll tables could be opened/saved correctly. + * Tests if small tables can be opened/saved correctly. */ @Test public void testSmallTables() { @@ -250,11 +250,13 @@ public void testGuessParser() { assertEquals(false, DefaultTableIOPlugin.guessParser("false").apply("false")); assertEquals(123.0, DefaultTableIOPlugin.guessParser("123.0").apply("123.0")); assertEquals(-123.0, DefaultTableIOPlugin.guessParser("-123.0").apply("-123.0")); - assertEquals(3, DefaultTableIOPlugin.guessParser("3").apply("3")); - assertEquals(36564573745634564L, DefaultTableIOPlugin.guessParser("36564573745634564").apply("36564573745634564")); + assertEquals(3.0, DefaultTableIOPlugin.guessParser("3").apply("3")); + assertEquals(36564573745634564d, DefaultTableIOPlugin.guessParser("36564573745634564").apply("36564573745634564")); assertEquals(1234567890.0987654321, DefaultTableIOPlugin.guessParser("1.2345678900987654E9").apply("1.2345678900987654E9")); assertEquals(Double.NaN, DefaultTableIOPlugin.guessParser("NaN").apply("NaN")); + assertEquals(Double.NaN, DefaultTableIOPlugin.guessParser("Nan").apply("Nan")); assertEquals(Double.NEGATIVE_INFINITY, DefaultTableIOPlugin.guessParser("-Infinity").apply("-Infinity")); + assertEquals(Double.POSITIVE_INFINITY, DefaultTableIOPlugin.guessParser("infinity").apply("infinity")); assertEquals(0.0, DefaultTableIOPlugin.guessParser("0.0").apply("0.0")); }