propane 3.4.2-java → 3.8.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +1 -1
  6. data/CHANGELOG.md +9 -1
  7. data/Gemfile +2 -0
  8. data/README.md +7 -10
  9. data/Rakefile +10 -11
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +4 -2
  12. data/lib/propane/app.rb +5 -1
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +22 -23
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +10 -9
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +20 -14
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +2 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +2 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +2 -0
  33. data/library/slider/slider.rb +23 -22
  34. data/library/vector_utils/vector_utils.rb +4 -0
  35. data/library/video_event/video_event.rb +2 -0
  36. data/pom.rb +37 -36
  37. data/pom.xml +7 -7
  38. data/propane.gemspec +13 -9
  39. data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
  40. data/src/main/java/monkstone/ColorUtil.java +1 -3
  41. data/src/main/java/monkstone/MathToolModule.java +1 -1
  42. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  43. data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
  44. data/src/main/java/monkstone/fastmath/Deglut.java +6 -56
  45. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  46. data/src/main/java/monkstone/noise/Noise.java +116 -0
  47. data/src/main/java/monkstone/noise/NoiseGenerator.java +63 -0
  48. data/src/main/java/monkstone/noise/NoiseMode.java +15 -0
  49. data/src/main/java/monkstone/noise/SimplexNoise.java +137 -103
  50. data/src/main/java/monkstone/noise/ValueNoise.java +170 -0
  51. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  53. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  54. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  55. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  56. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  57. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  58. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  59. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  60. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
  61. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  62. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  63. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  64. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  65. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  66. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  67. data/src/main/java/processing/awt/PSurfaceAWT.java +308 -208
  68. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  69. data/src/main/java/processing/core/PApplet.java +13142 -13883
  70. data/src/main/java/processing/core/PConstants.java +477 -447
  71. data/src/main/java/processing/core/PFont.java +914 -880
  72. data/src/main/java/processing/core/PGraphics.java +152 -136
  73. data/src/main/java/processing/core/PImage.java +275 -372
  74. data/src/main/java/processing/core/PMatrix.java +172 -159
  75. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  76. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  77. data/src/main/java/processing/core/PShape.java +2887 -2651
  78. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  79. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  80. data/src/main/java/processing/core/PStyle.java +40 -37
  81. data/src/main/java/processing/core/PSurface.java +139 -97
  82. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  83. data/src/main/java/processing/core/PVector.java +995 -963
  84. data/src/main/java/processing/core/ThinkDifferent.java +12 -8
  85. data/src/main/java/processing/data/DoubleDict.java +756 -710
  86. data/src/main/java/processing/data/DoubleList.java +749 -696
  87. data/src/main/java/processing/data/FloatDict.java +748 -702
  88. data/src/main/java/processing/data/FloatList.java +751 -697
  89. data/src/main/java/processing/data/IntDict.java +720 -673
  90. data/src/main/java/processing/data/IntList.java +699 -633
  91. data/src/main/java/processing/data/JSONArray.java +931 -873
  92. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  93. data/src/main/java/processing/data/JSONTokener.java +351 -341
  94. data/src/main/java/processing/data/LongDict.java +710 -663
  95. data/src/main/java/processing/data/LongList.java +701 -635
  96. data/src/main/java/processing/data/Sort.java +37 -41
  97. data/src/main/java/processing/data/StringDict.java +525 -486
  98. data/src/main/java/processing/data/StringList.java +626 -580
  99. data/src/main/java/processing/data/Table.java +3690 -3510
  100. data/src/main/java/processing/data/TableRow.java +182 -183
  101. data/src/main/java/processing/data/XML.java +957 -883
  102. data/src/main/java/processing/event/Event.java +87 -67
  103. data/src/main/java/processing/event/KeyEvent.java +48 -41
  104. data/src/main/java/processing/event/MouseEvent.java +88 -113
  105. data/src/main/java/processing/event/TouchEvent.java +10 -6
  106. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  107. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  108. data/src/main/java/processing/net/Client.java +20 -20
  109. data/src/main/java/processing/net/Server.java +9 -9
  110. data/src/main/java/processing/opengl/FontTexture.java +286 -266
  111. data/src/main/java/processing/opengl/FrameBuffer.java +389 -377
  112. data/src/main/java/processing/opengl/LinePath.java +132 -89
  113. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  114. data/src/main/java/processing/opengl/PGL.java +660 -567
  115. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  116. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  117. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  118. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  119. data/src/main/java/processing/opengl/PShader.java +369 -461
  120. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  121. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  122. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  123. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  124. data/test/create_test.rb +21 -20
  125. data/test/deglut_spec_test.rb +4 -2
  126. data/test/helper_methods_test.rb +49 -20
  127. data/test/math_tool_test.rb +39 -32
  128. data/test/native_folder.rb +47 -0
  129. data/test/respond_to_test.rb +3 -2
  130. data/test/sketches/key_event.rb +2 -2
  131. data/test/sketches/library/my_library/my_library.rb +3 -0
  132. data/test/test_helper.rb +2 -0
  133. data/test/vecmath_spec_test.rb +35 -22
  134. data/vendors/Rakefile +35 -40
  135. metadata +47 -23
  136. data/library/simplex_noise/simplex_noise.rb +0 -3
  137. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  138. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  139. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  140. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -33,6 +33,7 @@ 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
+
36
37
  import java.io.File;
37
38
  import java.io.IOException;
38
39
  import java.io.PrintWriter;
@@ -98,109 +99,116 @@ import processing.core.PApplet;
98
99
  */
99
100
  public class JSONArray {
100
101
 
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<>();
111
- }
112
-
113
- /**
114
- * @nowebref
115
- */
116
- public JSONArray(Reader reader) {
117
- this(new JSONTokener(reader));
102
+ /**
103
+ * The arrayList where the JSONArray's properties are kept.
104
+ */
105
+ private final ArrayList<Object> myArrayList;
106
+
107
+
108
+ /**
109
+ * Construct an empty JSONArray.
110
+ */
111
+ public JSONArray() {
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 '['");
118
135
  }
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 '['");
136
+ if (x.nextClean() != ']') {
137
+ x.back();
138
+ for (;;) {
139
+ if (x.nextClean() == ',') {
140
+ x.back();
141
+ myArrayList.add(JSONObject.NULL);
142
+ } else {
143
+ x.back();
144
+ myArrayList.add(x.nextValue());
131
145
  }
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
- }
146
+ switch (x.nextClean()) {
147
+ case ';':
148
+ case ',':
149
+ if (x.nextClean() == ']') {
150
+ return;
151
+ }
152
+ x.back();
153
+ break;
154
+ case ']':
155
+ return;
156
+ default:
157
+ throw new RuntimeException("Expected a ',' or ']'");
156
158
  }
159
+ }
157
160
  }
161
+ }
158
162
 
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
- }
167
- }
168
163
 
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
- }
164
+ /**
165
+ * @nowebref
166
+ */
167
+ public JSONArray(IntList list) {
168
+ myArrayList = new ArrayList<>();
169
+ for (int item : list.values()) {
170
+ myArrayList.add(Integer.valueOf(item));
177
171
  }
172
+ }
178
173
 
179
- /**
180
- * @nowebref
181
- */
182
- public JSONArray(StringList list) {
183
- myArrayList = new ArrayList<>();
184
- for (String item : list.values()) {
185
- myArrayList.add(item);
186
- }
174
+
175
+ /**
176
+ * @nowebref
177
+ */
178
+ public JSONArray(FloatList list) {
179
+ myArrayList = new ArrayList<>();
180
+ for (float item : list.values()) {
181
+ myArrayList.add(Float.valueOf(item));
187
182
  }
183
+ }
188
184
 
189
- /**
190
- * Construct a JSONArray from a source JSON text.
191
- *
192
- * @param source A string that begins with <code>[</code>&nbsp;<small>(left
193
- * bracket)</small>
194
- * and ends with <code>]</code>&nbsp;<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
- }
185
+
186
+ /**
187
+ * @nowebref
188
+ */
189
+ public JSONArray(StringList list) {
190
+ myArrayList = new ArrayList<>();
191
+ for (String item : list.values()) {
192
+ myArrayList.add(item);
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>&nbsp;<small>(left bracket)</small>
201
+ * and ends with <code>]</code>&nbsp;<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;
203
209
  }
210
+ }
211
+
204
212
 
205
213
  // /**
206
214
  // * Construct a JSONArray from a Collection.
@@ -215,397 +223,411 @@ public class JSONArray {
215
223
  // }
216
224
  // }
217
225
  // }
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
- }
234
- }
235
226
 
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);
247
- }
248
227
 
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;
228
+ // TODO not decided whether we keep this one, but used heavily by JSONObject
229
+ /**
230
+ * Construct a JSONArray from an array
231
+ * @throws RuntimeException If not an array.
232
+ */
233
+ protected JSONArray(Object array) {
234
+ this();
235
+ if (array.getClass().isArray()) {
236
+ int length = Array.getLength(array);
237
+ for (int i = 0; i < length; i += 1) {
238
+ this.append(JSONObject.wrap(Array.get(array, i)));
239
+ }
240
+ } else {
241
+ throw new RuntimeException("JSONArray initial value should be a string or collection or array.");
262
242
  }
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.");
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;
282
255
  }
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();
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.");
295
270
  }
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
- }
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;
319
291
  }
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
- }
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.");
336
330
  }
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
- }
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;
355
347
  }
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
- }
348
+ }
349
+
350
+
351
+ /**
352
+ * Get the long value associated with an index.
353
+ *
354
+ * @param index The index must be between 0 and length() - 1
355
+ * @return The value.
356
+ * @throws RuntimeException If the key is not found or if the value cannot
357
+ * be converted to a number.
358
+ */
359
+ public long getLong(int index) {
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.");
372
367
  }
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);
368
+ }
369
+
370
+
371
+ /**
372
+ * Get the optional long value associated with an index.
373
+ * The defaultValue is returned if there is no value for the index,
374
+ * or if the value is not a number and cannot be converted to a number.
375
+ * @param index The index must be between 0 and length() - 1.
376
+ * @param defaultValue The default value.
377
+ * @return The value.
378
+ */
379
+ public long getLong(int index, long defaultValue) {
380
+ try {
381
+ return this.getLong(index);
382
+ } catch (Exception e) {
383
+ return defaultValue;
387
384
  }
388
-
389
- public float getFloat(int index, float defaultValue) {
390
- try {
391
- return getFloat(index);
392
- } catch (Exception e) {
393
- return defaultValue;
394
- }
385
+ }
386
+
387
+
388
+ /**
389
+ * Get a value from an index as a float. JSON uses 'double' values
390
+ * internally, so this is simply getDouble() cast to a float.
391
+ *
392
+ * @webref jsonarray:method
393
+ * @brief Gets the float value associated with an index
394
+ * @param index must be between 0 and length() - 1
395
+ * @see JSONArray#getInt(int)
396
+ * @see JSONArray#getString(int)
397
+ * @see JSONArray#getBoolean(int)
398
+ */
399
+ public float getFloat(int index) {
400
+ return (float) getDouble(index);
401
+ }
402
+
403
+
404
+ public float getFloat(int index, float defaultValue) {
405
+ try {
406
+ return getFloat(index);
407
+ } catch (Exception e) {
408
+ return defaultValue;
395
409
  }
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
- }
410
+ }
411
+
412
+
413
+ /**
414
+ * Get the double value associated with an index.
415
+ *
416
+ * @param index must be between 0 and length() - 1
417
+ * @return The value.
418
+ * @throws RuntimeException If the key is not found or if the value cannot
419
+ * be converted to a number.
420
+ */
421
+ public double getDouble(int index) {
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.");
414
429
  }
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
- }
430
+ }
431
+
432
+
433
+ /**
434
+ * Get the optional double value associated with an index.
435
+ * The defaultValue is returned if there is no value for the index,
436
+ * or if the value is not a number and cannot be converted to a number.
437
+ *
438
+ * @param index subscript
439
+ * @param defaultValue The default value.
440
+ * @return The value.
441
+ */
442
+ public double getDouble(int index, double defaultValue) {
443
+ try {
444
+ return this.getDouble(index);
445
+ } catch (Exception e) {
446
+ return defaultValue;
431
447
  }
432
-
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.");
448
+ }
449
+
450
+
451
+ /**
452
+ * Get the boolean value associated with an index.
453
+ * The string values "true" and "false" are converted to boolean.
454
+ *
455
+ * @webref jsonarray:method
456
+ * @brief Gets the boolean value associated with an index
457
+ * @param index must be between 0 and length() - 1
458
+ * @return The truth.
459
+ * @throws RuntimeException If there is no value for the index or if the
460
+ * value is not convertible to boolean.
461
+ * @see JSONArray#getInt(int)
462
+ * @see JSONArray#getFloat(int)
463
+ * @see JSONArray#getString(int)
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;
459
475
  }
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
- }
476
+ throw new RuntimeException("JSONArray[" + index + "] is not a boolean.");
477
+ }
478
+
479
+
480
+ /**
481
+ * Get the optional boolean value associated with an index.
482
+ * It returns the defaultValue if there is no value at that index or if
483
+ * it is not a Boolean or the String "true" or "false" (case insensitive).
484
+ *
485
+ * @param index The index must be between 0 and length() - 1.
486
+ * @param defaultValue A boolean default.
487
+ * @return The truth.
488
+ */
489
+ public boolean getBoolean(int index, boolean defaultValue) {
490
+ try {
491
+ return getBoolean(index);
492
+ } catch (Exception e) {
493
+ return defaultValue;
476
494
  }
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.");
495
+ }
496
+
497
+
498
+ /**
499
+ * Get the JSONArray associated with an index.
500
+ *
501
+ * @webref jsonobject:method
502
+ * @brief Gets the JSONArray associated with an index value
503
+ * @param index must be between 0 and length() - 1
504
+ * @return A JSONArray value.
505
+ * @throws RuntimeException If there is no value for the index. or if the
506
+ * value is not a JSONArray
507
+ * @see JSONArray#getJSONObject(int)
508
+ * @see JSONArray#setJSONObject(int, JSONObject)
509
+ * @see JSONArray#setJSONArray(int, JSONArray)
510
+ */
511
+ public JSONArray getJSONArray(int index) {
512
+ Object object = this.get(index);
513
+ if (object instanceof JSONArray) {
514
+ return (JSONArray)object;
497
515
  }
516
+ throw new RuntimeException("JSONArray[" + index + "] is not a JSONArray.");
517
+ }
498
518
 
499
- public JSONArray getJSONArray(int index, JSONArray defaultValue) {
500
- try {
501
- return getJSONArray(index);
502
- } catch (Exception e) {
503
- return defaultValue;
504
- }
505
- }
506
519
 
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.");
520
+ public JSONArray getJSONArray(int index, JSONArray defaultValue) {
521
+ try {
522
+ return getJSONArray(index);
523
+ } catch (Exception e) {
524
+ return defaultValue;
526
525
  }
527
-
528
- public JSONObject getJSONObject(int index, JSONObject defaultValue) {
529
- try {
530
- return getJSONObject(index);
531
- } catch (Exception e) {
532
- return defaultValue;
533
- }
526
+ }
527
+
528
+
529
+ /**
530
+ * Get the JSONObject associated with an index.
531
+ *
532
+ * @webref jsonobject:method
533
+ * @brief Gets the JSONObject associated with an index value
534
+ * @param index the index value of the object to get
535
+ * @return A JSONObject value.
536
+ * @throws RuntimeException If there is no value for the index or if the
537
+ * value is not a JSONObject
538
+ * @see JSONArray#getJSONArray(int)
539
+ * @see JSONArray#setJSONObject(int, JSONObject)
540
+ * @see JSONArray#setJSONArray(int, JSONArray)
541
+ */
542
+ public JSONObject getJSONObject(int index) {
543
+ Object object = this.get(index);
544
+ if (object instanceof JSONObject) {
545
+ return (JSONObject)object;
534
546
  }
547
+ throw new RuntimeException("JSONArray[" + index + "] is not a JSONObject.");
548
+ }
535
549
 
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;
549
- }
550
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;
551
+ public JSONObject getJSONObject(int index, JSONObject defaultValue) {
552
+ try {
553
+ return getJSONObject(index);
554
+ } catch (Exception e) {
555
+ return defaultValue;
564
556
  }
557
+ }
558
+
559
+
560
+ /**
561
+ * Get this entire array as a String array.
562
+ *
563
+ * @webref jsonarray:method
564
+ * @brief Gets the entire array as an array of Strings
565
+ * @see JSONArray#getIntArray()
566
+ */
567
+ public String[] getStringArray() {
568
+ String[] outgoing = new String[size()];
569
+ for (int i = 0; i < size(); i++) {
570
+ outgoing[i] = getString(i);
571
+ }
572
+ return outgoing;
573
+ }
574
+
575
+
576
+ /**
577
+ * Get this entire array as an int array. Everything must be an int.
578
+ *
579
+ * @webref jsonarray:method
580
+ * @brief Gets the entire array as array of ints
581
+ * @see JSONArray#getStringArray()
582
+ */
583
+ public int[] getIntArray() {
584
+ int[] outgoing = new int[size()];
585
+ for (int i = 0; i < size(); i++) {
586
+ outgoing[i] = getInt(i);
587
+ }
588
+ return outgoing;
589
+ }
565
590
 
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;
591
+
592
+ /** Get this entire array as a long array. Everything must be an long. */
593
+ public long[] getLongArray() {
594
+ long[] outgoing = new long[size()];
595
+ for (int i = 0; i < size(); i++) {
596
+ outgoing[i] = getLong(i);
575
597
  }
598
+ return outgoing;
599
+ }
576
600
 
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;
601
+
602
+ /** Get this entire array as a float array. Everything must be an float. */
603
+ public float[] getFloatArray() {
604
+ float[] outgoing = new float[size()];
605
+ for (int i = 0; i < size(); i++) {
606
+ outgoing[i] = getFloat(i);
586
607
  }
608
+ return outgoing;
609
+ }
587
610
 
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;
611
+
612
+ /** Get this entire array as a double array. Everything must be an double. */
613
+ public double[] getDoubleArray() {
614
+ double[] outgoing = new double[size()];
615
+ for (int i = 0; i < size(); i++) {
616
+ outgoing[i] = getDouble(i);
597
617
  }
618
+ return outgoing;
619
+ }
598
620
 
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;
621
+
622
+ /** Get this entire array as a boolean array. Everything must be a boolean. */
623
+ public boolean[] getBooleanArray() {
624
+ boolean[] outgoing = new boolean[size()];
625
+ for (int i = 0; i < size(); i++) {
626
+ outgoing[i] = getBoolean(i);
608
627
  }
628
+ return outgoing;
629
+ }
630
+
609
631
 
610
632
  // /**
611
633
  // * Get the optional boolean value associated with an index.
@@ -670,81 +692,89 @@ public class JSONArray {
670
692
  // public String optString(int index) {
671
693
  // return this.optString(index, "");
672
694
  // }
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
- }
687
695
 
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
- }
698
696
 
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
- }
697
+ /**
698
+ * Append an String value. This increases the array's length by one.
699
+ *
700
+ * @webref jsonarray:method
701
+ * @brief Appends a value, increasing the array's length by one
702
+ * @param value a String value
703
+ * @return this.
704
+ * @see JSONArray#size()
705
+ * @see JSONArray#remove(int)
706
+ */
707
+ public JSONArray append(String value) {
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
+ }
710
777
 
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
- }
748
778
 
749
779
  // /**
750
780
  // * Put a value in the JSONArray, where the value will be a
@@ -756,6 +786,8 @@ public class JSONArray {
756
786
  // this.append(new JSONArray(value));
757
787
  // return this;
758
788
  // }
789
+
790
+
759
791
  // /**
760
792
  // * Put a value in the JSONArray, where the value will be a
761
793
  // * JSONObject which is produced from a Map.
@@ -766,34 +798,38 @@ public class JSONArray {
766
798
  // this.append(new JSONObject(value));
767
799
  // return this;
768
800
  // }
769
- /**
770
- * @param value a JSONArray value
771
- */
772
- public JSONArray append(JSONArray value) {
773
- myArrayList.add(value);
774
- return this;
775
- }
776
801
 
777
- /**
778
- * @param value a JSONObject value
779
- */
780
- public JSONArray append(JSONObject value) {
781
- myArrayList.add(value);
782
- return this;
783
- }
784
802
 
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
- }
803
+ /**
804
+ * @param value a JSONArray value
805
+ */
806
+ public JSONArray append(JSONArray value) {
807
+ myArrayList.add(value);
808
+ return this;
809
+ }
810
+
811
+
812
+ /**
813
+ * @param value a JSONObject value
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
+
797
833
 
798
834
  // /**
799
835
  // * Put a value in the JSONArray, where the value will be a
@@ -808,114 +844,120 @@ public class JSONArray {
808
844
  // this.set(index, new JSONArray(value));
809
845
  // return this;
810
846
  // }
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
- }
830
847
 
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
- }
864
848
 
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
- }
849
+ /**
850
+ * Put or replace a String value. If the index is greater than the length of
851
+ * the JSONArray, then null elements will be added as necessary to pad
852
+ * it out.
853
+ *
854
+ * @webref jsonarray:method
855
+ * @brief Put a String value in the JSONArray
856
+ * @param index an index value
857
+ * @param value the value to assign
858
+ * @return this.
859
+ * @throws RuntimeException If the index is negative.
860
+ * @see JSONArray#setInt(int, int)
861
+ * @see JSONArray#setFloat(int, float)
862
+ * @see JSONArray#setBoolean(int, boolean)
863
+ */
864
+ public JSONArray setString(int index, String value) {
865
+ this.set(index, value);
866
+ return this;
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
+ }
885
960
 
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
- }
919
961
 
920
962
  // /**
921
963
  // * Put a value in the JSONArray, where the value will be a
@@ -930,103 +972,106 @@ public class JSONArray {
930
972
  // this.set(index, new JSONObject(value));
931
973
  // return this;
932
974
  // }
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
- }
960
975
 
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;
976
+ /**
977
+ * @webref jsonarray:method
978
+ * @brief Sets the JSONArray value associated with an index value
979
+ * @param index the index value to target
980
+ * @param value the value to assign
981
+ * @see JSONArray#setJSONObject(int, JSONObject)
982
+ * @see JSONArray#getJSONObject(int)
983
+ * @see JSONArray#getJSONArray(int)
984
+ */
985
+ public JSONArray setJSONArray(int index, JSONArray value) {
986
+ set(index, value);
987
+ return this;
988
+ }
989
+
990
+ /**
991
+ * @webref jsonarray:method
992
+ * @brief Sets the JSONObject value associated with an index value
993
+ * @param index the index value to target
994
+ * @param value the value to assign
995
+ * @see JSONArray#setJSONArray(int, JSONArray)
996
+ * @see JSONArray#getJSONObject(int)
997
+ * @see JSONArray#getJSONArray(int)
998
+ */
999
+ public JSONArray setJSONObject(int index, JSONObject value) {
1000
+ set(index, value);
1001
+ return this;
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.");
988
1021
  }
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();
1022
+ if (index < this.size()) {
1023
+ this.myArrayList.set(index, value);
1024
+ } else {
1025
+ while (index != this.size()) {
1026
+ this.append(JSONObject.NULL);
1027
+ }
1028
+ this.append(value);
1001
1029
  }
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
+ }
1002
1074
 
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
- }
1030
1075
 
1031
1076
  // /**
1032
1077
  // * Produce a JSONObject by combining a JSONArray of names with the values
@@ -1047,72 +1092,81 @@ public class JSONArray {
1047
1092
  // }
1048
1093
  // return jo;
1049
1094
  // }
1095
+
1096
+
1050
1097
  // protected boolean save(OutputStream output) {
1051
1098
  // return write(PApplet.createWriter(output), null);
1052
1099
  // }
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
- }
1059
1100
 
1060
- public boolean write(PrintWriter output) {
1061
- return write(output, null);
1062
- }
1063
1101
 
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
- }
1080
- }
1081
- output.print(format(indentFactor));
1082
- output.flush();
1083
- return true;
1084
- }
1102
+ public boolean save(File file, String options) {
1103
+ PrintWriter writer = PApplet.createWriter(file);
1104
+ boolean success = write(writer, options);
1105
+ writer.close();
1106
+ return success;
1107
+ }
1085
1108
 
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
- }
1098
- }
1099
1109
 
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>&nbsp;<small>(left bracket)</small>
1108
- * and ending with <code>]</code>&nbsp;<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();
1110
+ public boolean write(PrintWriter output) {
1111
+ return write(output, null);
1112
+ }
1113
+
1114
+
1115
+ public boolean write(PrintWriter output, String options) {
1116
+ int indentFactor = 2;
1117
+ if (options != null) {
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);
1114
1129
  }
1130
+ }
1131
+ }
1132
+ output.print(format(indentFactor));
1133
+ output.flush();
1134
+ return true;
1135
+ }
1136
+
1137
+
1138
+ /**
1139
+ * Return the JSON data formatted with two spaces for indents.
1140
+ * Chosen to do this since it's the most common case (e.g. with println()).
1141
+ * Same as format(2). Use the format() function for more options.
1142
+ */
1143
+ @Override
1144
+ public String toString() {
1145
+ try {
1146
+ return format(2);
1147
+ } catch (Exception e) {
1148
+ return null;
1115
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>&nbsp;<small>(left bracket)</small> and ending
1161
+ * with <code>]</code>&nbsp;<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();
1167
+ }
1168
+ }
1169
+
1116
1170
 
1117
1171
  // /**
1118
1172
  // * Write the contents of the JSONArray as JSON text to a writer. For
@@ -1125,78 +1179,82 @@ public class JSONArray {
1125
1179
  // protected Writer write(Writer writer) {
1126
1180
  // return this.write(writer, -1, 0);
1127
1181
  // }
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);
1182
+
1183
+
1184
+ /**
1185
+ * Write the contents of the JSONArray as JSON text to a writer.
1186
+ * <p>
1187
+ * Warning: This method assumes that the data structure is acyclic.
1188
+ *
1189
+ * @param indentFactor
1190
+ * The number of spaces to add to each level of indentation.
1191
+ * Use -1 to specify no indentation and no newlines.
1192
+ * @param indent
1193
+ * The indention of the top level.
1194
+ * @return The writer.
1195
+ * @throws RuntimeException
1196
+ */
1197
+ protected Writer writeInternal(Writer writer, int indentFactor, int indent) {
1198
+ try {
1199
+ boolean commanate = false;
1200
+ int length = this.size();
1201
+ writer.write('[');
1202
+
1203
+ // Use -1 to signify 'no indent'
1204
+ int thisFactor = (indentFactor == -1) ? 0 : indentFactor;
1205
+
1206
+ if (length == 1) {
1207
+ JSONObject.writeValue(writer, this.myArrayList.get(0),
1208
+ indentFactor, indent);
1151
1209
  // thisFactor, indent);
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);
1210
+ } else if (length != 0) {
1211
+ final int newIndent = indent + thisFactor;
1212
+
1213
+ for (int i = 0; i < length; i += 1) {
1214
+ if (commanate) {
1215
+ writer.write(',');
1216
+ }
1217
+ if (indentFactor != -1) {
1218
+ writer.write('\n');
1219
+ }
1220
+ JSONObject.indent(writer, newIndent);
1163
1221
  // JSONObject.writeValue(writer, this.myArrayList.get(i),
1164
1222
  // thisFactor, newIndent);
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);
1223
+ JSONObject.writeValue(writer, this.myArrayList.get(i),
1224
+ indentFactor, newIndent);
1225
+ commanate = true;
1178
1226
  }
1179
- }
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)));
1227
+ if (indentFactor != -1) {
1228
+ writer.write('\n');
1199
1229
  }
1200
- return sb.toString();
1230
+ JSONObject.indent(writer, indent);
1231
+ }
1232
+ writer.write(']');
1233
+ return writer;
1234
+ } catch (IOException e) {
1235
+ throw new RuntimeException(e);
1236
+ }
1237
+ }
1238
+
1239
+
1240
+ /**
1241
+ * Make a string from the contents of this JSONArray. The
1242
+ * <code>separator</code> string is inserted between each element.
1243
+ * Warning: This method assumes that the data structure is acyclic.
1244
+ * @param separator A string that will be inserted between the elements.
1245
+ * @return a string.
1246
+ * @throws RuntimeException If the array contains an invalid number.
1247
+ */
1248
+ public String join(String separator) {
1249
+ int len = this.size();
1250
+ StringBuilder sb = new StringBuilder();
1251
+
1252
+ for (int i = 0; i < len; i += 1) {
1253
+ if (i > 0) {
1254
+ sb.append(separator);
1255
+ }
1256
+ sb.append(JSONObject.valueToString(this.myArrayList.get(i)));
1201
1257
  }
1258
+ return sb.toString();
1259
+ }
1202
1260
  }