OLINGO-1150: allowing support to read decimal values presented in the exponential form

This commit is contained in:
Ramesh Reddy 2018-01-19 11:03:46 -06:00
parent 9dfe499517
commit 1012bcb248
2 changed files with 5 additions and 3 deletions

View File

@ -31,7 +31,8 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
*/
public final class EdmDecimal extends SingletonPrimitiveType {
private static final Pattern PATTERN = Pattern.compile("(?:\\+|-)?(?:0*(\\p{Digit}+?))(?:\\.(\\p{Digit}+?)0*)?");
private static final Pattern PATTERN = Pattern.compile(
"(?:\\+|-)?(?:0*(\\p{Digit}+?))(?:\\.(\\p{Digit}+?)0*)?((?:E|e)(?:\\+|-)?\\p{Digit}+)?");
private static final EdmDecimal INSTANCE = new EdmDecimal();

View File

@ -97,7 +97,9 @@ public class EdmDecimalTest extends PrimitiveTypeBaseTest {
assertEquals(Double.valueOf(0.5), instance.valueOfString("0.5", null, null, 1, 1, null, Double.class));
assertEquals(Float.valueOf(0.5F), instance.valueOfString("0.5", null, null, null, 1, null, Float.class));
assertEquals(new BigDecimal("12.3"), instance.valueOfString("12.3", null, null, 3, 1, null, BigDecimal.class));
assertEquals(new BigDecimal("31991163"), instance.valueOfString("3.1991163E7", null, null, 8, 7,
null, BigDecimal.class));
expectFacetsErrorInValueOfString(instance, "0.5", null, null, null, null, null);
expectFacetsErrorInValueOfString(instance, "-1234", null, null, 2, null, null);
expectFacetsErrorInValueOfString(instance, "1234", null, null, 3, null, null);
@ -107,7 +109,6 @@ public class EdmDecimalTest extends PrimitiveTypeBaseTest {
expectFacetsErrorInValueOfString(instance, "0.00390625", null, null, 5, null, null);
expectFacetsErrorInValueOfString(instance, "0.00390625", null, null, null, 7, null);
expectContentErrorInValueOfString(instance, "-1E2");
expectContentErrorInValueOfString(instance, "1.");
expectContentErrorInValueOfString(instance, ".1");
expectContentErrorInValueOfString(instance, "1.0.1");