From fcdb8671b28eb74964d86ee53a9f96a81cd5423e Mon Sep 17 00:00:00 2001 From: "John J. Aylward" Date: Wed, 17 May 2017 11:32:44 -0400 Subject: [PATCH] grr, forgot to save changes on last commit --- JSONArray.java | 20 ++++++++++++++++++-- JSONObject.java | 8 ++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/JSONArray.java b/JSONArray.java index 18d43ce..bfab701 100644 --- a/JSONArray.java +++ b/JSONArray.java @@ -536,7 +536,7 @@ public class JSONArray implements Iterable { } /** - * Get the optional double value associated with an index. NaN is returned + * Get the optional float value associated with an index. NaN 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. * @@ -549,7 +549,7 @@ public class JSONArray implements Iterable { } /** - * Get the optional double value associated with an index. The defaultValue + * Get the optional float 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. * @@ -808,6 +808,22 @@ public class JSONArray implements Iterable { return defaultValue; } + /** + * Get an optional {@link Number} value associated with a key, or null + * if there is no such key or if the value is not a number. If the value is a string, + * an attempt will be made to evaluate it as a number ({@link BigDecimal}). This method + * would be used in cases where type coercion of the number value is unwanted. + * + * @param index + * The index must be between 0 and length() - 1. + * @param defaultValue + * The default. + * @return An object which is the value. + */ + public Number optNumber(int index) { + return this.optNumber(index, null); + } + /** * Get an optional {@link Number} value associated with a key, or the default if there * is no such key or if the value is not a number. If the value is a string, diff --git a/JSONObject.java b/JSONObject.java index 13ba48e..3ca47d0 100644 --- a/JSONObject.java +++ b/JSONObject.java @@ -1075,8 +1075,8 @@ public class JSONObject { * 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 key + * A key string. * @return The value. */ public float optFloat(String key) { @@ -1088,8 +1088,8 @@ public class JSONObject { * 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 - * subscript + * @param key + * A key string. * @param defaultValue * The default value. * @return The value.