Author: tchemit Date: 2014-03-26 08:42:52 +0100 (Wed, 26 Mar 2014) New Revision: 2611 Url: http://forge.nuiton.org/projects/nuiton-csv/repository/revisions/2611 Log: fixes #3131: Be able to parse more integer and long number fixes #3133: Add a *YEAR* ValueParserformatter Modified: trunk/src/main/java/org/nuiton/csv/Common.java Modified: trunk/src/main/java/org/nuiton/csv/Common.java =================================================================== --- trunk/src/main/java/org/nuiton/csv/Common.java 2014-03-26 07:42:29 UTC (rev 2610) +++ trunk/src/main/java/org/nuiton/csv/Common.java 2014-03-26 07:42:52 UTC (rev 2611) @@ -100,6 +100,9 @@ public static final ValueParserFormatter<Date> WEEK = new DateValue("w/yyyy"); + public static final ValueParserFormatter<Date> YEAR = + new DateValue("yyyy"); + public static <E extends Map<String, Object>, T> MapProperty<E, T> newMapProperty(String propertyName) { return new MapProperty<E, T>(propertyName); } @@ -251,7 +254,7 @@ if (StringUtils.isBlank(value)) { result = null; } else { - Integer ordinal = null; + Integer ordinal; try { ordinal = Integer.valueOf(value); } catch (NumberFormatException e) { @@ -263,7 +266,8 @@ "Ordinal value [" + ordinal + "] not inbound (possible value from [0.." + maxValue + "] for enum " + Arrays.toString(universe), - 0); + 0 + ); } result = universe[ordinal]; } @@ -464,7 +468,13 @@ @Override protected Integer parseNoneEmptyValue(String value) { - return Integer.valueOf(value); + // use a float to be able to parse for example 6e+06 (see https://forge.nuiton.org/issues/3131) + Float aFloat = Float.valueOf(value); + if (aFloat > Integer.MAX_VALUE) { + // too big + throw new IllegalArgumentException(value + " is too big to be an int, should be a long."); + } + return aFloat.intValue(); } } @@ -485,7 +495,13 @@ @Override protected Long parseNoneEmptyValue(String value) { - return Long.valueOf(value); + // use a double to be able to parse for example 6e+06 (see https://forge.nuiton.org/issues/3131) + Double aDouble = Double.valueOf(value); + if (aDouble > Long.MAX_VALUE) { + // too big + throw new IllegalArgumentException(value + " is too big to be an long."); + } + return aDouble.longValue(); } }
participants (1)
-
tchemit@users.nuiton.org