propane 2.7.2-java → 2.8.0.pre-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +10 -0
  3. data/CHANGELOG.md +1 -1
  4. data/README.md +10 -8
  5. data/Rakefile +1 -1
  6. data/lib/propane/app.rb +3 -3
  7. data/lib/propane/version.rb +1 -1
  8. data/lib/{processing-core.jar → propane-2.8.0.jar} +0 -0
  9. data/library/control_panel/control_panel.rb +3 -2
  10. data/pom.rb +89 -88
  11. data/pom.xml +75 -46
  12. data/propane.gemspec +1 -2
  13. data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
  14. data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
  15. data/src/{monkstone → main/java/monkstone}/ColorUtil.java +0 -0
  16. data/src/{monkstone → main/java/monkstone}/MathToolModule.java +0 -0
  17. data/src/{monkstone → main/java/monkstone}/PropaneLibrary.java +0 -0
  18. data/src/{monkstone → main/java/monkstone}/core/LibraryProxy.java +0 -0
  19. data/src/{monkstone → main/java/monkstone}/fastmath/Deglut.java +0 -0
  20. data/src/{monkstone → main/java/monkstone}/fastmath/package-info.java +0 -0
  21. data/src/{monkstone → main/java/monkstone}/filechooser/Chooser.java +0 -0
  22. data/src/{monkstone → main/java/monkstone}/noise/SimplexNoise.java +0 -0
  23. data/src/{monkstone → main/java/monkstone}/slider/CustomHorizontalSlider.java +0 -0
  24. data/src/{monkstone → main/java/monkstone}/slider/CustomVerticalSlider.java +0 -0
  25. data/src/{monkstone → main/java/monkstone}/slider/SimpleHorizontalSlider.java +0 -0
  26. data/src/{monkstone → main/java/monkstone}/slider/SimpleSlider.java +0 -0
  27. data/src/{monkstone → main/java/monkstone}/slider/SimpleVerticalSlider.java +0 -0
  28. data/src/{monkstone → main/java/monkstone}/slider/Slider.java +0 -0
  29. data/src/{monkstone → main/java/monkstone}/slider/SliderBar.java +0 -0
  30. data/src/{monkstone → main/java/monkstone}/slider/SliderGroup.java +0 -0
  31. data/src/{monkstone → main/java/monkstone}/slider/WheelHandler.java +0 -0
  32. data/src/{monkstone → main/java/monkstone}/vecmath/AppRender.java +0 -0
  33. data/src/{monkstone → main/java/monkstone}/vecmath/JRender.java +0 -0
  34. data/src/{monkstone → main/java/monkstone}/vecmath/ShapeRender.java +0 -0
  35. data/src/{monkstone → main/java/monkstone}/vecmath/package-info.java +0 -0
  36. data/src/{monkstone → main/java/monkstone}/vecmath/vec2/Vec2.java +0 -0
  37. data/src/{monkstone → main/java/monkstone}/vecmath/vec2/package-info.java +0 -0
  38. data/src/{monkstone → main/java/monkstone}/vecmath/vec3/Vec3.java +0 -0
  39. data/src/{monkstone → main/java/monkstone}/vecmath/vec3/package-info.java +0 -0
  40. data/src/{monkstone → main/java/monkstone}/videoevent/VideoInterface.java +0 -0
  41. data/src/{monkstone → main/java/monkstone}/videoevent/package-info.java +0 -0
  42. data/src/main/java/processing/awt/PGraphicsJava2D.java +3029 -0
  43. data/src/main/java/processing/awt/PShapeJava2D.java +377 -0
  44. data/src/main/java/processing/awt/PSurfaceAWT.java +1567 -0
  45. data/src/main/java/processing/core/PApplet.java +15709 -0
  46. data/src/main/java/processing/core/PConstants.java +527 -0
  47. data/src/main/java/processing/core/PFont.java +1098 -0
  48. data/src/main/java/processing/core/PGraphics.java +8467 -0
  49. data/src/main/java/processing/core/PImage.java +3438 -0
  50. data/src/main/java/processing/core/PMatrix.java +208 -0
  51. data/src/main/java/processing/core/PMatrix2D.java +534 -0
  52. data/src/main/java/processing/core/PMatrix3D.java +877 -0
  53. data/src/main/java/processing/core/PShape.java +3445 -0
  54. data/src/main/java/processing/core/PShapeOBJ.java +469 -0
  55. data/src/main/java/processing/core/PShapeSVG.java +1787 -0
  56. data/src/main/java/processing/core/PStyle.java +63 -0
  57. data/src/main/java/processing/core/PSurface.java +161 -0
  58. data/src/main/java/processing/core/PSurfaceNone.java +374 -0
  59. data/src/main/java/processing/core/PVector.java +1063 -0
  60. data/src/main/java/processing/data/FloatDict.java +829 -0
  61. data/src/main/java/processing/data/FloatList.java +912 -0
  62. data/src/main/java/processing/data/IntDict.java +796 -0
  63. data/src/main/java/processing/data/IntList.java +913 -0
  64. data/src/main/java/processing/data/JSONArray.java +1260 -0
  65. data/src/main/java/processing/data/JSONObject.java +2282 -0
  66. data/src/main/java/processing/data/JSONTokener.java +435 -0
  67. data/src/main/java/processing/data/Sort.java +46 -0
  68. data/src/main/java/processing/data/StringDict.java +601 -0
  69. data/src/main/java/processing/data/StringList.java +775 -0
  70. data/src/main/java/processing/data/Table.java +4923 -0
  71. data/src/main/java/processing/data/TableRow.java +198 -0
  72. data/src/main/java/processing/data/XML.java +1149 -0
  73. data/src/main/java/processing/event/Event.java +125 -0
  74. data/src/main/java/processing/event/KeyEvent.java +70 -0
  75. data/src/main/java/processing/event/MouseEvent.java +149 -0
  76. data/src/main/java/processing/event/TouchEvent.java +57 -0
  77. data/src/main/java/processing/opengl/FontTexture.java +379 -0
  78. data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
  79. data/src/main/java/processing/opengl/LinePath.java +623 -0
  80. data/src/main/java/processing/opengl/LineStroker.java +685 -0
  81. data/src/main/java/processing/opengl/PGL.java +3366 -0
  82. data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
  83. data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
  84. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
  85. data/src/main/java/processing/opengl/PJOGL.java +1966 -0
  86. data/src/main/java/processing/opengl/PShader.java +1478 -0
  87. data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
  88. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
  89. data/src/main/java/processing/opengl/Texture.java +1670 -0
  90. data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
  91. data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
  92. data/src/main/java/processing/opengl/cursors/cross.png +0 -0
  93. data/src/main/java/processing/opengl/cursors/hand.png +0 -0
  94. data/src/main/java/processing/opengl/cursors/license.txt +27 -0
  95. data/src/main/java/processing/opengl/cursors/move.png +0 -0
  96. data/src/main/java/processing/opengl/cursors/text.png +0 -0
  97. data/src/main/java/processing/opengl/cursors/wait.png +0 -0
  98. data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
  99. data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
  100. data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
  101. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
  102. data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
  103. data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
  104. data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
  105. data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
  106. data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
  107. data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
  108. data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
  109. data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
  110. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
  111. data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
  112. data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
  113. data/src/main/resources/icon/icon-1024.png +0 -0
  114. data/src/main/resources/icon/icon-128.png +0 -0
  115. data/src/main/resources/icon/icon-16.png +0 -0
  116. data/src/main/resources/icon/icon-256.png +0 -0
  117. data/src/main/resources/icon/icon-32.png +0 -0
  118. data/src/main/resources/icon/icon-48.png +0 -0
  119. data/src/main/resources/icon/icon-512.png +0 -0
  120. data/src/main/resources/icon/icon-64.png +0 -0
  121. data/src/main/resources/license.txt +508 -0
  122. data/vendors/Rakefile +5 -20
  123. metadata +115 -33
  124. data/lib/propane.jar +0 -0
@@ -0,0 +1,775 @@
1
+ package processing.data;
2
+
3
+ import java.util.Arrays;
4
+ import java.util.Iterator;
5
+ import java.util.Random;
6
+
7
+ import processing.core.PApplet;
8
+
9
+ /**
10
+ * Helper class for a list of Strings. Lists are designed to have some of the
11
+ * features of ArrayLists, but to maintain the simplicity and efficiency of
12
+ * working with arrays.
13
+ *
14
+ * Functions like sort() and shuffle() always act on the list itself. To get
15
+ * a sorted copy, use list.copy().sort().
16
+ *
17
+ * @webref data:composite
18
+ * @see IntList
19
+ * @see FloatList
20
+ */
21
+ public class StringList implements Iterable<String> {
22
+ int count;
23
+ String[] data;
24
+
25
+
26
+ public StringList() {
27
+ this(10);
28
+ }
29
+
30
+ /**
31
+ * @nowebref
32
+ */
33
+ public StringList(int length) {
34
+ data = new String[length];
35
+ }
36
+
37
+ /**
38
+ * @nowebref
39
+ */
40
+ public StringList(String[] list) {
41
+ count = list.length;
42
+ data = new String[count];
43
+ System.arraycopy(list, 0, data, 0, count);
44
+ }
45
+
46
+
47
+ /**
48
+ * Construct a StringList from a random pile of objects. Null values will
49
+ * stay null, but all the others will be converted to String values.
50
+ */
51
+ public StringList(Object... items) {
52
+ count = items.length;
53
+ data = new String[count];
54
+ int index = 0;
55
+ for (Object o : items) {
56
+ // // Not gonna go with null values staying that way because perhaps
57
+ // // the most common case here is to immediately call join() or similar.
58
+ // data[index++] = String.valueOf(o);
59
+ // Keep null values null (because join() will make non-null anyway)
60
+ if (o != null) { // leave null values null
61
+ data[index] = o.toString();
62
+ }
63
+ index++;
64
+ }
65
+ }
66
+
67
+
68
+ /**
69
+ * Create from something iterable, for instance:
70
+ * StringList list = new StringList(hashMap.keySet());
71
+ *
72
+ * @nowebref
73
+ */
74
+ public StringList(Iterable<String> iter) {
75
+ this(10);
76
+ for (String s : iter) {
77
+ append(s);
78
+ }
79
+ }
80
+
81
+
82
+ /**
83
+ * Improve efficiency by removing allocated but unused entries from the
84
+ * internal array used to store the data. Set to private, though it could
85
+ * be useful to have this public if lists are frequently making drastic
86
+ * size changes (from very large to very small).
87
+ */
88
+ private void crop() {
89
+ if (count != data.length) {
90
+ data = PApplet.subset(data, 0, count);
91
+ }
92
+ }
93
+
94
+
95
+ /**
96
+ * Get the length of the list.
97
+ *
98
+ * @webref stringlist:method
99
+ * @brief Get the length of the list
100
+ */
101
+ public int size() {
102
+ return count;
103
+ }
104
+
105
+
106
+ public void resize(int length) {
107
+ if (length > data.length) {
108
+ String[] temp = new String[length];
109
+ System.arraycopy(data, 0, temp, 0, count);
110
+ data = temp;
111
+
112
+ } else if (length > count) {
113
+ Arrays.fill(data, count, length, 0);
114
+ }
115
+ count = length;
116
+ }
117
+
118
+
119
+ /**
120
+ * Remove all entries from the list.
121
+ *
122
+ * @webref stringlist:method
123
+ * @brief Remove all entries from the list
124
+ */
125
+ public void clear() {
126
+ count = 0;
127
+ }
128
+
129
+
130
+ /**
131
+ * Get an entry at a particular index.
132
+ *
133
+ * @webref stringlist:method
134
+ * @brief Get an entry at a particular index
135
+ */
136
+ public String get(int index) {
137
+ if (index >= count) {
138
+ throw new ArrayIndexOutOfBoundsException(index);
139
+ }
140
+ return data[index];
141
+ }
142
+
143
+
144
+ /**
145
+ * Set the entry at a particular index. If the index is past the length of
146
+ * the list, it'll expand the list to accommodate, and fill the intermediate
147
+ * entries with 0s.
148
+ *
149
+ * @webref stringlist:method
150
+ * @brief Set an entry at a particular index
151
+ */
152
+ public void set(int index, String what) {
153
+ if (index >= count) {
154
+ data = PApplet.expand(data, index+1);
155
+ for (int i = count; i < index; i++) {
156
+ data[i] = null;
157
+ }
158
+ count = index+1;
159
+ }
160
+ data[index] = what;
161
+ }
162
+
163
+
164
+ /** Just an alias for append(), but matches pop() */
165
+ public void push(String value) {
166
+ append(value);
167
+ }
168
+
169
+
170
+ public String pop() {
171
+ if (count == 0) {
172
+ throw new RuntimeException("Can't call pop() on an empty list");
173
+ }
174
+ String value = get(count-1);
175
+ data[--count] = null; // avoid leak
176
+ return value;
177
+ }
178
+
179
+
180
+ /**
181
+ * Remove an element from the specified index.
182
+ *
183
+ * @webref stringlist:method
184
+ * @brief Remove an element from the specified index
185
+ */
186
+ public String remove(int index) {
187
+ if (index < 0 || index >= count) {
188
+ throw new ArrayIndexOutOfBoundsException(index);
189
+ }
190
+ String entry = data[index];
191
+ // int[] outgoing = new int[count - 1];
192
+ // System.arraycopy(data, 0, outgoing, 0, index);
193
+ // count--;
194
+ // System.arraycopy(data, index + 1, outgoing, 0, count - index);
195
+ // data = outgoing;
196
+ for (int i = index; i < count-1; i++) {
197
+ data[i] = data[i+1];
198
+ }
199
+ count--;
200
+ return entry;
201
+ }
202
+
203
+
204
+ // Remove the first instance of a particular value and return its index.
205
+ public int removeValue(String value) {
206
+ if (value == null) {
207
+ for (int i = 0; i < count; i++) {
208
+ if (data[i] == null) {
209
+ remove(i);
210
+ return i;
211
+ }
212
+ }
213
+ } else {
214
+ int index = index(value);
215
+ if (index != -1) {
216
+ remove(index);
217
+ return index;
218
+ }
219
+ }
220
+ return -1;
221
+ }
222
+
223
+
224
+ // Remove all instances of a particular value and return the count removed.
225
+ public int removeValues(String value) {
226
+ int ii = 0;
227
+ if (value == null) {
228
+ for (int i = 0; i < count; i++) {
229
+ if (data[i] != null) {
230
+ data[ii++] = data[i];
231
+ }
232
+ }
233
+ } else {
234
+ for (int i = 0; i < count; i++) {
235
+ if (!value.equals(data[i])) {
236
+ data[ii++] = data[i];
237
+ }
238
+ }
239
+ }
240
+ int removed = count - ii;
241
+ count = ii;
242
+ return removed;
243
+ }
244
+
245
+
246
+ // replace the first value that matches, return the index that was replaced
247
+ public int replaceValue(String value, String newValue) {
248
+ if (value == null) {
249
+ for (int i = 0; i < count; i++) {
250
+ if (data[i] == null) {
251
+ data[i] = newValue;
252
+ return i;
253
+ }
254
+ }
255
+ } else {
256
+ for (int i = 0; i < count; i++) {
257
+ if (value.equals(data[i])) {
258
+ data[i] = newValue;
259
+ return i;
260
+ }
261
+ }
262
+ }
263
+ return -1;
264
+ }
265
+
266
+
267
+ // replace all values that match, return the count of those replaced
268
+ public int replaceValues(String value, String newValue) {
269
+ int changed = 0;
270
+ if (value == null) {
271
+ for (int i = 0; i < count; i++) {
272
+ if (data[i] == null) {
273
+ data[i] = newValue;
274
+ changed++;
275
+ }
276
+ }
277
+ } else {
278
+ for (int i = 0; i < count; i++) {
279
+ if (value.equals(data[i])) {
280
+ data[i] = newValue;
281
+ changed++;
282
+ }
283
+ }
284
+ }
285
+ return changed;
286
+ }
287
+
288
+
289
+ /**
290
+ * Add a new entry to the list.
291
+ *
292
+ * @webref stringlist:method
293
+ * @brief Add a new entry to the list
294
+ */
295
+ public void append(String value) {
296
+ if (count == data.length) {
297
+ data = PApplet.expand(data);
298
+ }
299
+ data[count++] = value;
300
+ }
301
+
302
+
303
+ public void append(String[] values) {
304
+ for (String v : values) {
305
+ append(v);
306
+ }
307
+ }
308
+
309
+
310
+ public void append(StringList list) {
311
+ for (String v : list.values()) { // will concat the list...
312
+ append(v);
313
+ }
314
+ }
315
+
316
+
317
+ /** Add this value, but only if it's not already in the list. */
318
+ public void appendUnique(String value) {
319
+ if (!hasValue(value)) {
320
+ append(value);
321
+ }
322
+ }
323
+
324
+
325
+ // public void insert(int index, int value) {
326
+ // if (index+1 > count) {
327
+ // if (index+1 < data.length) {
328
+ // }
329
+ // }
330
+ // if (index >= data.length) {
331
+ // data = PApplet.expand(data, index+1);
332
+ // data[index] = value;
333
+ // count = index+1;
334
+ //
335
+ // } else if (count == data.length) {
336
+ // if (index >= count) {
337
+ // //int[] temp = new int[count << 1];
338
+ // System.arraycopy(data, 0, temp, 0, index);
339
+ // temp[index] = value;
340
+ // System.arraycopy(data, index, temp, index+1, count - index);
341
+ // data = temp;
342
+ //
343
+ // } else {
344
+ // // data[] has room to grow
345
+ // // for() loop believed to be faster than System.arraycopy over itself
346
+ // for (int i = count; i > index; --i) {
347
+ // data[i] = data[i-1];
348
+ // }
349
+ // data[index] = value;
350
+ // count++;
351
+ // }
352
+ // }
353
+
354
+
355
+ public void insert(int index, String value) {
356
+ insert(index, new String[] { value });
357
+ }
358
+
359
+
360
+ // same as splice
361
+ public void insert(int index, String[] values) {
362
+ if (index < 0) {
363
+ throw new IllegalArgumentException("insert() index cannot be negative: it was " + index);
364
+ }
365
+ if (index >= data.length) {
366
+ throw new IllegalArgumentException("insert() index " + index + " is past the end of this list");
367
+ }
368
+
369
+ String[] temp = new String[count + values.length];
370
+
371
+ // Copy the old values, but not more than already exist
372
+ System.arraycopy(data, 0, temp, 0, Math.min(count, index));
373
+
374
+ // Copy the new values into the proper place
375
+ System.arraycopy(values, 0, temp, index, values.length);
376
+
377
+ // if (index < count) {
378
+ // The index was inside count, so it's a true splice/insert
379
+ System.arraycopy(data, index, temp, index+values.length, count - index);
380
+ count = count + values.length;
381
+ // } else {
382
+ // // The index was past 'count', so the new count is weirder
383
+ // count = index + values.length;
384
+ // }
385
+ data = temp;
386
+ }
387
+
388
+
389
+ public void insert(int index, StringList list) {
390
+ insert(index, list.values());
391
+ }
392
+
393
+
394
+ // below are aborted attempts at more optimized versions of the code
395
+ // that are harder to read and debug...
396
+
397
+ // if (index + values.length >= count) {
398
+ // // We're past the current 'count', check to see if we're still allocated
399
+ // // index 9, data.length = 10, values.length = 1
400
+ // if (index + values.length < data.length) {
401
+ // // There's still room for these entries, even though it's past 'count'.
402
+ // // First clear out the entries leading up to it, however.
403
+ // for (int i = count; i < index; i++) {
404
+ // data[i] = 0;
405
+ // }
406
+ // data[index] =
407
+ // }
408
+ // if (index >= data.length) {
409
+ // int length = index + values.length;
410
+ // int[] temp = new int[length];
411
+ // System.arraycopy(data, 0, temp, 0, count);
412
+ // System.arraycopy(values, 0, temp, index, values.length);
413
+ // data = temp;
414
+ // count = data.length;
415
+ // } else {
416
+ //
417
+ // }
418
+ //
419
+ // } else if (count == data.length) {
420
+ // int[] temp = new int[count << 1];
421
+ // System.arraycopy(data, 0, temp, 0, index);
422
+ // temp[index] = value;
423
+ // System.arraycopy(data, index, temp, index+1, count - index);
424
+ // data = temp;
425
+ //
426
+ // } else {
427
+ // // data[] has room to grow
428
+ // // for() loop believed to be faster than System.arraycopy over itself
429
+ // for (int i = count; i > index; --i) {
430
+ // data[i] = data[i-1];
431
+ // }
432
+ // data[index] = value;
433
+ // count++;
434
+ // }
435
+
436
+
437
+ /** Return the first index of a particular value. */
438
+ public int index(String what) {
439
+ if (what == null) {
440
+ for (int i = 0; i < count; i++) {
441
+ if (data[i] == null) {
442
+ return i;
443
+ }
444
+ }
445
+ } else {
446
+ for (int i = 0; i < count; i++) {
447
+ if (what.equals(data[i])) {
448
+ return i;
449
+ }
450
+ }
451
+ }
452
+ return -1;
453
+ }
454
+
455
+
456
+ // !!! TODO this is not yet correct, because it's not being reset when
457
+ // the rest of the entries are changed
458
+ // protected void cacheIndices() {
459
+ // indexCache = new HashMap<Integer, Integer>();
460
+ // for (int i = 0; i < count; i++) {
461
+ // indexCache.put(data[i], i);
462
+ // }
463
+ // }
464
+
465
+ /**
466
+ * @webref stringlist:method
467
+ * @brief Check if a value is a part of the list
468
+ */
469
+ public boolean hasValue(String value) {
470
+ if (value == null) {
471
+ for (int i = 0; i < count; i++) {
472
+ if (data[i] == null) {
473
+ return true;
474
+ }
475
+ }
476
+ } else {
477
+ for (int i = 0; i < count; i++) {
478
+ if (value.equals(data[i])) {
479
+ return true;
480
+ }
481
+ }
482
+ }
483
+ return false;
484
+ }
485
+
486
+
487
+ /**
488
+ * Sorts the array in place.
489
+ *
490
+ * @webref stringlist:method
491
+ * @brief Sorts the array in place
492
+ */
493
+ public void sort() {
494
+ sortImpl(false);
495
+ }
496
+
497
+
498
+ /**
499
+ * Reverse sort, orders values from highest to lowest.
500
+ *
501
+ * @webref stringlist:method
502
+ * @brief Reverse sort, orders values from highest to lowest
503
+ */
504
+ public void sortReverse() {
505
+ sortImpl(true);
506
+ }
507
+
508
+
509
+ private void sortImpl(final boolean reverse) {
510
+ new Sort() {
511
+ @Override
512
+ public int size() {
513
+ return count;
514
+ }
515
+
516
+ @Override
517
+ public float compare(int a, int b) {
518
+ float diff = data[a].compareToIgnoreCase(data[b]);
519
+ return reverse ? -diff : diff;
520
+ }
521
+
522
+ @Override
523
+ public void swap(int a, int b) {
524
+ String temp = data[a];
525
+ data[a] = data[b];
526
+ data[b] = temp;
527
+ }
528
+ }.run();
529
+ }
530
+
531
+
532
+ // use insert()
533
+ // public void splice(int index, int value) {
534
+ // }
535
+
536
+
537
+ // public void subset(int start) {
538
+ // subset(start, count - start);
539
+ // }
540
+ //
541
+ //
542
+ // public void subset(int start, int num) {
543
+ // for (int i = 0; i < num; i++) {
544
+ // data[i] = data[i+start];
545
+ // }
546
+ // count = num;
547
+ // }
548
+
549
+ /**
550
+ * @webref stringlist:method
551
+ * @brief Reverse the order of the list elements
552
+ */
553
+ public void reverse() {
554
+ int ii = count - 1;
555
+ for (int i = 0; i < count/2; i++) {
556
+ String t = data[i];
557
+ data[i] = data[ii];
558
+ data[ii] = t;
559
+ --ii;
560
+ }
561
+ }
562
+
563
+
564
+ /**
565
+ * Randomize the order of the list elements. Note that this does not
566
+ * obey the randomSeed() function in PApplet.
567
+ *
568
+ * @webref stringlist:method
569
+ * @brief Randomize the order of the list elements
570
+ */
571
+ public void shuffle() {
572
+ Random r = new Random();
573
+ int num = count;
574
+ while (num > 1) {
575
+ int value = r.nextInt(num);
576
+ num--;
577
+ String temp = data[num];
578
+ data[num] = data[value];
579
+ data[value] = temp;
580
+ }
581
+ }
582
+
583
+
584
+ /**
585
+ * Randomize the list order using the random() function from the specified
586
+ * sketch, allowing shuffle() to use its current randomSeed() setting.
587
+ */
588
+ public void shuffle(PApplet sketch) {
589
+ int num = count;
590
+ while (num > 1) {
591
+ int value = (int) sketch.random(num);
592
+ num--;
593
+ String temp = data[num];
594
+ data[num] = data[value];
595
+ data[value] = temp;
596
+ }
597
+ }
598
+
599
+
600
+ /**
601
+ * Make the entire list lower case.
602
+ *
603
+ * @webref stringlist:method
604
+ * @brief Make the entire list lower case
605
+ */
606
+ public void lower() {
607
+ for (int i = 0; i < count; i++) {
608
+ if (data[i] != null) {
609
+ data[i] = data[i].toLowerCase();
610
+ }
611
+ }
612
+ }
613
+
614
+
615
+ /**
616
+ * Make the entire list upper case.
617
+ *
618
+ * @webref stringlist:method
619
+ * @brief Make the entire list upper case
620
+ */
621
+ public void upper() {
622
+ for (int i = 0; i < count; i++) {
623
+ if (data[i] != null) {
624
+ data[i] = data[i].toUpperCase();
625
+ }
626
+ }
627
+ }
628
+
629
+
630
+ public StringList copy() {
631
+ StringList outgoing = new StringList(data);
632
+ outgoing.count = count;
633
+ return outgoing;
634
+ }
635
+
636
+
637
+ /**
638
+ * Returns the actual array being used to store the data. Suitable for
639
+ * iterating with a for() loop, but modifying the list could cause terrible
640
+ * things to happen.
641
+ */
642
+ public String[] values() {
643
+ crop();
644
+ return data;
645
+ }
646
+
647
+
648
+ @Override
649
+ public Iterator<String> iterator() {
650
+ // return valueIterator();
651
+ // }
652
+ //
653
+ //
654
+ // public Iterator<String> valueIterator() {
655
+ return new Iterator<String>() {
656
+ int index = -1;
657
+
658
+ public void remove() {
659
+ StringList.this.remove(index);
660
+ index--;
661
+ }
662
+
663
+ public String next() {
664
+ return data[++index];
665
+ }
666
+
667
+ public boolean hasNext() {
668
+ return index+1 < count;
669
+ }
670
+ };
671
+ }
672
+
673
+
674
+ /**
675
+ * Create a new array with a copy of all the values.
676
+ *
677
+ * @return an array sized by the length of the list with each of the values.
678
+ * @webref stringlist:method
679
+ * @brief Create a new array with a copy of all the values
680
+ */
681
+ public String[] array() {
682
+ return array(null);
683
+ }
684
+
685
+
686
+ /**
687
+ * Copy values into the specified array. If the specified array is null or
688
+ * not the same size, a new array will be allocated.
689
+ * @param array
690
+ */
691
+ public String[] array(String[] array) {
692
+ if (array == null || array.length != count) {
693
+ array = new String[count];
694
+ }
695
+ System.arraycopy(data, 0, array, 0, count);
696
+ return array;
697
+ }
698
+
699
+
700
+ public StringList getSubset(int start) {
701
+ return getSubset(start, count - start);
702
+ }
703
+
704
+
705
+ public StringList getSubset(int start, int num) {
706
+ String[] subset = new String[num];
707
+ System.arraycopy(data, start, subset, 0, num);
708
+ return new StringList(subset);
709
+ }
710
+
711
+
712
+ /** Get a list of all unique entries. */
713
+ public String[] getUnique() {
714
+ return getTally().keyArray();
715
+ }
716
+
717
+
718
+ /** Count the number of times each String entry is found in this list. */
719
+ public IntDict getTally() {
720
+ IntDict outgoing = new IntDict();
721
+ for (int i = 0; i < count; i++) {
722
+ outgoing.increment(data[i]);
723
+ }
724
+ return outgoing;
725
+ }
726
+
727
+
728
+ /** Create a dictionary associating each entry in this list to its index. */
729
+ public IntDict getOrder() {
730
+ IntDict outgoing = new IntDict();
731
+ for (int i = 0; i < count; i++) {
732
+ outgoing.set(data[i], i);
733
+ }
734
+ return outgoing;
735
+ }
736
+
737
+
738
+ public String join(String separator) {
739
+ if (count == 0) {
740
+ return "";
741
+ }
742
+ StringBuilder sb = new StringBuilder();
743
+ sb.append(data[0]);
744
+ for (int i = 1; i < count; i++) {
745
+ sb.append(separator);
746
+ sb.append(data[i]);
747
+ }
748
+ return sb.toString();
749
+ }
750
+
751
+
752
+ public void print() {
753
+ for (int i = 0; i < count; i++) {
754
+ System.out.format("[%d] %s%n", i, data[i]);
755
+ }
756
+ }
757
+
758
+
759
+ /**
760
+ * Return this dictionary as a String in JSON format.
761
+ */
762
+ public String toJSON() {
763
+ StringList temp = new StringList();
764
+ for (String item : this) {
765
+ temp.append(JSONObject.quote(item));
766
+ }
767
+ return "[ " + temp.join(", ") + " ]";
768
+ }
769
+
770
+
771
+ @Override
772
+ public String toString() {
773
+ return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
774
+ }
775
+ }