@@ -203,6 +203,14 @@ public abstract class ParserBase extends ParserMinimalBase
203
203
204
204
protected BigDecimal _numberBigDecimal ;
205
205
206
+ /**
207
+ * Textual number representation captured from input in cases lazy-parsing
208
+ * is desired.
209
+ *<p>
210
+ * As of 2.14 this only applies to {@link BigInteger}.
211
+ *
212
+ * @since 2.14
213
+ */
206
214
protected String _numberString ;
207
215
208
216
// And then other information about value itself
@@ -609,7 +617,7 @@ public Number getNumberValue() throws IOException
609
617
return _numberLong ;
610
618
}
611
619
if ((_numTypesValid & NR_BIGINT ) != 0 ) {
612
- return getBigInteger ();
620
+ return _getBigInteger ();
613
621
}
614
622
_throwInternal ();
615
623
}
@@ -643,7 +651,7 @@ public Number getNumberValueExact() throws IOException
643
651
return _numberLong ;
644
652
}
645
653
if ((_numTypesValid & NR_BIGINT ) != 0 ) {
646
- return getBigInteger ();
654
+ return _getBigInteger ();
647
655
}
648
656
_throwInternal ();
649
657
}
@@ -733,7 +741,7 @@ public BigInteger getBigIntegerValue() throws IOException
733
741
convertNumberToBigInteger ();
734
742
}
735
743
}
736
- return getBigInteger ();
744
+ return _getBigInteger ();
737
745
}
738
746
739
747
@ Override
@@ -971,7 +979,7 @@ protected void convertNumberToInt() throws IOException
971
979
}
972
980
_numberInt = result ;
973
981
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
974
- final BigInteger bigInteger = getBigInteger ();
982
+ final BigInteger bigInteger = _getBigInteger ();
975
983
if (BI_MIN_INT .compareTo (bigInteger ) > 0
976
984
|| BI_MAX_INT .compareTo (bigInteger ) < 0 ) {
977
985
reportOverflowInt ();
@@ -1000,7 +1008,7 @@ protected void convertNumberToLong() throws IOException
1000
1008
if ((_numTypesValid & NR_INT ) != 0 ) {
1001
1009
_numberLong = (long ) _numberInt ;
1002
1010
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
1003
- final BigInteger bigInteger = getBigInteger ();
1011
+ final BigInteger bigInteger = _getBigInteger ();
1004
1012
if (BI_MIN_LONG .compareTo (bigInteger ) > 0
1005
1013
|| BI_MAX_LONG .compareTo (bigInteger ) < 0 ) {
1006
1014
reportOverflowLong ();
@@ -1052,7 +1060,7 @@ protected void convertNumberToDouble() throws IOException
1052
1060
if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
1053
1061
_numberDouble = _numberBigDecimal .doubleValue ();
1054
1062
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
1055
- _numberDouble = getBigInteger ().doubleValue ();
1063
+ _numberDouble = _getBigInteger ().doubleValue ();
1056
1064
} else if ((_numTypesValid & NR_LONG ) != 0 ) {
1057
1065
_numberDouble = (double ) _numberLong ;
1058
1066
} else if ((_numTypesValid & NR_INT ) != 0 ) {
@@ -1076,7 +1084,7 @@ protected void convertNumberToFloat() throws IOException
1076
1084
if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
1077
1085
_numberFloat = _numberBigDecimal .floatValue ();
1078
1086
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
1079
- _numberFloat = getBigInteger ().floatValue ();
1087
+ _numberFloat = _getBigInteger ().floatValue ();
1080
1088
} else if ((_numTypesValid & NR_LONG ) != 0 ) {
1081
1089
_numberFloat = (float ) _numberLong ;
1082
1090
} else if ((_numTypesValid & NR_INT ) != 0 ) {
@@ -1098,12 +1106,11 @@ protected void convertNumberToBigDecimal() throws IOException
1098
1106
*/
1099
1107
1100
1108
if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
1101
- /* Let's actually parse from String representation, to avoid
1102
- * rounding errors that non-decimal floating operations could incur
1103
- */
1109
+ // Let's actually parse from String representation, to avoid
1110
+ // rounding errors that non-decimal floating operations could incur
1104
1111
_numberBigDecimal = NumberInput .parseBigDecimal (getText ());
1105
1112
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
1106
- _numberBigDecimal = new BigDecimal (getBigInteger ());
1113
+ _numberBigDecimal = new BigDecimal (_getBigInteger ());
1107
1114
} else if ((_numTypesValid & NR_LONG ) != 0 ) {
1108
1115
_numberBigDecimal = BigDecimal .valueOf (_numberLong );
1109
1116
} else if ((_numTypesValid & NR_INT ) != 0 ) {
@@ -1114,6 +1121,23 @@ protected void convertNumberToBigDecimal() throws IOException
1114
1121
_numTypesValid |= NR_BIGDECIMAL ;
1115
1122
}
1116
1123
1124
+ /**
1125
+ * Internal accessor that needs to be used for accessing number value of type
1126
+ * {@link BigInteger} which -- as of 2.14 -- is typically lazily parsed.
1127
+ *
1128
+ * @since 2.14
1129
+ */
1130
+ protected BigInteger _getBigInteger () {
1131
+ if (_numberBigInt != null ) {
1132
+ return _numberBigInt ;
1133
+ } else if (_numberString == null ) {
1134
+ throw new IllegalStateException ("cannot get BigInteger from current parser state" );
1135
+ }
1136
+ _numberBigInt = NumberInput .parseBigInteger (_numberString );
1137
+ _numberString = null ;
1138
+ return _numberBigInt ;
1139
+ }
1140
+
1117
1141
/*
1118
1142
/**********************************************************
1119
1143
/* Internal/package methods: Error reporting
@@ -1332,7 +1356,7 @@ protected static int[] growArrayBy(int[] arr, int more)
1332
1356
}
1333
1357
return Arrays .copyOf (arr , arr .length + more );
1334
1358
}
1335
-
1359
+
1336
1360
/*
1337
1361
/**********************************************************
1338
1362
/* Stuff that was abstract and required before 2.8, but that
@@ -1350,15 +1374,4 @@ protected void loadMoreGuaranteed() throws IOException {
1350
1374
1351
1375
// Can't declare as deprecated, for now, but shouldn't be needed
1352
1376
protected void _finishString () throws IOException { }
1353
-
1354
- private BigInteger getBigInteger () {
1355
- if (_numberBigInt != null ) {
1356
- return _numberBigInt ;
1357
- } else if (_numberString == null ) {
1358
- throw new IllegalStateException ("cannot get BigInteger from current parser state" );
1359
- }
1360
- _numberBigInt = NumberInput .parseBigInteger (_numberString );
1361
- _numberString = null ;
1362
- return _numberBigInt ;
1363
- }
1364
1377
}
0 commit comments