@@ -163,10 +163,10 @@ public JSONObject() {
163
163
public JSONObject (JSONObject jo , String [] names ) {
164
164
this ();
165
165
for (int i = 0 ; i < names .length ; i += 1 ) {
166
- try {
167
- putOnce (names [i ], jo .opt (names [i ]));
168
- } catch (Exception ignore ) {
169
- }
166
+ try {
167
+ putOnce (names [i ], jo .opt (names [i ]));
168
+ } catch (Exception ignore ) {
169
+ }
170
170
}
171
171
}
172
172
@@ -197,9 +197,7 @@ public JSONObject(JSONTokener x) throws JSONException {
197
197
key = x .nextValue ().toString ();
198
198
}
199
199
200
- /*
201
- * The key is followed by ':'. We will also tolerate '=' or '=>'.
202
- */
200
+ // The key is followed by ':'. We will also tolerate '=' or '=>'.
203
201
204
202
c = x .nextClean ();
205
203
if (c == '=' ) {
@@ -211,9 +209,7 @@ public JSONObject(JSONTokener x) throws JSONException {
211
209
}
212
210
putOnce (key , x .nextValue ());
213
211
214
- /*
215
- * Pairs are separated by ','. We will also tolerate ';'.
216
- */
212
+ // Pairs are separated by ','. We will also tolerate ';'.
217
213
218
214
switch (x .nextClean ()) {
219
215
case ';' :
@@ -247,7 +243,7 @@ public JSONObject(Map map) {
247
243
Map .Entry e = (Map .Entry )i .next ();
248
244
Object value = e .getValue ();
249
245
if (value != null ) {
250
- this .map .put (e .getKey (), wrap (value ));
246
+ this .map .put (e .getKey (), wrap (value ));
251
247
}
252
248
}
253
249
}
@@ -326,33 +322,33 @@ public JSONObject(String source) throws JSONException {
326
322
public JSONObject (String baseName , Locale locale ) throws JSONException {
327
323
this ();
328
324
ResourceBundle r = ResourceBundle .getBundle (baseName , locale ,
329
- Thread .currentThread ().getContextClassLoader ());
325
+ Thread .currentThread ().getContextClassLoader ());
330
326
331
327
// Iterate through the keys in the bundle.
332
328
333
329
Enumeration keys = r .getKeys ();
334
330
while (keys .hasMoreElements ()) {
335
- Object key = keys .nextElement ();
336
- if (key instanceof String ) {
337
-
331
+ Object key = keys .nextElement ();
332
+ if (key instanceof String ) {
333
+
338
334
// Go through the path, ensuring that there is a nested JSONObject for each
339
335
// segment except the last. Add the value using the last segment's name into
340
336
// the deepest nested JSONObject.
341
-
342
- String [] path = ((String )key ).split ("\\ ." );
343
- int last = path .length - 1 ;
344
- JSONObject target = this ;
345
- for (int i = 0 ; i < last ; i += 1 ) {
346
- String segment = path [i ];
337
+
338
+ String [] path = ((String )key ).split ("\\ ." );
339
+ int last = path .length - 1 ;
340
+ JSONObject target = this ;
341
+ for (int i = 0 ; i < last ; i += 1 ) {
342
+ String segment = path [i ];
347
343
JSONObject nextTarget = target .optJSONObject (segment );
348
344
if (nextTarget == null ) {
349
345
nextTarget = new JSONObject ();
350
346
target .put (segment , nextTarget );
351
347
}
352
348
target = nextTarget ;
353
- }
354
- target .put (path [last ], r .getString ((String )key ));
355
- }
349
+ }
350
+ target .put (path [last ], r .getString ((String )key ));
351
+ }
356
352
}
357
353
}
358
354
@@ -653,23 +649,23 @@ public boolean has(String key) {
653
649
* that is not an Integer, Long, Double, or Float.
654
650
*/
655
651
public JSONObject increment (String key ) throws JSONException {
656
- Object value = opt (key );
657
- if (value == null ) {
658
- put (key , 1 );
659
- } else {
660
- if (value instanceof Integer ) {
661
- put (key , ((Integer )value ).intValue () + 1 );
662
- } else if (value instanceof Long ) {
663
- put (key , ((Long )value ).longValue () + 1 );
664
- } else if (value instanceof Double ) {
665
- put (key , ((Double )value ).doubleValue () + 1 );
666
- } else if (value instanceof Float ) {
667
- put (key , ((Float )value ).floatValue () + 1 );
668
- } else {
669
- throw new JSONException ("Unable to increment [" + key + "]." );
670
- }
671
- }
672
- return this ;
652
+ Object value = opt (key );
653
+ if (value == null ) {
654
+ put (key , 1 );
655
+ } else {
656
+ if (value instanceof Integer ) {
657
+ put (key , ((Integer )value ).intValue () + 1 );
658
+ } else if (value instanceof Long ) {
659
+ put (key , ((Long )value ).longValue () + 1 );
660
+ } else if (value instanceof Double ) {
661
+ put (key , ((Double )value ).doubleValue () + 1 );
662
+ } else if (value instanceof Float ) {
663
+ put (key , ((Float )value ).floatValue () + 1 );
664
+ } else {
665
+ throw new JSONException ("Unable to increment [" + key + "]." );
666
+ }
667
+ }
668
+ return this ;
673
669
}
674
670
675
671
@@ -961,12 +957,12 @@ private void populateMap(Object bean) {
961
957
String name = method .getName ();
962
958
String key = "" ;
963
959
if (name .startsWith ("get" )) {
964
- if (name .equals ("getClass" ) ||
965
- name .equals ("getDeclaringClass" )) {
966
- key = "" ;
967
- } else {
968
- key = name .substring (3 );
969
- }
960
+ if (name .equals ("getClass" ) ||
961
+ name .equals ("getDeclaringClass" )) {
962
+ key = "" ;
963
+ } else {
964
+ key = name .substring (3 );
965
+ }
970
966
} else if (name .startsWith ("is" )) {
971
967
key = name .substring (2 );
972
968
}
@@ -982,7 +978,7 @@ private void populateMap(Object bean) {
982
978
983
979
Object result = method .invoke (bean , (Object [])null );
984
980
if (result != null ) {
985
- map .put (key , wrap (result ));
981
+ map .put (key , wrap (result ));
986
982
}
987
983
}
988
984
}
@@ -1230,7 +1226,7 @@ public Iterator sortedKeys() {
1230
1226
* @param s A String.
1231
1227
* @return A simple JSON value.
1232
1228
*/
1233
- static public Object stringToValue (String s ) {
1229
+ public static Object stringToValue (String s ) {
1234
1230
if (s .equals ("" )) {
1235
1231
return s ;
1236
1232
}
@@ -1264,7 +1260,7 @@ static public Object stringToValue(String s) {
1264
1260
}
1265
1261
try {
1266
1262
if (s .indexOf ('.' ) > -1 ||
1267
- s .indexOf ('e' ) > -1 || s .indexOf ('E' ) > -1 ) {
1263
+ s .indexOf ('e' ) > -1 || s .indexOf ('E' ) > -1 ) {
1268
1264
return Double .valueOf (s );
1269
1265
} else {
1270
1266
Long myLong = new Long (s );
@@ -1558,8 +1554,8 @@ public static Object wrap(Object object) {
1558
1554
return NULL ;
1559
1555
}
1560
1556
if (object instanceof JSONObject || object instanceof JSONArray ||
1561
- NULL .equals (object ) || object instanceof JSONString ||
1562
- object instanceof Byte || object instanceof Character ||
1557
+ NULL .equals (object ) || object instanceof JSONString ||
1558
+ object instanceof Byte || object instanceof Character ||
1563
1559
object instanceof Short || object instanceof Integer ||
1564
1560
object instanceof Long || object instanceof Boolean ||
1565
1561
object instanceof Float || object instanceof Double ||
@@ -1579,8 +1575,8 @@ public static Object wrap(Object object) {
1579
1575
Package objectPackage = object .getClass ().getPackage ();
1580
1576
String objectPackageName = ( objectPackage != null ? objectPackage .getName () : "" );
1581
1577
if (objectPackageName .startsWith ("java." ) ||
1582
- objectPackageName .startsWith ("javax." ) ||
1583
- object .getClass ().getClassLoader () == null ) {
1578
+ objectPackageName .startsWith ("javax." ) ||
1579
+ object .getClass ().getClassLoader () == null ) {
1584
1580
return object .toString ();
1585
1581
}
1586
1582
return new JSONObject (object );
0 commit comments