Skip to content

Commit 68de4fe

Browse files
hygiene
1 parent 667813d commit 68de4fe

File tree

2 files changed

+55
-59
lines changed

2 files changed

+55
-59
lines changed

JSONObject.java

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ public JSONObject() {
163163
public JSONObject(JSONObject jo, String[] names) {
164164
this();
165165
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+
}
170170
}
171171
}
172172

@@ -197,9 +197,7 @@ public JSONObject(JSONTokener x) throws JSONException {
197197
key = x.nextValue().toString();
198198
}
199199

200-
/*
201-
* The key is followed by ':'. We will also tolerate '=' or '=>'.
202-
*/
200+
// The key is followed by ':'. We will also tolerate '=' or '=>'.
203201

204202
c = x.nextClean();
205203
if (c == '=') {
@@ -211,9 +209,7 @@ public JSONObject(JSONTokener x) throws JSONException {
211209
}
212210
putOnce(key, x.nextValue());
213211

214-
/*
215-
* Pairs are separated by ','. We will also tolerate ';'.
216-
*/
212+
// Pairs are separated by ','. We will also tolerate ';'.
217213

218214
switch (x.nextClean()) {
219215
case ';':
@@ -247,7 +243,7 @@ public JSONObject(Map map) {
247243
Map.Entry e = (Map.Entry)i.next();
248244
Object value = e.getValue();
249245
if (value != null) {
250-
this.map.put(e.getKey(), wrap(value));
246+
this.map.put(e.getKey(), wrap(value));
251247
}
252248
}
253249
}
@@ -326,33 +322,33 @@ public JSONObject(String source) throws JSONException {
326322
public JSONObject(String baseName, Locale locale) throws JSONException {
327323
this();
328324
ResourceBundle r = ResourceBundle.getBundle(baseName, locale,
329-
Thread.currentThread().getContextClassLoader());
325+
Thread.currentThread().getContextClassLoader());
330326

331327
// Iterate through the keys in the bundle.
332328

333329
Enumeration keys = r.getKeys();
334330
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+
338334
// Go through the path, ensuring that there is a nested JSONObject for each
339335
// segment except the last. Add the value using the last segment's name into
340336
// 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];
347343
JSONObject nextTarget = target.optJSONObject(segment);
348344
if (nextTarget == null) {
349345
nextTarget = new JSONObject();
350346
target.put(segment, nextTarget);
351347
}
352348
target = nextTarget;
353-
}
354-
target.put(path[last], r.getString((String)key));
355-
}
349+
}
350+
target.put(path[last], r.getString((String)key));
351+
}
356352
}
357353
}
358354

@@ -653,23 +649,23 @@ public boolean has(String key) {
653649
* that is not an Integer, Long, Double, or Float.
654650
*/
655651
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;
673669
}
674670

675671

@@ -961,12 +957,12 @@ private void populateMap(Object bean) {
961957
String name = method.getName();
962958
String key = "";
963959
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+
}
970966
} else if (name.startsWith("is")) {
971967
key = name.substring(2);
972968
}
@@ -982,7 +978,7 @@ private void populateMap(Object bean) {
982978

983979
Object result = method.invoke(bean, (Object[])null);
984980
if (result != null) {
985-
map.put(key, wrap(result));
981+
map.put(key, wrap(result));
986982
}
987983
}
988984
}
@@ -1230,7 +1226,7 @@ public Iterator sortedKeys() {
12301226
* @param s A String.
12311227
* @return A simple JSON value.
12321228
*/
1233-
static public Object stringToValue(String s) {
1229+
public static Object stringToValue(String s) {
12341230
if (s.equals("")) {
12351231
return s;
12361232
}
@@ -1264,7 +1260,7 @@ static public Object stringToValue(String s) {
12641260
}
12651261
try {
12661262
if (s.indexOf('.') > -1 ||
1267-
s.indexOf('e') > -1 || s.indexOf('E') > -1) {
1263+
s.indexOf('e') > -1 || s.indexOf('E') > -1) {
12681264
return Double.valueOf(s);
12691265
} else {
12701266
Long myLong = new Long(s);
@@ -1558,8 +1554,8 @@ public static Object wrap(Object object) {
15581554
return NULL;
15591555
}
15601556
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 ||
15631559
object instanceof Short || object instanceof Integer ||
15641560
object instanceof Long || object instanceof Boolean ||
15651561
object instanceof Float || object instanceof Double ||
@@ -1579,8 +1575,8 @@ public static Object wrap(Object object) {
15791575
Package objectPackage = object.getClass().getPackage();
15801576
String objectPackageName = ( objectPackage != null ? objectPackage.getName() : "" );
15811577
if (objectPackageName.startsWith("java.") ||
1582-
objectPackageName.startsWith("javax.") ||
1583-
object.getClass().getClassLoader() == null) {
1578+
objectPackageName.startsWith("javax.") ||
1579+
object.getClass().getClassLoader() == null) {
15841580
return object.toString();
15851581
}
15861582
return new JSONObject(object);

README

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ The package compiles on Java 1.2 thru Java 1.4.
2525

2626

2727
JSONObject.java: The JSONObject can parse text from a String or a JSONTokener
28-
to produce a map-like object. The object provides methods of manipulating its
29-
contents, and for producing a JSON compliant serialization.
28+
to produce a map-like object. The object provides methods for manipulating its
29+
contents, and for producing a JSON compliant object serialization.
3030

3131
JSONArray.java: The JSONObject can parse text from a String or a JSONTokener
32-
to produce a vector-like object. The object provides methods of manipulating
33-
its contents, and for producing a JSON compliant serialization.
32+
to produce a vector-like object. The object provides methods for manipulating
33+
its contents, and for producing a JSON compliant array serialization.
3434

3535
JSONTokenizer.java: The JSONTokener breaks a text into a sequence of individual
36-
tokens. It can be constructed from a String,Reader, or InputStream.
36+
tokens. It can be constructed from a String, Reader, or InputStream.
3737

3838
JSONException.java: The JSONException is the standard exception type thrown
3939
by this package.

0 commit comments

Comments
 (0)