From 006ea4d3409b54d9ef84629b8f1955ee6252ff6f Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Thu, 2 May 2013 15:55:30 -0400 Subject: [PATCH] more JSON fixes for API consistency w/ the rest of processing.data.* --- core/src/processing/data/JSONArray.java | 46 +++++++++++++++---------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/core/src/processing/data/JSONArray.java b/core/src/processing/data/JSONArray.java index 6b579108f..349704599 100644 --- a/core/src/processing/data/JSONArray.java +++ b/core/src/processing/data/JSONArray.java @@ -392,6 +392,16 @@ public class JSONArray { } + /** Get this entire array as a String array. */ + public String[] getStringArray() { + String[] outgoing = new String[size()]; + for (int i = 0; i < size(); i++) { + outgoing[i] = getString(i); + } + return outgoing; + } + + /** Get this entire array as an int array. Everything must be an int. */ public int[] getIntArray() { int[] outgoing = new int[size()]; @@ -759,21 +769,6 @@ public class JSONArray { // } - /** - * Put or replace an int value. If the index is greater than the length of - * the JSONArray, then null elements will be added as necessary to pad - * it out. - * @param index The subscript. - * @param value An int value. - * @return this. - * @throws JSONException If the index is negative. - */ - public JSONArray setInt(int index, int value) { - this.set(index, new Integer(value)); - return this; - } - - /** * Put or replace a String value. If the index is greater than the length of * the JSONArray, then null elements will be added as necessary to pad @@ -789,6 +784,21 @@ public class JSONArray { } + /** + * Put or replace an int value. If the index is greater than the length of + * the JSONArray, then null elements will be added as necessary to pad + * it out. + * @param index The subscript. + * @param value An int value. + * @return this. + * @throws JSONException If the index is negative. + */ + public JSONArray setInt(int index, int value) { + this.set(index, new Integer(value)); + return this; + } + + /** * Put or replace a long value. If the index is greater than the length of * the JSONArray, then null elements will be added as necessary to pad @@ -863,13 +873,13 @@ public class JSONArray { // } - public JSONArray setArray(int index, JSONArray value) { + public JSONArray setJSONArray(int index, JSONArray value) { set(index, value); return this; } - public JSONArray setObject(int index, JSONObject value) { + public JSONArray setJSONObject(int index, JSONObject value) { set(index, value); return this; } @@ -931,7 +941,7 @@ public class JSONArray { * @return The value that was associated with the index, * or null if there was no value. */ - public Object removeIndex(int index) { + public Object remove(int index) { Object o = this.opt(index); this.myArrayList.remove(index); return o;