propane 3.9.0-java → 3.10.0-java

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