propane 3.1.0.pre-java → 3.2.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/CHANGELOG.md +1 -5
- data/README.md +23 -12
- data/Rakefile +23 -12
- data/lib/propane/helpers/version_error.rb +6 -0
- data/lib/propane/runner.rb +12 -0
- data/lib/propane/version.rb +1 -1
- data/library/slider/slider.rb +1 -1
- data/mvnw +234 -0
- data/mvnw.cmd +145 -0
- data/pom.xml +28 -27
- data/propane.gemspec +2 -2
- data/src/main/java/japplemenubar/JAppleMenuBar.java +41 -47
- data/src/main/java/monkstone/ColorUtil.java +1 -1
- data/src/main/java/monkstone/MathToolModule.java +12 -11
- data/src/main/java/monkstone/PropaneLibrary.java +9 -10
- data/src/main/java/monkstone/core/LibraryProxy.java +124 -113
- data/src/main/java/monkstone/fastmath/Deglut.java +86 -89
- data/src/main/java/monkstone/filechooser/Chooser.java +7 -13
- data/src/main/java/monkstone/noise/SimplexNoise.java +0 -1
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +4 -4
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +9 -9
- data/src/main/java/monkstone/slider/SimpleSlider.java +0 -9
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +11 -13
- data/src/main/java/monkstone/slider/Slider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +8 -9
- data/src/main/java/monkstone/vecmath/AppRender.java +2 -2
- data/src/main/java/monkstone/vecmath/ShapeRender.java +2 -2
- data/src/main/java/monkstone/vecmath/package-info.java +2 -2
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- data/src/main/java/monkstone/videoevent/VideoInterface.java +11 -5
- data/src/main/java/monkstone/videoevent/package-info.java +2 -2
- data/src/main/java/processing/awt/PGraphicsJava2D.java +1742 -2243
- data/src/main/java/processing/awt/PShapeJava2D.java +268 -270
- data/src/main/java/processing/awt/PSurfaceAWT.java +821 -920
- data/src/main/java/processing/core/DesktopHandler.java +94 -0
- data/src/main/java/processing/core/PApplet.java +14170 -14082
- data/src/main/java/processing/core/PConstants.java +447 -473
- data/src/main/java/processing/core/PFont.java +867 -873
- data/src/main/java/processing/core/PGraphics.java +7193 -7428
- data/src/main/java/processing/core/PImage.java +3051 -3117
- data/src/main/java/processing/core/PMatrix.java +159 -172
- data/src/main/java/processing/core/PMatrix2D.java +403 -444
- data/src/main/java/processing/core/PMatrix3D.java +735 -749
- data/src/main/java/processing/core/PShape.java +2651 -2793
- data/src/main/java/processing/core/PShapeOBJ.java +415 -422
- data/src/main/java/processing/core/PShapeSVG.java +1466 -1475
- data/src/main/java/processing/core/PStyle.java +37 -40
- data/src/main/java/processing/core/PSurface.java +98 -103
- data/src/main/java/processing/core/PSurfaceNone.java +208 -236
- data/src/main/java/processing/core/PVector.java +961 -990
- data/src/main/java/processing/data/DoubleDict.java +709 -753
- data/src/main/java/processing/data/DoubleList.java +695 -748
- data/src/main/java/processing/data/FloatDict.java +702 -746
- data/src/main/java/processing/data/FloatList.java +697 -751
- data/src/main/java/processing/data/IntDict.java +673 -718
- data/src/main/java/processing/data/IntList.java +633 -699
- data/src/main/java/processing/data/JSONArray.java +873 -931
- data/src/main/java/processing/data/JSONObject.java +1165 -1262
- data/src/main/java/processing/data/JSONTokener.java +341 -351
- data/src/main/java/processing/data/LongDict.java +662 -707
- data/src/main/java/processing/data/LongList.java +634 -700
- data/src/main/java/processing/data/Sort.java +41 -37
- data/src/main/java/processing/data/StringDict.java +486 -522
- data/src/main/java/processing/data/StringList.java +580 -624
- data/src/main/java/processing/data/Table.java +3508 -3686
- data/src/main/java/processing/data/TableRow.java +183 -182
- data/src/main/java/processing/data/XML.java +883 -957
- data/src/main/java/processing/event/Event.java +66 -87
- data/src/main/java/processing/event/KeyEvent.java +41 -48
- data/src/main/java/processing/event/MouseEvent.java +93 -103
- data/src/main/java/processing/event/TouchEvent.java +6 -10
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +5 -69
- data/src/main/java/processing/javafx/PSurfaceFX.java +2 -7
- data/src/main/java/processing/opengl/FontTexture.java +270 -290
- data/src/main/java/processing/opengl/FrameBuffer.java +363 -375
- data/src/main/java/processing/opengl/LinePath.java +500 -543
- data/src/main/java/processing/opengl/LineStroker.java +582 -593
- data/src/main/java/processing/opengl/PGL.java +2881 -2904
- data/src/main/java/processing/opengl/PGraphics2D.java +315 -408
- data/src/main/java/processing/opengl/PGraphics3D.java +72 -107
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12043 -12230
- data/src/main/java/processing/opengl/PJOGL.java +1681 -1745
- data/src/main/java/processing/opengl/PShader.java +1257 -1260
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4599 -4662
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1030 -1047
- data/src/main/java/processing/opengl/Texture.java +1397 -1462
- data/src/main/java/processing/opengl/VertexBuffer.java +55 -57
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/vendors/Rakefile +1 -1
- metadata +12 -8
- data/src/main/java/processing/core/ThinkDifferent.java +0 -70
|
@@ -33,7 +33,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
33
33
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
34
34
|
SOFTWARE.
|
|
35
35
|
*/
|
|
36
|
-
|
|
37
36
|
import java.io.File;
|
|
38
37
|
import java.io.IOException;
|
|
39
38
|
import java.io.PrintWriter;
|
|
@@ -99,116 +98,109 @@ import processing.core.PApplet;
|
|
|
99
98
|
*/
|
|
100
99
|
public class JSONArray {
|
|
101
100
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
this.myArrayList = new ArrayList<>();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* @nowebref
|
|
118
|
-
*/
|
|
119
|
-
public JSONArray(Reader reader) {
|
|
120
|
-
this(new JSONTokener(reader));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Construct a JSONArray from a JSONTokener.
|
|
126
|
-
*
|
|
127
|
-
* @param x A JSONTokener
|
|
128
|
-
* @throws RuntimeException If there is a syntax error.
|
|
129
|
-
* @nowebref
|
|
130
|
-
*/
|
|
131
|
-
protected JSONArray(JSONTokener x) {
|
|
132
|
-
this();
|
|
133
|
-
if (x.nextClean() != '[') {
|
|
134
|
-
throw new RuntimeException("A JSONArray text must start with '['");
|
|
101
|
+
/**
|
|
102
|
+
* The arrayList where the JSONArray's properties are kept.
|
|
103
|
+
*/
|
|
104
|
+
private final ArrayList<Object> myArrayList;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Construct an empty JSONArray.
|
|
108
|
+
*/
|
|
109
|
+
public JSONArray() {
|
|
110
|
+
this.myArrayList = new ArrayList<>();
|
|
135
111
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @nowebref
|
|
115
|
+
*/
|
|
116
|
+
public JSONArray(Reader reader) {
|
|
117
|
+
this(new JSONTokener(reader));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Construct a JSONArray from a JSONTokener.
|
|
122
|
+
*
|
|
123
|
+
* @param x A JSONTokener
|
|
124
|
+
* @throws RuntimeException If there is a syntax error.
|
|
125
|
+
* @nowebref
|
|
126
|
+
*/
|
|
127
|
+
protected JSONArray(JSONTokener x) {
|
|
128
|
+
this();
|
|
129
|
+
if (x.nextClean() != '[') {
|
|
130
|
+
throw new RuntimeException("A JSONArray text must start with '['");
|
|
145
131
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
132
|
+
if (x.nextClean() != ']') {
|
|
133
|
+
x.back();
|
|
134
|
+
for (;;) {
|
|
135
|
+
if (x.nextClean() == ',') {
|
|
136
|
+
x.back();
|
|
137
|
+
myArrayList.add(JSONObject.NULL);
|
|
138
|
+
} else {
|
|
139
|
+
x.back();
|
|
140
|
+
myArrayList.add(x.nextValue());
|
|
141
|
+
}
|
|
142
|
+
switch (x.nextClean()) {
|
|
143
|
+
case ';':
|
|
144
|
+
case ',':
|
|
145
|
+
if (x.nextClean() == ']') {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
x.back();
|
|
149
|
+
break;
|
|
150
|
+
case ']':
|
|
151
|
+
return;
|
|
152
|
+
default:
|
|
153
|
+
throw new RuntimeException("Expected a ',' or ']'");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
158
156
|
}
|
|
159
|
-
}
|
|
160
157
|
}
|
|
161
|
-
}
|
|
162
158
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
/**
|
|
160
|
+
* @nowebref
|
|
161
|
+
*/
|
|
162
|
+
public JSONArray(IntList list) {
|
|
163
|
+
myArrayList = new ArrayList<>();
|
|
164
|
+
for (int item : list.values()) {
|
|
165
|
+
myArrayList.add(Integer.valueOf(item));
|
|
166
|
+
}
|
|
171
167
|
}
|
|
172
|
-
}
|
|
173
168
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
169
|
+
/**
|
|
170
|
+
* @nowebref
|
|
171
|
+
*/
|
|
172
|
+
public JSONArray(FloatList list) {
|
|
173
|
+
myArrayList = new ArrayList<>();
|
|
174
|
+
for (float item : list.values()) {
|
|
175
|
+
myArrayList.add(Float.valueOf(item));
|
|
176
|
+
}
|
|
182
177
|
}
|
|
183
|
-
}
|
|
184
178
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Construct a JSONArray from a source JSON text.
|
|
199
|
-
* @param source A string that begins with
|
|
200
|
-
* <code>[</code> <small>(left bracket)</small>
|
|
201
|
-
* and ends with <code>]</code> <small>(right bracket)</small>.
|
|
202
|
-
* @return {@code null} if there is a syntax error.
|
|
203
|
-
*/
|
|
204
|
-
static public JSONArray parse(String source) {
|
|
205
|
-
try {
|
|
206
|
-
return new JSONArray(new JSONTokener(source));
|
|
207
|
-
} catch (Exception e) {
|
|
208
|
-
return null;
|
|
179
|
+
/**
|
|
180
|
+
* @nowebref
|
|
181
|
+
*/
|
|
182
|
+
public JSONArray(StringList list) {
|
|
183
|
+
myArrayList = new ArrayList<>();
|
|
184
|
+
for (String item : list.values()) {
|
|
185
|
+
myArrayList.add(item);
|
|
186
|
+
}
|
|
209
187
|
}
|
|
210
|
-
}
|
|
211
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Construct a JSONArray from a source JSON text.
|
|
191
|
+
*
|
|
192
|
+
* @param source A string that begins with <code>[</code> <small>(left
|
|
193
|
+
* bracket)</small>
|
|
194
|
+
* and ends with <code>]</code> <small>(right bracket)</small>.
|
|
195
|
+
* @return {@code null} if there is a syntax error.
|
|
196
|
+
*/
|
|
197
|
+
static public JSONArray parse(String source) {
|
|
198
|
+
try {
|
|
199
|
+
return new JSONArray(new JSONTokener(source));
|
|
200
|
+
} catch (Exception e) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
212
204
|
|
|
213
205
|
// /**
|
|
214
206
|
// * Construct a JSONArray from a Collection.
|
|
@@ -223,411 +215,397 @@ public class JSONArray {
|
|
|
223
215
|
// }
|
|
224
216
|
// }
|
|
225
217
|
// }
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Get the optional object value associated with an index.
|
|
248
|
-
* @param index must be between 0 and length() - 1
|
|
249
|
-
* @return An object value, or null if there is no
|
|
250
|
-
* object at that index.
|
|
251
|
-
*/
|
|
252
|
-
private Object opt(int index) {
|
|
253
|
-
if (index < 0 || index >= this.size()) {
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
return myArrayList.get(index);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Get the object value associated with an index.
|
|
262
|
-
* @param index must be between 0 and length() - 1
|
|
263
|
-
* @return An object value.
|
|
264
|
-
* @throws RuntimeException If there is no value for the index.
|
|
265
|
-
*/
|
|
266
|
-
public Object get(int index) {
|
|
267
|
-
Object object = opt(index);
|
|
268
|
-
if (object == null) {
|
|
269
|
-
throw new RuntimeException("JSONArray[" + index + "] not found.");
|
|
270
|
-
}
|
|
271
|
-
return object;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Get the string associated with an index.
|
|
277
|
-
*
|
|
278
|
-
* @webref jsonarray:method
|
|
279
|
-
* @brief Gets the String value associated with an index
|
|
280
|
-
* @param index must be between 0 and length() - 1
|
|
281
|
-
* @return A string value.
|
|
282
|
-
* @throws RuntimeException If there is no string value for the index.
|
|
283
|
-
* @see JSONArray#getInt(int)
|
|
284
|
-
* @see JSONArray#getFloat(int)
|
|
285
|
-
* @see JSONArray#getBoolean(int)
|
|
286
|
-
*/
|
|
287
|
-
public String getString(int index) {
|
|
288
|
-
Object object = this.get(index);
|
|
289
|
-
if (object instanceof String) {
|
|
290
|
-
return (String)object;
|
|
291
|
-
}
|
|
292
|
-
throw new RuntimeException("JSONArray[" + index + "] not a string.");
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
/**
|
|
297
|
-
* Get the optional string associated with an index.
|
|
298
|
-
* The defaultValue is returned if the key is not found.
|
|
299
|
-
*
|
|
300
|
-
* @param index The index must be between 0 and length() - 1.
|
|
301
|
-
* @param defaultValue The default value.
|
|
302
|
-
* @return A String value.
|
|
303
|
-
*/
|
|
304
|
-
public String getString(int index, String defaultValue) {
|
|
305
|
-
Object object = this.opt(index);
|
|
306
|
-
return JSONObject.NULL.equals(object) ? defaultValue : object.toString();
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Get the int value associated with an index.
|
|
312
|
-
*
|
|
313
|
-
* @webref jsonarray:method
|
|
314
|
-
* @brief Gets the int value associated with an index
|
|
315
|
-
* @param index must be between 0 and length() - 1
|
|
316
|
-
* @return The value.
|
|
317
|
-
* @throws RuntimeException If the key is not found or if the value is not a number.
|
|
318
|
-
* @see JSONArray#getFloat(int)
|
|
319
|
-
* @see JSONArray#getString(int)
|
|
320
|
-
* @see JSONArray#getBoolean(int)
|
|
321
|
-
*/
|
|
322
|
-
public int getInt(int index) {
|
|
323
|
-
Object object = this.get(index);
|
|
324
|
-
try {
|
|
325
|
-
return object instanceof Number
|
|
326
|
-
? ((Number)object).intValue()
|
|
327
|
-
: Integer.parseInt((String)object);
|
|
328
|
-
} catch (Exception e) {
|
|
329
|
-
throw new RuntimeException("JSONArray[" + index + "] is not a number.");
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* Get the optional int value associated with an index.
|
|
336
|
-
* The defaultValue is returned if there is no value for the index,
|
|
337
|
-
* or if the value is not a number and cannot be converted to a number.
|
|
338
|
-
* @param index The index must be between 0 and length() - 1.
|
|
339
|
-
* @param defaultValue The default value.
|
|
340
|
-
* @return The value.
|
|
341
|
-
*/
|
|
342
|
-
public int getInt(int index, int defaultValue) {
|
|
343
|
-
try {
|
|
344
|
-
return getInt(index);
|
|
345
|
-
} catch (Exception e) {
|
|
346
|
-
return defaultValue;
|
|
218
|
+
// TODO not decided whether we keep this one, but used heavily by JSONObject
|
|
219
|
+
/**
|
|
220
|
+
* Construct a JSONArray from an array
|
|
221
|
+
*
|
|
222
|
+
* @throws RuntimeException If not an array.
|
|
223
|
+
*/
|
|
224
|
+
protected JSONArray(Object array) {
|
|
225
|
+
this();
|
|
226
|
+
if (array.getClass().isArray()) {
|
|
227
|
+
int length = Array.getLength(array);
|
|
228
|
+
for (int i = 0; i < length; i += 1) {
|
|
229
|
+
this.append(JSONObject.wrap(Array.get(array, i)));
|
|
230
|
+
}
|
|
231
|
+
} else {
|
|
232
|
+
throw new RuntimeException("JSONArray initial value should be a string or collection or array.");
|
|
233
|
+
}
|
|
347
234
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
Object object = this.get(index);
|
|
361
|
-
try {
|
|
362
|
-
return object instanceof Number
|
|
363
|
-
? ((Number)object).longValue()
|
|
364
|
-
: Long.parseLong((String)object);
|
|
365
|
-
} catch (Exception e) {
|
|
366
|
-
throw new RuntimeException("JSONArray[" + index + "] is not a number.");
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Get the optional object value associated with an index.
|
|
238
|
+
*
|
|
239
|
+
* @param index must be between 0 and length() - 1
|
|
240
|
+
* @return An object value, or null if there is no object at that index.
|
|
241
|
+
*/
|
|
242
|
+
private Object opt(int index) {
|
|
243
|
+
if (index < 0 || index >= this.size()) {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
return myArrayList.get(index);
|
|
367
247
|
}
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
} catch (Exception e) {
|
|
383
|
-
return defaultValue;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Get the object value associated with an index.
|
|
251
|
+
*
|
|
252
|
+
* @param index must be between 0 and length() - 1
|
|
253
|
+
* @return An object value.
|
|
254
|
+
* @throws RuntimeException If there is no value for the index.
|
|
255
|
+
*/
|
|
256
|
+
public Object get(int index) {
|
|
257
|
+
Object object = opt(index);
|
|
258
|
+
if (object == null) {
|
|
259
|
+
throw new RuntimeException("JSONArray[" + index + "] not found.");
|
|
260
|
+
}
|
|
261
|
+
return object;
|
|
384
262
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
public float getFloat(int index, float defaultValue) {
|
|
405
|
-
try {
|
|
406
|
-
return getFloat(index);
|
|
407
|
-
} catch (Exception e) {
|
|
408
|
-
return defaultValue;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Get the string associated with an index.
|
|
266
|
+
*
|
|
267
|
+
* @webref jsonarray:method
|
|
268
|
+
* @brief Gets the String value associated with an index
|
|
269
|
+
* @param index must be between 0 and length() - 1
|
|
270
|
+
* @return A string value.
|
|
271
|
+
* @throws RuntimeException If there is no string value for the index.
|
|
272
|
+
* @see JSONArray#getInt(int)
|
|
273
|
+
* @see JSONArray#getFloat(int)
|
|
274
|
+
* @see JSONArray#getBoolean(int)
|
|
275
|
+
*/
|
|
276
|
+
public String getString(int index) {
|
|
277
|
+
Object object = this.get(index);
|
|
278
|
+
if (object instanceof String) {
|
|
279
|
+
return (String) object;
|
|
280
|
+
}
|
|
281
|
+
throw new RuntimeException("JSONArray[" + index + "] not a string.");
|
|
409
282
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
Object object = this.get(index);
|
|
423
|
-
try {
|
|
424
|
-
return object instanceof Number
|
|
425
|
-
? ((Number)object).doubleValue()
|
|
426
|
-
: Double.parseDouble((String)object);
|
|
427
|
-
} catch (Exception e) {
|
|
428
|
-
throw new RuntimeException("JSONArray[" + index + "] is not a number.");
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Get the optional string associated with an index. The defaultValue is
|
|
286
|
+
* returned if the key is not found.
|
|
287
|
+
*
|
|
288
|
+
* @param index The index must be between 0 and length() - 1.
|
|
289
|
+
* @param defaultValue The default value.
|
|
290
|
+
* @return A String value.
|
|
291
|
+
*/
|
|
292
|
+
public String getString(int index, String defaultValue) {
|
|
293
|
+
Object object = this.opt(index);
|
|
294
|
+
return JSONObject.NULL.equals(object) ? defaultValue : object.toString();
|
|
429
295
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Get the int value associated with an index.
|
|
299
|
+
*
|
|
300
|
+
* @webref jsonarray:method
|
|
301
|
+
* @brief Gets the int value associated with an index
|
|
302
|
+
* @param index must be between 0 and length() - 1
|
|
303
|
+
* @return The value.
|
|
304
|
+
* @throws RuntimeException If the key is not found or if the value is not a
|
|
305
|
+
* number.
|
|
306
|
+
* @see JSONArray#getFloat(int)
|
|
307
|
+
* @see JSONArray#getString(int)
|
|
308
|
+
* @see JSONArray#getBoolean(int)
|
|
309
|
+
*/
|
|
310
|
+
public int getInt(int index) {
|
|
311
|
+
Object object = this.get(index);
|
|
312
|
+
try {
|
|
313
|
+
return object instanceof Number
|
|
314
|
+
? ((Number) object).intValue()
|
|
315
|
+
: Integer.parseInt((String) object);
|
|
316
|
+
} catch (Exception e) {
|
|
317
|
+
throw new RuntimeException("JSONArray[" + index + "] is not a number.");
|
|
318
|
+
}
|
|
447
319
|
}
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
*/
|
|
465
|
-
public boolean getBoolean(int index) {
|
|
466
|
-
Object object = this.get(index);
|
|
467
|
-
if (object.equals(Boolean.FALSE) ||
|
|
468
|
-
(object instanceof String &&
|
|
469
|
-
((String)object).equalsIgnoreCase("false"))) {
|
|
470
|
-
return false;
|
|
471
|
-
} else if (object.equals(Boolean.TRUE) ||
|
|
472
|
-
(object instanceof String &&
|
|
473
|
-
((String)object).equalsIgnoreCase("true"))) {
|
|
474
|
-
return true;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Get the optional int value associated with an index. The defaultValue is
|
|
323
|
+
* returned if there is no value for the index, or if the value is not a
|
|
324
|
+
* number and cannot be converted to a number.
|
|
325
|
+
*
|
|
326
|
+
* @param index The index must be between 0 and length() - 1.
|
|
327
|
+
* @param defaultValue The default value.
|
|
328
|
+
* @return The value.
|
|
329
|
+
*/
|
|
330
|
+
public int getInt(int index, int defaultValue) {
|
|
331
|
+
try {
|
|
332
|
+
return getInt(index);
|
|
333
|
+
} catch (Exception e) {
|
|
334
|
+
return defaultValue;
|
|
335
|
+
}
|
|
475
336
|
}
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Get the long value associated with an index.
|
|
340
|
+
*
|
|
341
|
+
* @param index The index must be between 0 and length() - 1
|
|
342
|
+
* @return The value.
|
|
343
|
+
* @throws RuntimeException If the key is not found or if the value cannot
|
|
344
|
+
* be converted to a number.
|
|
345
|
+
*/
|
|
346
|
+
public long getLong(int index) {
|
|
347
|
+
Object object = this.get(index);
|
|
348
|
+
try {
|
|
349
|
+
return object instanceof Number
|
|
350
|
+
? ((Number) object).longValue()
|
|
351
|
+
: Long.parseLong((String) object);
|
|
352
|
+
} catch (Exception e) {
|
|
353
|
+
throw new RuntimeException("JSONArray[" + index + "] is not a number.");
|
|
354
|
+
}
|
|
494
355
|
}
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
public JSONArray getJSONArray(int index) {
|
|
512
|
-
Object object = this.get(index);
|
|
513
|
-
if (object instanceof JSONArray) {
|
|
514
|
-
return (JSONArray)object;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Get the optional long value associated with an index. The defaultValue is
|
|
359
|
+
* returned if there is no value for the index, or if the value is not a
|
|
360
|
+
* number and cannot be converted to a number.
|
|
361
|
+
*
|
|
362
|
+
* @param index The index must be between 0 and length() - 1.
|
|
363
|
+
* @param defaultValue The default value.
|
|
364
|
+
* @return The value.
|
|
365
|
+
*/
|
|
366
|
+
public long getLong(int index, long defaultValue) {
|
|
367
|
+
try {
|
|
368
|
+
return this.getLong(index);
|
|
369
|
+
} catch (Exception e) {
|
|
370
|
+
return defaultValue;
|
|
371
|
+
}
|
|
515
372
|
}
|
|
516
|
-
throw new RuntimeException("JSONArray[" + index + "] is not a JSONArray.");
|
|
517
|
-
}
|
|
518
373
|
|
|
374
|
+
/**
|
|
375
|
+
* Get a value from an index as a float. JSON uses 'double' values
|
|
376
|
+
* internally, so this is simply getDouble() cast to a float.
|
|
377
|
+
*
|
|
378
|
+
* @webref jsonarray:method
|
|
379
|
+
* @brief Gets the float value associated with an index
|
|
380
|
+
* @param index must be between 0 and length() - 1
|
|
381
|
+
* @see JSONArray#getInt(int)
|
|
382
|
+
* @see JSONArray#getString(int)
|
|
383
|
+
* @see JSONArray#getBoolean(int)
|
|
384
|
+
*/
|
|
385
|
+
public float getFloat(int index) {
|
|
386
|
+
return (float) getDouble(index);
|
|
387
|
+
}
|
|
519
388
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
389
|
+
public float getFloat(int index, float defaultValue) {
|
|
390
|
+
try {
|
|
391
|
+
return getFloat(index);
|
|
392
|
+
} catch (Exception e) {
|
|
393
|
+
return defaultValue;
|
|
394
|
+
}
|
|
525
395
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
if (object instanceof JSONObject) {
|
|
545
|
-
return (JSONObject)object;
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Get the double value associated with an index.
|
|
399
|
+
*
|
|
400
|
+
* @param index must be between 0 and length() - 1
|
|
401
|
+
* @return The value.
|
|
402
|
+
* @throws RuntimeException If the key is not found or if the value cannot
|
|
403
|
+
* be converted to a number.
|
|
404
|
+
*/
|
|
405
|
+
public double getDouble(int index) {
|
|
406
|
+
Object object = this.get(index);
|
|
407
|
+
try {
|
|
408
|
+
return object instanceof Number
|
|
409
|
+
? ((Number) object).doubleValue()
|
|
410
|
+
: Double.parseDouble((String) object);
|
|
411
|
+
} catch (Exception e) {
|
|
412
|
+
throw new RuntimeException("JSONArray[" + index + "] is not a number.");
|
|
413
|
+
}
|
|
546
414
|
}
|
|
547
|
-
throw new RuntimeException("JSONArray[" + index + "] is not a JSONObject.");
|
|
548
|
-
}
|
|
549
415
|
|
|
416
|
+
/**
|
|
417
|
+
* Get the optional double value associated with an index. The defaultValue
|
|
418
|
+
* is returned if there is no value for the index, or if the value is not a
|
|
419
|
+
* number and cannot be converted to a number.
|
|
420
|
+
*
|
|
421
|
+
* @param index subscript
|
|
422
|
+
* @param defaultValue The default value.
|
|
423
|
+
* @return The value.
|
|
424
|
+
*/
|
|
425
|
+
public double getDouble(int index, double defaultValue) {
|
|
426
|
+
try {
|
|
427
|
+
return this.getDouble(index);
|
|
428
|
+
} catch (Exception e) {
|
|
429
|
+
return defaultValue;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
550
432
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
433
|
+
/**
|
|
434
|
+
* Get the boolean value associated with an index. The string values "true"
|
|
435
|
+
* and "false" are converted to boolean.
|
|
436
|
+
*
|
|
437
|
+
* @webref jsonarray:method
|
|
438
|
+
* @brief Gets the boolean value associated with an index
|
|
439
|
+
* @param index must be between 0 and length() - 1
|
|
440
|
+
* @return The truth.
|
|
441
|
+
* @throws RuntimeException If there is no value for the index or if the
|
|
442
|
+
* value is not convertible to boolean.
|
|
443
|
+
* @see JSONArray#getInt(int)
|
|
444
|
+
* @see JSONArray#getFloat(int)
|
|
445
|
+
* @see JSONArray#getString(int)
|
|
446
|
+
*/
|
|
447
|
+
public boolean getBoolean(int index) {
|
|
448
|
+
Object object = this.get(index);
|
|
449
|
+
if (object.equals(Boolean.FALSE)
|
|
450
|
+
|| (object instanceof String
|
|
451
|
+
&& ((String) object).equalsIgnoreCase("false"))) {
|
|
452
|
+
return false;
|
|
453
|
+
} else if (object.equals(Boolean.TRUE)
|
|
454
|
+
|| (object instanceof String
|
|
455
|
+
&& ((String) object).equalsIgnoreCase("true"))) {
|
|
456
|
+
return true;
|
|
457
|
+
}
|
|
458
|
+
throw new RuntimeException("JSONArray[" + index + "] is not a boolean.");
|
|
556
459
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Get the optional boolean value associated with an index. It returns the
|
|
463
|
+
* defaultValue if there is no value at that index or if it is not a Boolean
|
|
464
|
+
* or the String "true" or "false" (case insensitive).
|
|
465
|
+
*
|
|
466
|
+
* @param index The index must be between 0 and length() - 1.
|
|
467
|
+
* @param defaultValue A boolean default.
|
|
468
|
+
* @return The truth.
|
|
469
|
+
*/
|
|
470
|
+
public boolean getBoolean(int index, boolean defaultValue) {
|
|
471
|
+
try {
|
|
472
|
+
return getBoolean(index);
|
|
473
|
+
} catch (Exception e) {
|
|
474
|
+
return defaultValue;
|
|
475
|
+
}
|
|
571
476
|
}
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Get the JSONArray associated with an index.
|
|
480
|
+
*
|
|
481
|
+
* @webref jsonobject:method
|
|
482
|
+
* @brief Gets the JSONArray associated with an index value
|
|
483
|
+
* @param index must be between 0 and length() - 1
|
|
484
|
+
* @return A JSONArray value.
|
|
485
|
+
* @throws RuntimeException If there is no value for the index. or if the
|
|
486
|
+
* value is not a JSONArray
|
|
487
|
+
* @see JSONArray#getJSONObject(int)
|
|
488
|
+
* @see JSONArray#setJSONObject(int, JSONObject)
|
|
489
|
+
* @see JSONArray#setJSONArray(int, JSONArray)
|
|
490
|
+
*/
|
|
491
|
+
public JSONArray getJSONArray(int index) {
|
|
492
|
+
Object object = this.get(index);
|
|
493
|
+
if (object instanceof JSONArray) {
|
|
494
|
+
return (JSONArray) object;
|
|
495
|
+
}
|
|
496
|
+
throw new RuntimeException("JSONArray[" + index + "] is not a JSONArray.");
|
|
587
497
|
}
|
|
588
|
-
return outgoing;
|
|
589
|
-
}
|
|
590
498
|
|
|
499
|
+
public JSONArray getJSONArray(int index, JSONArray defaultValue) {
|
|
500
|
+
try {
|
|
501
|
+
return getJSONArray(index);
|
|
502
|
+
} catch (Exception e) {
|
|
503
|
+
return defaultValue;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
591
506
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
507
|
+
/**
|
|
508
|
+
* Get the JSONObject associated with an index.
|
|
509
|
+
*
|
|
510
|
+
* @webref jsonobject:method
|
|
511
|
+
* @brief Gets the JSONObject associated with an index value
|
|
512
|
+
* @param index the index value of the object to get
|
|
513
|
+
* @return A JSONObject value.
|
|
514
|
+
* @throws RuntimeException If there is no value for the index or if the
|
|
515
|
+
* value is not a JSONObject
|
|
516
|
+
* @see JSONArray#getJSONArray(int)
|
|
517
|
+
* @see JSONArray#setJSONObject(int, JSONObject)
|
|
518
|
+
* @see JSONArray#setJSONArray(int, JSONArray)
|
|
519
|
+
*/
|
|
520
|
+
public JSONObject getJSONObject(int index) {
|
|
521
|
+
Object object = this.get(index);
|
|
522
|
+
if (object instanceof JSONObject) {
|
|
523
|
+
return (JSONObject) object;
|
|
524
|
+
}
|
|
525
|
+
throw new RuntimeException("JSONArray[" + index + "] is not a JSONObject.");
|
|
597
526
|
}
|
|
598
|
-
return outgoing;
|
|
599
|
-
}
|
|
600
527
|
|
|
528
|
+
public JSONObject getJSONObject(int index, JSONObject defaultValue) {
|
|
529
|
+
try {
|
|
530
|
+
return getJSONObject(index);
|
|
531
|
+
} catch (Exception e) {
|
|
532
|
+
return defaultValue;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
601
535
|
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
536
|
+
/**
|
|
537
|
+
* Get this entire array as a String array.
|
|
538
|
+
*
|
|
539
|
+
* @webref jsonarray:method
|
|
540
|
+
* @brief Gets the entire array as an array of Strings
|
|
541
|
+
* @see JSONArray#getIntArray()
|
|
542
|
+
*/
|
|
543
|
+
public String[] getStringArray() {
|
|
544
|
+
String[] outgoing = new String[size()];
|
|
545
|
+
for (int i = 0; i < size(); i++) {
|
|
546
|
+
outgoing[i] = getString(i);
|
|
547
|
+
}
|
|
548
|
+
return outgoing;
|
|
607
549
|
}
|
|
608
|
-
return outgoing;
|
|
609
|
-
}
|
|
610
550
|
|
|
551
|
+
/**
|
|
552
|
+
* Get this entire array as an int array. Everything must be an int.
|
|
553
|
+
*
|
|
554
|
+
* @webref jsonarray:method
|
|
555
|
+
* @brief Gets the entire array as array of ints
|
|
556
|
+
* @see JSONArray#getStringArray()
|
|
557
|
+
*/
|
|
558
|
+
public int[] getIntArray() {
|
|
559
|
+
int[] outgoing = new int[size()];
|
|
560
|
+
for (int i = 0; i < size(); i++) {
|
|
561
|
+
outgoing[i] = getInt(i);
|
|
562
|
+
}
|
|
563
|
+
return outgoing;
|
|
564
|
+
}
|
|
611
565
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
566
|
+
/**
|
|
567
|
+
* Get this entire array as a long array. Everything must be an long.
|
|
568
|
+
*/
|
|
569
|
+
public long[] getLongArray() {
|
|
570
|
+
long[] outgoing = new long[size()];
|
|
571
|
+
for (int i = 0; i < size(); i++) {
|
|
572
|
+
outgoing[i] = getLong(i);
|
|
573
|
+
}
|
|
574
|
+
return outgoing;
|
|
617
575
|
}
|
|
618
|
-
return outgoing;
|
|
619
|
-
}
|
|
620
576
|
|
|
577
|
+
/**
|
|
578
|
+
* Get this entire array as a float array. Everything must be an float.
|
|
579
|
+
*/
|
|
580
|
+
public float[] getFloatArray() {
|
|
581
|
+
float[] outgoing = new float[size()];
|
|
582
|
+
for (int i = 0; i < size(); i++) {
|
|
583
|
+
outgoing[i] = getFloat(i);
|
|
584
|
+
}
|
|
585
|
+
return outgoing;
|
|
586
|
+
}
|
|
621
587
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
588
|
+
/**
|
|
589
|
+
* Get this entire array as a double array. Everything must be an double.
|
|
590
|
+
*/
|
|
591
|
+
public double[] getDoubleArray() {
|
|
592
|
+
double[] outgoing = new double[size()];
|
|
593
|
+
for (int i = 0; i < size(); i++) {
|
|
594
|
+
outgoing[i] = getDouble(i);
|
|
595
|
+
}
|
|
596
|
+
return outgoing;
|
|
627
597
|
}
|
|
628
|
-
return outgoing;
|
|
629
|
-
}
|
|
630
598
|
|
|
599
|
+
/**
|
|
600
|
+
* Get this entire array as a boolean array. Everything must be a boolean.
|
|
601
|
+
*/
|
|
602
|
+
public boolean[] getBooleanArray() {
|
|
603
|
+
boolean[] outgoing = new boolean[size()];
|
|
604
|
+
for (int i = 0; i < size(); i++) {
|
|
605
|
+
outgoing[i] = getBoolean(i);
|
|
606
|
+
}
|
|
607
|
+
return outgoing;
|
|
608
|
+
}
|
|
631
609
|
|
|
632
610
|
// /**
|
|
633
611
|
// * Get the optional boolean value associated with an index.
|
|
@@ -692,89 +670,81 @@ public class JSONArray {
|
|
|
692
670
|
// public String optString(int index) {
|
|
693
671
|
// return this.optString(index, "");
|
|
694
672
|
// }
|
|
673
|
+
/**
|
|
674
|
+
* Append an String value. This increases the array's length by one.
|
|
675
|
+
*
|
|
676
|
+
* @webref jsonarray:method
|
|
677
|
+
* @brief Appends a value, increasing the array's length by one
|
|
678
|
+
* @param value a String value
|
|
679
|
+
* @return this.
|
|
680
|
+
* @see JSONArray#size()
|
|
681
|
+
* @see JSONArray#remove(int)
|
|
682
|
+
*/
|
|
683
|
+
public JSONArray append(String value) {
|
|
684
|
+
this.append((Object) value);
|
|
685
|
+
return this;
|
|
686
|
+
}
|
|
695
687
|
|
|
688
|
+
/**
|
|
689
|
+
* Append an int value. This increases the array's length by one.
|
|
690
|
+
*
|
|
691
|
+
* @param value an int value
|
|
692
|
+
* @return this.
|
|
693
|
+
*/
|
|
694
|
+
public JSONArray append(int value) {
|
|
695
|
+
this.append(Integer.valueOf(value));
|
|
696
|
+
return this;
|
|
697
|
+
}
|
|
696
698
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
this.append((Object)value);
|
|
709
|
-
return this;
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
/**
|
|
714
|
-
* Append an int value. This increases the array's length by one.
|
|
715
|
-
*
|
|
716
|
-
* @param value an int value
|
|
717
|
-
* @return this.
|
|
718
|
-
*/
|
|
719
|
-
public JSONArray append(int value) {
|
|
720
|
-
this.append(Integer.valueOf(value));
|
|
721
|
-
return this;
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
/**
|
|
726
|
-
* Append an long value. This increases the array's length by one.
|
|
727
|
-
*
|
|
728
|
-
* @nowebref
|
|
729
|
-
* @param value A long value.
|
|
730
|
-
* @return this.
|
|
731
|
-
*/
|
|
732
|
-
public JSONArray append(long value) {
|
|
733
|
-
this.append(Long.valueOf(value));
|
|
734
|
-
return this;
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
/**
|
|
739
|
-
* Append a float value. This increases the array's length by one.
|
|
740
|
-
* This will store the value as a double, since there are no floats in JSON.
|
|
741
|
-
*
|
|
742
|
-
* @param value a float value
|
|
743
|
-
* @throws RuntimeException if the value is not finite.
|
|
744
|
-
* @return this.
|
|
745
|
-
*/
|
|
746
|
-
public JSONArray append(float value) {
|
|
747
|
-
return append((double) value);
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
/**
|
|
752
|
-
* Append a double value. This increases the array's length by one.
|
|
753
|
-
*
|
|
754
|
-
* @nowebref
|
|
755
|
-
* @param value A double value.
|
|
756
|
-
* @throws RuntimeException if the value is not finite.
|
|
757
|
-
* @return this.
|
|
758
|
-
*/
|
|
759
|
-
public JSONArray append(double value) {
|
|
760
|
-
Double d = value;
|
|
761
|
-
JSONObject.testValidity(d);
|
|
762
|
-
this.append(d);
|
|
763
|
-
return this;
|
|
764
|
-
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
/**
|
|
768
|
-
* Append a boolean value. This increases the array's length by one.
|
|
769
|
-
*
|
|
770
|
-
* @param value a boolean value
|
|
771
|
-
* @return this.
|
|
772
|
-
*/
|
|
773
|
-
public JSONArray append(boolean value) {
|
|
774
|
-
this.append(value ? Boolean.TRUE : Boolean.FALSE);
|
|
775
|
-
return this;
|
|
776
|
-
}
|
|
699
|
+
/**
|
|
700
|
+
* Append an long value. This increases the array's length by one.
|
|
701
|
+
*
|
|
702
|
+
* @nowebref
|
|
703
|
+
* @param value A long value.
|
|
704
|
+
* @return this.
|
|
705
|
+
*/
|
|
706
|
+
public JSONArray append(long value) {
|
|
707
|
+
this.append(Long.valueOf(value));
|
|
708
|
+
return this;
|
|
709
|
+
}
|
|
777
710
|
|
|
711
|
+
/**
|
|
712
|
+
* Append a float value. This increases the array's length by one. This will
|
|
713
|
+
* store the value as a double, since there are no floats in JSON.
|
|
714
|
+
*
|
|
715
|
+
* @param value a float value
|
|
716
|
+
* @throws RuntimeException if the value is not finite.
|
|
717
|
+
* @return this.
|
|
718
|
+
*/
|
|
719
|
+
public JSONArray append(float value) {
|
|
720
|
+
return append((double) value);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Append a double value. This increases the array's length by one.
|
|
725
|
+
*
|
|
726
|
+
* @nowebref
|
|
727
|
+
* @param value A double value.
|
|
728
|
+
* @throws RuntimeException if the value is not finite.
|
|
729
|
+
* @return this.
|
|
730
|
+
*/
|
|
731
|
+
public JSONArray append(double value) {
|
|
732
|
+
Double d = value;
|
|
733
|
+
JSONObject.testValidity(d);
|
|
734
|
+
this.append(d);
|
|
735
|
+
return this;
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
/**
|
|
739
|
+
* Append a boolean value. This increases the array's length by one.
|
|
740
|
+
*
|
|
741
|
+
* @param value a boolean value
|
|
742
|
+
* @return this.
|
|
743
|
+
*/
|
|
744
|
+
public JSONArray append(boolean value) {
|
|
745
|
+
this.append(value ? Boolean.TRUE : Boolean.FALSE);
|
|
746
|
+
return this;
|
|
747
|
+
}
|
|
778
748
|
|
|
779
749
|
// /**
|
|
780
750
|
// * Put a value in the JSONArray, where the value will be a
|
|
@@ -786,8 +756,6 @@ public class JSONArray {
|
|
|
786
756
|
// this.append(new JSONArray(value));
|
|
787
757
|
// return this;
|
|
788
758
|
// }
|
|
789
|
-
|
|
790
|
-
|
|
791
759
|
// /**
|
|
792
760
|
// * Put a value in the JSONArray, where the value will be a
|
|
793
761
|
// * JSONObject which is produced from a Map.
|
|
@@ -798,38 +766,34 @@ public class JSONArray {
|
|
|
798
766
|
// this.append(new JSONObject(value));
|
|
799
767
|
// return this;
|
|
800
768
|
// }
|
|
769
|
+
/**
|
|
770
|
+
* @param value a JSONArray value
|
|
771
|
+
*/
|
|
772
|
+
public JSONArray append(JSONArray value) {
|
|
773
|
+
myArrayList.add(value);
|
|
774
|
+
return this;
|
|
775
|
+
}
|
|
801
776
|
|
|
777
|
+
/**
|
|
778
|
+
* @param value a JSONObject value
|
|
779
|
+
*/
|
|
780
|
+
public JSONArray append(JSONObject value) {
|
|
781
|
+
myArrayList.add(value);
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
802
784
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
public JSONArray append(JSONObject value) {
|
|
816
|
-
myArrayList.add(value);
|
|
817
|
-
return this;
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
/**
|
|
822
|
-
* Append an object value. This increases the array's length by one.
|
|
823
|
-
* @param value An object value. The value should be a
|
|
824
|
-
* Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
|
|
825
|
-
* JSONObject.NULL object.
|
|
826
|
-
* @return this.
|
|
827
|
-
*/
|
|
828
|
-
protected JSONArray append(Object value) {
|
|
829
|
-
myArrayList.add(value);
|
|
830
|
-
return this;
|
|
831
|
-
}
|
|
832
|
-
|
|
785
|
+
/**
|
|
786
|
+
* Append an object value. This increases the array's length by one.
|
|
787
|
+
*
|
|
788
|
+
* @param value An object value. The value should be a Boolean, Double,
|
|
789
|
+
* Integer, JSONArray, JSONObject, Long, or String, or the JSONObject.NULL
|
|
790
|
+
* object.
|
|
791
|
+
* @return this.
|
|
792
|
+
*/
|
|
793
|
+
protected JSONArray append(Object value) {
|
|
794
|
+
myArrayList.add(value);
|
|
795
|
+
return this;
|
|
796
|
+
}
|
|
833
797
|
|
|
834
798
|
// /**
|
|
835
799
|
// * Put a value in the JSONArray, where the value will be a
|
|
@@ -844,120 +808,114 @@ public class JSONArray {
|
|
|
844
808
|
// this.set(index, new JSONArray(value));
|
|
845
809
|
// return this;
|
|
846
810
|
// }
|
|
811
|
+
/**
|
|
812
|
+
* Put or replace a String value. If the index is greater than the length of
|
|
813
|
+
* the JSONArray, then null elements will be added as necessary to pad it
|
|
814
|
+
* out.
|
|
815
|
+
*
|
|
816
|
+
* @webref jsonarray:method
|
|
817
|
+
* @brief Put a String value in the JSONArray
|
|
818
|
+
* @param index an index value
|
|
819
|
+
* @param value the value to assign
|
|
820
|
+
* @return this.
|
|
821
|
+
* @throws RuntimeException If the index is negative.
|
|
822
|
+
* @see JSONArray#setInt(int, int)
|
|
823
|
+
* @see JSONArray#setFloat(int, float)
|
|
824
|
+
* @see JSONArray#setBoolean(int, boolean)
|
|
825
|
+
*/
|
|
826
|
+
public JSONArray setString(int index, String value) {
|
|
827
|
+
this.set(index, value);
|
|
828
|
+
return this;
|
|
829
|
+
}
|
|
847
830
|
|
|
831
|
+
/**
|
|
832
|
+
* Put or replace an int value. If the index is greater than the length of
|
|
833
|
+
* the JSONArray, then null elements will be added as necessary to pad it
|
|
834
|
+
* out.
|
|
835
|
+
*
|
|
836
|
+
* @webref jsonarray:method
|
|
837
|
+
* @brief Put an int value in the JSONArray
|
|
838
|
+
* @param index an index value
|
|
839
|
+
* @param value the value to assign
|
|
840
|
+
* @return this.
|
|
841
|
+
* @throws RuntimeException If the index is negative.
|
|
842
|
+
* @see JSONArray#setFloat(int, float)
|
|
843
|
+
* @see JSONArray#setString(int, String)
|
|
844
|
+
* @see JSONArray#setBoolean(int, boolean)
|
|
845
|
+
*/
|
|
846
|
+
public JSONArray setInt(int index, int value) {
|
|
847
|
+
this.set(index, Integer.valueOf(value));
|
|
848
|
+
return this;
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Put or replace a long value. If the index is greater than the length of
|
|
853
|
+
* the JSONArray, then null elements will be added as necessary to pad it
|
|
854
|
+
* out.
|
|
855
|
+
*
|
|
856
|
+
* @param index The subscript.
|
|
857
|
+
* @param value A long value.
|
|
858
|
+
* @return this.
|
|
859
|
+
* @throws RuntimeException If the index is negative.
|
|
860
|
+
*/
|
|
861
|
+
public JSONArray setLong(int index, long value) {
|
|
862
|
+
return set(index, Long.valueOf(value));
|
|
863
|
+
}
|
|
848
864
|
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
/**
|
|
871
|
-
* Put or replace an int value. If the index is greater than the length of
|
|
872
|
-
* the JSONArray, then null elements will be added as necessary to pad
|
|
873
|
-
* it out.
|
|
874
|
-
*
|
|
875
|
-
* @webref jsonarray:method
|
|
876
|
-
* @brief Put an int value in the JSONArray
|
|
877
|
-
* @param index an index value
|
|
878
|
-
* @param value the value to assign
|
|
879
|
-
* @return this.
|
|
880
|
-
* @throws RuntimeException If the index is negative.
|
|
881
|
-
* @see JSONArray#setFloat(int, float)
|
|
882
|
-
* @see JSONArray#setString(int, String)
|
|
883
|
-
* @see JSONArray#setBoolean(int, boolean)
|
|
884
|
-
*/
|
|
885
|
-
public JSONArray setInt(int index, int value) {
|
|
886
|
-
this.set(index, Integer.valueOf(value));
|
|
887
|
-
return this;
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
/**
|
|
892
|
-
* Put or replace a long value. If the index is greater than the length of
|
|
893
|
-
* the JSONArray, then null elements will be added as necessary to pad
|
|
894
|
-
* it out.
|
|
895
|
-
* @param index The subscript.
|
|
896
|
-
* @param value A long value.
|
|
897
|
-
* @return this.
|
|
898
|
-
* @throws RuntimeException If the index is negative.
|
|
899
|
-
*/
|
|
900
|
-
public JSONArray setLong(int index, long value) {
|
|
901
|
-
return set(index, Long.valueOf(value));
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
/**
|
|
906
|
-
* Put or replace a float value. If the index is greater than the length
|
|
907
|
-
* of the JSONArray, then null elements will be added as necessary to pad
|
|
908
|
-
* it out. There are no 'double' values in JSON, so this is passed to
|
|
909
|
-
* setDouble(value).
|
|
910
|
-
*
|
|
911
|
-
* @webref jsonarray:method
|
|
912
|
-
* @brief Put a float value in the JSONArray
|
|
913
|
-
* @param index an index value
|
|
914
|
-
* @param value the value to assign
|
|
915
|
-
* @return this.
|
|
916
|
-
* @throws RuntimeException If the index is negative or if the value is
|
|
917
|
-
* not finite.
|
|
918
|
-
* @see JSONArray#setInt(int, int)
|
|
919
|
-
* @see JSONArray#setString(int, String)
|
|
920
|
-
* @see JSONArray#setBoolean(int, boolean)
|
|
921
|
-
*/
|
|
922
|
-
public JSONArray setFloat(int index, float value) {
|
|
923
|
-
return setDouble(index, value);
|
|
924
|
-
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
/**
|
|
928
|
-
* Put or replace a double value. If the index is greater than the length of
|
|
929
|
-
* the JSONArray, then null elements will be added as necessary to pad
|
|
930
|
-
* it out.
|
|
931
|
-
* @param index The subscript.
|
|
932
|
-
* @param value A double value.
|
|
933
|
-
* @return this.
|
|
934
|
-
* @throws RuntimeException If the index is negative or if the value is
|
|
935
|
-
* not finite.
|
|
936
|
-
*/
|
|
937
|
-
public JSONArray setDouble(int index, double value) {
|
|
938
|
-
return set(index, Double.valueOf(value));
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
/**
|
|
943
|
-
* Put or replace a boolean value in the JSONArray. If the index is greater
|
|
944
|
-
* than the length of the JSONArray, then null elements will be added as
|
|
945
|
-
* necessary to pad it out.
|
|
946
|
-
*
|
|
947
|
-
* @webref jsonarray:method
|
|
948
|
-
* @brief Put a boolean value in the JSONArray
|
|
949
|
-
* @param index an index value
|
|
950
|
-
* @param value the value to assign
|
|
951
|
-
* @return this.
|
|
952
|
-
* @throws RuntimeException If the index is negative.
|
|
953
|
-
* @see JSONArray#setInt(int, int)
|
|
954
|
-
* @see JSONArray#setFloat(int, float)
|
|
955
|
-
* @see JSONArray#setString(int, String)
|
|
956
|
-
*/
|
|
957
|
-
public JSONArray setBoolean(int index, boolean value) {
|
|
958
|
-
return set(index, value ? Boolean.TRUE : Boolean.FALSE);
|
|
959
|
-
}
|
|
865
|
+
/**
|
|
866
|
+
* Put or replace a float value. If the index is greater than the length of
|
|
867
|
+
* the JSONArray, then null elements will be added as necessary to pad it
|
|
868
|
+
* out. There are no 'double' values in JSON, so this is passed to
|
|
869
|
+
* setDouble(value).
|
|
870
|
+
*
|
|
871
|
+
* @webref jsonarray:method
|
|
872
|
+
* @brief Put a float value in the JSONArray
|
|
873
|
+
* @param index an index value
|
|
874
|
+
* @param value the value to assign
|
|
875
|
+
* @return this.
|
|
876
|
+
* @throws RuntimeException If the index is negative or if the value is not
|
|
877
|
+
* finite.
|
|
878
|
+
* @see JSONArray#setInt(int, int)
|
|
879
|
+
* @see JSONArray#setString(int, String)
|
|
880
|
+
* @see JSONArray#setBoolean(int, boolean)
|
|
881
|
+
*/
|
|
882
|
+
public JSONArray setFloat(int index, float value) {
|
|
883
|
+
return setDouble(index, value);
|
|
884
|
+
}
|
|
960
885
|
|
|
886
|
+
/**
|
|
887
|
+
* Put or replace a double value. If the index is greater than the length of
|
|
888
|
+
* the JSONArray, then null elements will be added as necessary to pad it
|
|
889
|
+
* out.
|
|
890
|
+
*
|
|
891
|
+
* @param index The subscript.
|
|
892
|
+
* @param value A double value.
|
|
893
|
+
* @return this.
|
|
894
|
+
* @throws RuntimeException If the index is negative or if the value is not
|
|
895
|
+
* finite.
|
|
896
|
+
*/
|
|
897
|
+
public JSONArray setDouble(int index, double value) {
|
|
898
|
+
return set(index, Double.valueOf(value));
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* Put or replace a boolean value in the JSONArray. If the index is greater
|
|
903
|
+
* than the length of the JSONArray, then null elements will be added as
|
|
904
|
+
* necessary to pad it out.
|
|
905
|
+
*
|
|
906
|
+
* @webref jsonarray:method
|
|
907
|
+
* @brief Put a boolean value in the JSONArray
|
|
908
|
+
* @param index an index value
|
|
909
|
+
* @param value the value to assign
|
|
910
|
+
* @return this.
|
|
911
|
+
* @throws RuntimeException If the index is negative.
|
|
912
|
+
* @see JSONArray#setInt(int, int)
|
|
913
|
+
* @see JSONArray#setFloat(int, float)
|
|
914
|
+
* @see JSONArray#setString(int, String)
|
|
915
|
+
*/
|
|
916
|
+
public JSONArray setBoolean(int index, boolean value) {
|
|
917
|
+
return set(index, value ? Boolean.TRUE : Boolean.FALSE);
|
|
918
|
+
}
|
|
961
919
|
|
|
962
920
|
// /**
|
|
963
921
|
// * Put a value in the JSONArray, where the value will be a
|
|
@@ -972,106 +930,103 @@ public class JSONArray {
|
|
|
972
930
|
// this.set(index, new JSONObject(value));
|
|
973
931
|
// return this;
|
|
974
932
|
// }
|
|
933
|
+
/**
|
|
934
|
+
* @webref jsonarray:method
|
|
935
|
+
* @brief Sets the JSONArray value associated with an index value
|
|
936
|
+
* @param index the index value to target
|
|
937
|
+
* @param value the value to assign
|
|
938
|
+
* @see JSONArray#setJSONObject(int, JSONObject)
|
|
939
|
+
* @see JSONArray#getJSONObject(int)
|
|
940
|
+
* @see JSONArray#getJSONArray(int)
|
|
941
|
+
*/
|
|
942
|
+
public JSONArray setJSONArray(int index, JSONArray value) {
|
|
943
|
+
set(index, value);
|
|
944
|
+
return this;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
/**
|
|
948
|
+
* @webref jsonarray:method
|
|
949
|
+
* @brief Sets the JSONObject value associated with an index value
|
|
950
|
+
* @param index the index value to target
|
|
951
|
+
* @param value the value to assign
|
|
952
|
+
* @see JSONArray#setJSONArray(int, JSONArray)
|
|
953
|
+
* @see JSONArray#getJSONObject(int)
|
|
954
|
+
* @see JSONArray#getJSONArray(int)
|
|
955
|
+
*/
|
|
956
|
+
public JSONArray setJSONObject(int index, JSONObject value) {
|
|
957
|
+
set(index, value);
|
|
958
|
+
return this;
|
|
959
|
+
}
|
|
975
960
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
/**
|
|
1006
|
-
* Put or replace an object value in the JSONArray. If the index is greater
|
|
1007
|
-
* than the length of the JSONArray, then null elements will be added as
|
|
1008
|
-
* necessary to pad it out.
|
|
1009
|
-
* @param index The subscript.
|
|
1010
|
-
* @param value The value to put into the array. The value should be a
|
|
1011
|
-
* Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
|
|
1012
|
-
* JSONObject.NULL object.
|
|
1013
|
-
* @return this.
|
|
1014
|
-
* @throws RuntimeException If the index is negative or if the the value is
|
|
1015
|
-
* an invalid number.
|
|
1016
|
-
*/
|
|
1017
|
-
private JSONArray set(int index, Object value) {
|
|
1018
|
-
JSONObject.testValidity(value);
|
|
1019
|
-
if (index < 0) {
|
|
1020
|
-
throw new RuntimeException("JSONArray[" + index + "] not found.");
|
|
961
|
+
/**
|
|
962
|
+
* Put or replace an object value in the JSONArray. If the index is greater
|
|
963
|
+
* than the length of the JSONArray, then null elements will be added as
|
|
964
|
+
* necessary to pad it out.
|
|
965
|
+
*
|
|
966
|
+
* @param index The subscript.
|
|
967
|
+
* @param value The value to put into the array. The value should be a
|
|
968
|
+
* Boolean, Double, Integer, JSONArray, JSONObject, Long, or String, or the
|
|
969
|
+
* JSONObject.NULL object.
|
|
970
|
+
* @return this.
|
|
971
|
+
* @throws RuntimeException If the index is negative or if the the value is
|
|
972
|
+
* an invalid number.
|
|
973
|
+
*/
|
|
974
|
+
private JSONArray set(int index, Object value) {
|
|
975
|
+
JSONObject.testValidity(value);
|
|
976
|
+
if (index < 0) {
|
|
977
|
+
throw new RuntimeException("JSONArray[" + index + "] not found.");
|
|
978
|
+
}
|
|
979
|
+
if (index < this.size()) {
|
|
980
|
+
this.myArrayList.set(index, value);
|
|
981
|
+
} else {
|
|
982
|
+
while (index != this.size()) {
|
|
983
|
+
this.append(JSONObject.NULL);
|
|
984
|
+
}
|
|
985
|
+
this.append(value);
|
|
986
|
+
}
|
|
987
|
+
return this;
|
|
1021
988
|
}
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
989
|
+
|
|
990
|
+
/**
|
|
991
|
+
* Get the number of elements in the JSONArray, included nulls.
|
|
992
|
+
*
|
|
993
|
+
* @webref jsonarray:method
|
|
994
|
+
* @brief Gets the number of elements in the JSONArray
|
|
995
|
+
* @return The length (or size).
|
|
996
|
+
* @see JSONArray#append(String)
|
|
997
|
+
* @see JSONArray#remove(int)
|
|
998
|
+
*/
|
|
999
|
+
public int size() {
|
|
1000
|
+
return myArrayList.size();
|
|
1029
1001
|
}
|
|
1030
|
-
return this;
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
/**
|
|
1035
|
-
* Get the number of elements in the JSONArray, included nulls.
|
|
1036
|
-
*
|
|
1037
|
-
* @webref jsonarray:method
|
|
1038
|
-
* @brief Gets the number of elements in the JSONArray
|
|
1039
|
-
* @return The length (or size).
|
|
1040
|
-
* @see JSONArray#append(String)
|
|
1041
|
-
* @see JSONArray#remove(int)
|
|
1042
|
-
*/
|
|
1043
|
-
public int size() {
|
|
1044
|
-
return myArrayList.size();
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
/**
|
|
1049
|
-
* Determine if the value is null.
|
|
1050
|
-
* @webref
|
|
1051
|
-
* @param index must be between 0 and length() - 1
|
|
1052
|
-
* @return true if the value at the index is null, or if there is no value.
|
|
1053
|
-
*/
|
|
1054
|
-
public boolean isNull(int index) {
|
|
1055
|
-
return JSONObject.NULL.equals(this.opt(index));
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
/**
|
|
1060
|
-
* Remove an index and close the hole.
|
|
1061
|
-
*
|
|
1062
|
-
* @webref jsonarray:method
|
|
1063
|
-
* @brief Removes an element
|
|
1064
|
-
* @param index the index value of the element to be removed
|
|
1065
|
-
* @return The value that was associated with the index, or null if there was no value.
|
|
1066
|
-
* @see JSONArray#size()
|
|
1067
|
-
* @see JSONArray#append(String)
|
|
1068
|
-
*/
|
|
1069
|
-
public Object remove(int index) {
|
|
1070
|
-
Object o = this.opt(index);
|
|
1071
|
-
this.myArrayList.remove(index);
|
|
1072
|
-
return o;
|
|
1073
|
-
}
|
|
1074
1002
|
|
|
1003
|
+
/**
|
|
1004
|
+
* Determine if the value is null.
|
|
1005
|
+
*
|
|
1006
|
+
* @webref
|
|
1007
|
+
* @param index must be between 0 and length() - 1
|
|
1008
|
+
* @return true if the value at the index is null, or if there is no value.
|
|
1009
|
+
*/
|
|
1010
|
+
public boolean isNull(int index) {
|
|
1011
|
+
return JSONObject.NULL.equals(this.opt(index));
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Remove an index and close the hole.
|
|
1016
|
+
*
|
|
1017
|
+
* @webref jsonarray:method
|
|
1018
|
+
* @brief Removes an element
|
|
1019
|
+
* @param index the index value of the element to be removed
|
|
1020
|
+
* @return The value that was associated with the index, or null if there
|
|
1021
|
+
* was no value.
|
|
1022
|
+
* @see JSONArray#size()
|
|
1023
|
+
* @see JSONArray#append(String)
|
|
1024
|
+
*/
|
|
1025
|
+
public Object remove(int index) {
|
|
1026
|
+
Object o = this.opt(index);
|
|
1027
|
+
this.myArrayList.remove(index);
|
|
1028
|
+
return o;
|
|
1029
|
+
}
|
|
1075
1030
|
|
|
1076
1031
|
// /**
|
|
1077
1032
|
// * Produce a JSONObject by combining a JSONArray of names with the values
|
|
@@ -1092,81 +1047,72 @@ public class JSONArray {
|
|
|
1092
1047
|
// }
|
|
1093
1048
|
// return jo;
|
|
1094
1049
|
// }
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
1050
|
// protected boolean save(OutputStream output) {
|
|
1098
1051
|
// return write(PApplet.createWriter(output), null);
|
|
1099
1052
|
// }
|
|
1053
|
+
public boolean save(File file, String options) {
|
|
1054
|
+
PrintWriter writer = PApplet.createWriter(file);
|
|
1055
|
+
boolean success = write(writer, options);
|
|
1056
|
+
writer.close();
|
|
1057
|
+
return success;
|
|
1058
|
+
}
|
|
1100
1059
|
|
|
1060
|
+
public boolean write(PrintWriter output) {
|
|
1061
|
+
return write(output, null);
|
|
1062
|
+
}
|
|
1101
1063
|
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
String[] opts = PApplet.split(options, ',');
|
|
1119
|
-
for (String opt : opts) {
|
|
1120
|
-
if (opt.equals("compact")) {
|
|
1121
|
-
indentFactor = -1;
|
|
1122
|
-
} else if (opt.startsWith("indent=")) {
|
|
1123
|
-
indentFactor = PApplet.parseInt(opt.substring(7), -2);
|
|
1124
|
-
if (indentFactor == -2) {
|
|
1125
|
-
throw new IllegalArgumentException("Could not read a number from " + opt);
|
|
1126
|
-
}
|
|
1127
|
-
} else {
|
|
1128
|
-
System.err.println("Ignoring " + opt);
|
|
1064
|
+
public boolean write(PrintWriter output, String options) {
|
|
1065
|
+
int indentFactor = 2;
|
|
1066
|
+
if (options != null) {
|
|
1067
|
+
String[] opts = PApplet.split(options, ',');
|
|
1068
|
+
for (String opt : opts) {
|
|
1069
|
+
if (opt.equals("compact")) {
|
|
1070
|
+
indentFactor = -1;
|
|
1071
|
+
} else if (opt.startsWith("indent=")) {
|
|
1072
|
+
indentFactor = PApplet.parseInt(opt.substring(7), -2);
|
|
1073
|
+
if (indentFactor == -2) {
|
|
1074
|
+
throw new IllegalArgumentException("Could not read a number from " + opt);
|
|
1075
|
+
}
|
|
1076
|
+
} else {
|
|
1077
|
+
System.err.println("Ignoring " + opt);
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1129
1080
|
}
|
|
1130
|
-
|
|
1081
|
+
output.print(format(indentFactor));
|
|
1082
|
+
output.flush();
|
|
1083
|
+
return true;
|
|
1131
1084
|
}
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
try {
|
|
1146
|
-
return format(2);
|
|
1147
|
-
} catch (Exception e) {
|
|
1148
|
-
return null;
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
/**
|
|
1154
|
-
* Make a pretty-printed JSON text of this JSONArray.
|
|
1155
|
-
* Warning: This method assumes that the data structure is acyclical.
|
|
1156
|
-
* @param indentFactor The number of spaces to add to each level of
|
|
1157
|
-
* indentation. Use -1 to specify no indentation and no newlines.
|
|
1158
|
-
* @return a printable, displayable, transmittable
|
|
1159
|
-
* representation of the object, beginning
|
|
1160
|
-
* with <code>[</code> <small>(left bracket)</small> and ending
|
|
1161
|
-
* with <code>]</code> <small>(right bracket)</small>.
|
|
1162
|
-
*/
|
|
1163
|
-
public String format(int indentFactor) {
|
|
1164
|
-
StringWriter sw = new StringWriter();
|
|
1165
|
-
synchronized (sw.getBuffer()) {
|
|
1166
|
-
return this.writeInternal(sw, indentFactor, 0).toString();
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* Return the JSON data formatted with two spaces for indents. Chosen to do
|
|
1088
|
+
* this since it's the most common case (e.g. with println()). Same as
|
|
1089
|
+
* format(2). Use the format() function for more options.
|
|
1090
|
+
*/
|
|
1091
|
+
@Override
|
|
1092
|
+
public String toString() {
|
|
1093
|
+
try {
|
|
1094
|
+
return format(2);
|
|
1095
|
+
} catch (Exception e) {
|
|
1096
|
+
return null;
|
|
1097
|
+
}
|
|
1167
1098
|
}
|
|
1168
|
-
}
|
|
1169
1099
|
|
|
1100
|
+
/**
|
|
1101
|
+
* Make a pretty-printed JSON text of this JSONArray. Warning: This method
|
|
1102
|
+
* assumes that the data structure is acyclical.
|
|
1103
|
+
*
|
|
1104
|
+
* @param indentFactor The number of spaces to add to each level of
|
|
1105
|
+
* indentation. Use -1 to specify no indentation and no newlines.
|
|
1106
|
+
* @return a printable, displayable, transmittable representation of the
|
|
1107
|
+
* object, beginning with <code>[</code> <small>(left bracket)</small>
|
|
1108
|
+
* and ending with <code>]</code> <small>(right bracket)</small>.
|
|
1109
|
+
*/
|
|
1110
|
+
public String format(int indentFactor) {
|
|
1111
|
+
StringWriter sw = new StringWriter();
|
|
1112
|
+
synchronized (sw.getBuffer()) {
|
|
1113
|
+
return this.writeInternal(sw, indentFactor, 0).toString();
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1170
1116
|
|
|
1171
1117
|
// /**
|
|
1172
1118
|
// * Write the contents of the JSONArray as JSON text to a writer. For
|
|
@@ -1179,82 +1125,78 @@ public class JSONArray {
|
|
|
1179
1125
|
// protected Writer write(Writer writer) {
|
|
1180
1126
|
// return this.write(writer, -1, 0);
|
|
1181
1127
|
// }
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
if (length == 1) {
|
|
1207
|
-
JSONObject.writeValue(writer, this.myArrayList.get(0),
|
|
1208
|
-
indentFactor, indent);
|
|
1128
|
+
/**
|
|
1129
|
+
* Write the contents of the JSONArray as JSON text to a writer.
|
|
1130
|
+
* <p>
|
|
1131
|
+
* Warning: This method assumes that the data structure is acyclic.
|
|
1132
|
+
*
|
|
1133
|
+
* @param indentFactor The number of spaces to add to each level of
|
|
1134
|
+
* indentation. Use -1 to specify no indentation and no newlines.
|
|
1135
|
+
* @param indent The indention of the top level.
|
|
1136
|
+
* @return The writer.
|
|
1137
|
+
* @throws RuntimeException
|
|
1138
|
+
*/
|
|
1139
|
+
protected Writer writeInternal(Writer writer, int indentFactor, int indent) {
|
|
1140
|
+
try {
|
|
1141
|
+
boolean commanate = false;
|
|
1142
|
+
int length = this.size();
|
|
1143
|
+
writer.write('[');
|
|
1144
|
+
|
|
1145
|
+
// Use -1 to signify 'no indent'
|
|
1146
|
+
int thisFactor = (indentFactor == -1) ? 0 : indentFactor;
|
|
1147
|
+
|
|
1148
|
+
if (length == 1) {
|
|
1149
|
+
JSONObject.writeValue(writer, this.myArrayList.get(0),
|
|
1150
|
+
indentFactor, indent);
|
|
1209
1151
|
// thisFactor, indent);
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1152
|
+
} else if (length != 0) {
|
|
1153
|
+
final int newIndent = indent + thisFactor;
|
|
1154
|
+
|
|
1155
|
+
for (int i = 0; i < length; i += 1) {
|
|
1156
|
+
if (commanate) {
|
|
1157
|
+
writer.write(',');
|
|
1158
|
+
}
|
|
1159
|
+
if (indentFactor != -1) {
|
|
1160
|
+
writer.write('\n');
|
|
1161
|
+
}
|
|
1162
|
+
JSONObject.indent(writer, newIndent);
|
|
1221
1163
|
// JSONObject.writeValue(writer, this.myArrayList.get(i),
|
|
1222
1164
|
// thisFactor, newIndent);
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1165
|
+
JSONObject.writeValue(writer, this.myArrayList.get(i),
|
|
1166
|
+
indentFactor, newIndent);
|
|
1167
|
+
commanate = true;
|
|
1168
|
+
}
|
|
1169
|
+
if (indentFactor != -1) {
|
|
1170
|
+
writer.write('\n');
|
|
1171
|
+
}
|
|
1172
|
+
JSONObject.indent(writer, indent);
|
|
1173
|
+
}
|
|
1174
|
+
writer.write(']');
|
|
1175
|
+
return writer;
|
|
1176
|
+
} catch (IOException e) {
|
|
1177
|
+
throw new RuntimeException(e);
|
|
1226
1178
|
}
|
|
1227
|
-
if (indentFactor != -1) {
|
|
1228
|
-
writer.write('\n');
|
|
1229
|
-
}
|
|
1230
|
-
JSONObject.indent(writer, indent);
|
|
1231
|
-
}
|
|
1232
|
-
writer.write(']');
|
|
1233
|
-
return writer;
|
|
1234
|
-
} catch (IOException e) {
|
|
1235
|
-
throw new RuntimeException(e);
|
|
1236
1179
|
}
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1180
|
+
|
|
1181
|
+
/**
|
|
1182
|
+
* Make a string from the contents of this JSONArray. The
|
|
1183
|
+
* <code>separator</code> string is inserted between each element. Warning:
|
|
1184
|
+
* This method assumes that the data structure is acyclic.
|
|
1185
|
+
*
|
|
1186
|
+
* @param separator A string that will be inserted between the elements.
|
|
1187
|
+
* @return a string.
|
|
1188
|
+
* @throws RuntimeException If the array contains an invalid number.
|
|
1189
|
+
*/
|
|
1190
|
+
public String join(String separator) {
|
|
1191
|
+
int len = this.size();
|
|
1192
|
+
StringBuilder sb = new StringBuilder();
|
|
1193
|
+
|
|
1194
|
+
for (int i = 0; i < len; i += 1) {
|
|
1195
|
+
if (i > 0) {
|
|
1196
|
+
sb.append(separator);
|
|
1197
|
+
}
|
|
1198
|
+
sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
|
|
1199
|
+
}
|
|
1200
|
+
return sb.toString();
|
|
1257
1201
|
}
|
|
1258
|
-
return sb.toString();
|
|
1259
|
-
}
|
|
1260
1202
|
}
|