@@ -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.
@@ -754,13 +763,13 @@ public JSONObject increment(String key) throws JSONException {
754763 } else if (value instanceof BigDecimal ) {
755764 this .put (key , ((BigDecimal )value ).add (BigDecimal .ONE ));
756765 } else if (value instanceof Integer ) {
757- this .put (key , (Integer ) value + 1 );
766+ this .put (key , (( Integer ) value ). intValue () + 1 );
758767 } else if (value instanceof Long ) {
759- this .put (key , (Long ) value + 1 );
768+ this .put (key , (( Long ) value ). longValue () + 1L );
760769 } else if (value instanceof Double ) {
761- this .put (key , (Double ) value + 1 );
770+ this .put (key , (( Double ) value ). doubleValue () + 1D );
762771 } else if (value instanceof Float ) {
763- this .put (key , (Float ) value + 1 );
772+ this .put (key , (( Float ) value ). floatValue () + 1F );
764773 } else {
765774 throw new JSONException ("Unable to increment [" + quote (key ) + "]." );
766775 }
@@ -887,7 +896,7 @@ public <E extends Enum<E>> E optEnum(Class<E> clazz, String key) {
887896 * @param defaultValue
888897 * The default in case the value is not found
889898 * @return The enum value associated with the key or defaultValue
890- * if the value is not found or cannot be assigned to clazz
899+ * if the value is not found or cannot be assigned to <code> clazz</code>
891900 */
892901 public <E extends Enum <E >> E optEnum (Class <E > clazz , String key , E defaultValue ) {
893902 try {
@@ -1218,7 +1227,23 @@ public JSONObject put(String key, Collection<?> value) throws JSONException {
12181227 * If the key is null or if the number is invalid.
12191228 */
12201229 public JSONObject put (String key , double value ) throws JSONException {
1221- this .put (key , new Double (value ));
1230+ this .put (key , Double .valueOf (value ));
1231+ return this ;
1232+ }
1233+
1234+ /**
1235+ * Put a key/float pair in the JSONObject.
1236+ *
1237+ * @param key
1238+ * A key string.
1239+ * @param value
1240+ * A float which is the value.
1241+ * @return this.
1242+ * @throws JSONException
1243+ * If the key is null or if the number is invalid.
1244+ */
1245+ public JSONObject put (String key , float value ) throws JSONException {
1246+ this .put (key , Float .valueOf (value ));
12221247 return this ;
12231248 }
12241249
@@ -1234,7 +1259,7 @@ public JSONObject put(String key, double value) throws JSONException {
12341259 * If the key is null.
12351260 */
12361261 public JSONObject put (String key , int value ) throws JSONException {
1237- this .put (key , new Integer (value ));
1262+ this .put (key , Integer . valueOf (value ));
12381263 return this ;
12391264 }
12401265
@@ -1250,7 +1275,7 @@ public JSONObject put(String key, int value) throws JSONException {
12501275 * If the key is null.
12511276 */
12521277 public JSONObject put (String key , long value ) throws JSONException {
1253- this .put (key , new Long (value ));
1278+ this .put (key , Long . valueOf (value ));
12541279 return this ;
12551280 }
12561281
@@ -1340,7 +1365,7 @@ public JSONObject putOpt(String key, Object value) throws JSONException {
13401365 }
13411366
13421367 /**
1343- * Creates a JSONPointer using an intialization string and tries to
1368+ * Creates a JSONPointer using an initialization string and tries to
13441369 * match it to an item within this JSONObject. For example, given a
13451370 * JSONObject initialized with this document:
13461371 * <pre>
@@ -1362,7 +1387,7 @@ public Object query(String jsonPointer) {
13621387 return query (new JSONPointer (jsonPointer ));
13631388 }
13641389 /**
1365- * Uses a uaer initialized JSONPointer and tries to
1390+ * Uses a user initialized JSONPointer and tries to
13661391 * match it to an item within this JSONObject. For example, given a
13671392 * JSONObject initialized with this document:
13681393 * <pre>
@@ -1665,7 +1690,7 @@ public String toString() {
16651690 }
16661691
16671692 /**
1668- * Make a prettyprinted JSON text of this JSONObject.
1693+ * Make a pretty-printed JSON text of this JSONObject.
16691694 * <p>
16701695 * Warning: This method assumes that the data structure is acyclical.
16711696 *
@@ -1730,7 +1755,8 @@ public static String valueToString(Object value) throws JSONException {
17301755 final String numberAsString = numberToString ((Number ) value );
17311756 try {
17321757 // Use the BigDecimal constructor for it's parser to validate the format.
1733- new BigDecimal (numberAsString );
1758+ @ SuppressWarnings ("unused" )
1759+ BigDecimal unused = new BigDecimal (numberAsString );
17341760 // Close enough to a JSON number that we will return it unquoted
17351761 return numberAsString ;
17361762 } catch (NumberFormatException ex ){
@@ -1891,7 +1917,7 @@ static final void indent(Writer writer, int indent) throws IOException {
18911917 * @param indentFactor
18921918 * The number of spaces to add to each level of indentation.
18931919 * @param indent
1894- * The indention of the top level.
1920+ * The indentation of the top level.
18951921 * @return The writer.
18961922 * @throws JSONException
18971923 */
0 commit comments