From 6394d92279023dbfbd910ef9ee8895b1899860d5 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Dec 2011 17:31:55 -0800 Subject: [PATCH] optString --- JSONArray.java | 66 +++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) mode change 100755 => 100644 JSONArray.java diff --git a/JSONArray.java b/JSONArray.java old mode 100755 new mode 100644 index 066ea5f..4ae610f --- a/JSONArray.java +++ b/JSONArray.java @@ -76,7 +76,7 @@ import java.util.Map; * * @author JSON.org - * @version 2011-11-24 + * @version 2011-12-19 */ public class JSONArray { @@ -105,29 +105,29 @@ public class JSONArray { throw x.syntaxError("A JSONArray text must start with '['"); } if (x.nextClean() != ']') { - x.back(); - for (;;) { - if (x.nextClean() == ',') { - x.back(); - this.myArrayList.add(JSONObject.NULL); - } else { - x.back(); - this.myArrayList.add(x.nextValue()); - } - switch (x.nextClean()) { - case ';': - case ',': - if (x.nextClean() == ']') { - return; - } - x.back(); - break; - case ']': - return; - default: - throw x.syntaxError("Expected a ',' or ']'"); - } - } + x.back(); + for (;;) { + if (x.nextClean() == ',') { + x.back(); + this.myArrayList.add(JSONObject.NULL); + } else { + x.back(); + this.myArrayList.add(x.nextValue()); + } + switch (x.nextClean()) { + case ';': + case ',': + if (x.nextClean() == ']') { + return; + } + x.back(); + break; + case ']': + return; + default: + throw x.syntaxError("Expected a ',' or ']'"); + } + } } } @@ -149,13 +149,13 @@ public class JSONArray { * @param collection A Collection. */ public JSONArray(Collection collection) { - this.myArrayList = new ArrayList(); - if (collection != null) { - Iterator iter = collection.iterator(); - while (iter.hasNext()) { + this.myArrayList = new ArrayList(); + if (collection != null) { + Iterator iter = collection.iterator(); + while (iter.hasNext()) { this.myArrayList.add(JSONObject.wrap(iter.next())); - } - } + } + } } @@ -555,8 +555,8 @@ public class JSONArray { public String optString(int index, String defaultValue) { Object object = this.opt(index); return JSONObject.NULL.equals(object) - ? object.toString() - : defaultValue; + ? defaultValue + : object.toString(); } @@ -775,7 +775,7 @@ public class JSONArray { * or null if there was no value. */ public Object remove(int index) { - Object o = this.opt(index); + Object o = this.opt(index); this.myArrayList.remove(index); return o; }