From 410afaff145ba59c4979c0492e2d244ac6e6dfe4 Mon Sep 17 00:00:00 2001 From: stleary Date: Mon, 6 Jul 2015 22:20:19 -0500 Subject: [PATCH] latest --- JSONArray.java | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/JSONArray.java b/JSONArray.java index 22d4ab7..684ed7a 100644 --- a/JSONArray.java +++ b/JSONArray.java @@ -531,6 +531,44 @@ public class JSONArray implements Iterable { } } + /** + * Get the optional BigInteger value associated with an index. The + * defaultValue is returned if there is no value for the index, or if the + * value is not a number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public BigInteger optBigInteger(int index, BigInteger defaultValue) { + try { + return this.getBigInteger(index); + } catch (Exception e) { + return defaultValue; + } + } + + /** + * Get the optional BigDecimal value associated with an index. The + * defaultValue is returned if there is no value for the index, or if the + * value is not a number and cannot be converted to a number. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default value. + * @return The value. + */ + public BigDecimal optBigDecimal(int index, BigDecimal defaultValue) { + try { + return this.getBigDecimal(index); + } catch (Exception e) { + return defaultValue; + } + } + /** * Get the optional JSONArray associated with an index. *