@@ -126,6 +126,15 @@ protected final Object clone() {
126126 public boolean equals (Object object ) {
127127 return object == null || object == this ;
128128 }
129+ /**
130+ * A Null object is equal to the null value and to itself.
131+ *
132+ * @return always returns 0.
133+ */
134+ @ Override
135+ public int hashCode () {
136+ return 0 ;
137+ }
129138
130139 /**
131140 * Get the "null" string value.
@@ -801,13 +810,13 @@ public JSONObject increment(String key) throws JSONException {
801810 } else if (value instanceof BigDecimal ) {
802811 this .put (key , ((BigDecimal )value ).add (BigDecimal .ONE ));
803812 } else if (value instanceof Integer ) {
804- this .put (key , (Integer ) value + 1 );
813+ this .put (key , (( Integer ) value ). intValue () + 1 );
805814 } else if (value instanceof Long ) {
806- this .put (key , (Long ) value + 1 );
815+ this .put (key , (( Long ) value ). longValue () + 1L );
807816 } else if (value instanceof Double ) {
808- this .put (key , (Double ) value + 1 );
817+ this .put (key , (( Double ) value ). doubleValue () + 1.0d );
809818 } else if (value instanceof Float ) {
810- this .put (key , (Float ) value + 1 );
819+ this .put (key , (( Float ) value ). floatValue () + 1.0f );
811820 } else {
812821 throw new JSONException ("Unable to increment [" + quote (key ) + "]." );
813822 }
@@ -934,7 +943,7 @@ public <E extends Enum<E>> E optEnum(Class<E> clazz, String key) {
934943 * @param defaultValue
935944 * The default in case the value is not found
936945 * @return The enum value associated with the key or defaultValue
937- * if the value is not found or cannot be assigned to clazz
946+ * if the value is not found or cannot be assigned to <code> clazz</code>
938947 */
939948 public <E extends Enum <E >> E optEnum (Class <E > clazz , String key , E defaultValue ) {
940949 try {
@@ -1437,7 +1446,23 @@ public JSONObject put(String key, Collection<?> value) throws JSONException {
14371446 * If the key is null or if the number is invalid.
14381447 */
14391448 public JSONObject put (String key , double value ) throws JSONException {
1440- this .put (key , new Double (value ));
1449+ this .put (key , Double .valueOf (value ));
1450+ return this ;
1451+ }
1452+
1453+ /**
1454+ * Put a key/float pair in the JSONObject.
1455+ *
1456+ * @param key
1457+ * A key string.
1458+ * @param value
1459+ * A float which is the value.
1460+ * @return this.
1461+ * @throws JSONException
1462+ * If the key is null or if the number is invalid.
1463+ */
1464+ public JSONObject put (String key , float value ) throws JSONException {
1465+ this .put (key , Float .valueOf (value ));
14411466 return this ;
14421467 }
14431468
@@ -1453,7 +1478,7 @@ public JSONObject put(String key, double value) throws JSONException {
14531478 * If the key is null.
14541479 */
14551480 public JSONObject put (String key , int value ) throws JSONException {
1456- this .put (key , new Integer (value ));
1481+ this .put (key , Integer . valueOf (value ));
14571482 return this ;
14581483 }
14591484
@@ -1469,7 +1494,7 @@ public JSONObject put(String key, int value) throws JSONException {
14691494 * If the key is null.
14701495 */
14711496 public JSONObject put (String key , long value ) throws JSONException {
1472- this .put (key , new Long (value ));
1497+ this .put (key , Long . valueOf (value ));
14731498 return this ;
14741499 }
14751500
@@ -1559,7 +1584,7 @@ public JSONObject putOpt(String key, Object value) throws JSONException {
15591584 }
15601585
15611586 /**
1562- * Creates a JSONPointer using an intialization string and tries to
1587+ * Creates a JSONPointer using an initialization string and tries to
15631588 * match it to an item within this JSONObject. For example, given a
15641589 * JSONObject initialized with this document:
15651590 * <pre>
@@ -1581,7 +1606,7 @@ public Object query(String jsonPointer) {
15811606 return query (new JSONPointer (jsonPointer ));
15821607 }
15831608 /**
1584- * Uses a uaer initialized JSONPointer and tries to
1609+ * Uses a user initialized JSONPointer and tries to
15851610 * match it to an item within this JSONObject. For example, given a
15861611 * JSONObject initialized with this document:
15871612 * <pre>
@@ -1959,7 +1984,7 @@ public String toString() {
19591984 }
19601985
19611986 /**
1962- * Make a prettyprinted JSON text of this JSONObject.
1987+ * Make a pretty-printed JSON text of this JSONObject.
19631988 * <p>
19641989 * Warning: This method assumes that the data structure is acyclical.
19651990 *
@@ -2024,7 +2049,8 @@ public static String valueToString(Object value) throws JSONException {
20242049 final String numberAsString = numberToString ((Number ) value );
20252050 try {
20262051 // Use the BigDecimal constructor for it's parser to validate the format.
2027- new BigDecimal (numberAsString );
2052+ @ SuppressWarnings ("unused" )
2053+ BigDecimal unused = new BigDecimal (numberAsString );
20282054 // Close enough to a JSON number that we will return it unquoted
20292055 return numberAsString ;
20302056 } catch (NumberFormatException ex ){
@@ -2185,7 +2211,7 @@ static final void indent(Writer writer, int indent) throws IOException {
21852211 * @param indentFactor
21862212 * The number of spaces to add to each level of indentation.
21872213 * @param indent
2188- * The indention of the top level.
2214+ * The indentation of the top level.
21892215 * @return The writer.
21902216 * @throws JSONException
21912217 */
0 commit comments