propane 3.1.0.pre-java → 3.2.0-java

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