propane 3.4.2-java → 3.8.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -1
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +1 -1
  6. data/CHANGELOG.md +9 -1
  7. data/Gemfile +2 -0
  8. data/README.md +7 -10
  9. data/Rakefile +10 -11
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +4 -2
  12. data/lib/propane/app.rb +5 -1
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +22 -23
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +10 -9
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +20 -14
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +2 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +2 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +2 -0
  33. data/library/slider/slider.rb +23 -22
  34. data/library/vector_utils/vector_utils.rb +4 -0
  35. data/library/video_event/video_event.rb +2 -0
  36. data/pom.rb +37 -36
  37. data/pom.xml +7 -7
  38. data/propane.gemspec +13 -9
  39. data/src/main/java/japplemenubar/JAppleMenuBar.java +3 -3
  40. data/src/main/java/monkstone/ColorUtil.java +1 -3
  41. data/src/main/java/monkstone/MathToolModule.java +1 -1
  42. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  43. data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
  44. data/src/main/java/monkstone/fastmath/Deglut.java +6 -56
  45. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  46. data/src/main/java/monkstone/noise/Noise.java +116 -0
  47. data/src/main/java/monkstone/noise/NoiseGenerator.java +63 -0
  48. data/src/main/java/monkstone/noise/NoiseMode.java +15 -0
  49. data/src/main/java/monkstone/noise/SimplexNoise.java +137 -103
  50. data/src/main/java/monkstone/noise/ValueNoise.java +170 -0
  51. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  53. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  54. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  55. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  56. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  57. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  58. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  59. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  60. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
  61. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  62. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  63. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  64. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  65. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  66. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  67. data/src/main/java/processing/awt/PSurfaceAWT.java +308 -208
  68. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  69. data/src/main/java/processing/core/PApplet.java +13142 -13883
  70. data/src/main/java/processing/core/PConstants.java +477 -447
  71. data/src/main/java/processing/core/PFont.java +914 -880
  72. data/src/main/java/processing/core/PGraphics.java +152 -136
  73. data/src/main/java/processing/core/PImage.java +275 -372
  74. data/src/main/java/processing/core/PMatrix.java +172 -159
  75. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  76. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  77. data/src/main/java/processing/core/PShape.java +2887 -2651
  78. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  79. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  80. data/src/main/java/processing/core/PStyle.java +40 -37
  81. data/src/main/java/processing/core/PSurface.java +139 -97
  82. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  83. data/src/main/java/processing/core/PVector.java +995 -963
  84. data/src/main/java/processing/core/ThinkDifferent.java +12 -8
  85. data/src/main/java/processing/data/DoubleDict.java +756 -710
  86. data/src/main/java/processing/data/DoubleList.java +749 -696
  87. data/src/main/java/processing/data/FloatDict.java +748 -702
  88. data/src/main/java/processing/data/FloatList.java +751 -697
  89. data/src/main/java/processing/data/IntDict.java +720 -673
  90. data/src/main/java/processing/data/IntList.java +699 -633
  91. data/src/main/java/processing/data/JSONArray.java +931 -873
  92. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  93. data/src/main/java/processing/data/JSONTokener.java +351 -341
  94. data/src/main/java/processing/data/LongDict.java +710 -663
  95. data/src/main/java/processing/data/LongList.java +701 -635
  96. data/src/main/java/processing/data/Sort.java +37 -41
  97. data/src/main/java/processing/data/StringDict.java +525 -486
  98. data/src/main/java/processing/data/StringList.java +626 -580
  99. data/src/main/java/processing/data/Table.java +3690 -3510
  100. data/src/main/java/processing/data/TableRow.java +182 -183
  101. data/src/main/java/processing/data/XML.java +957 -883
  102. data/src/main/java/processing/event/Event.java +87 -67
  103. data/src/main/java/processing/event/KeyEvent.java +48 -41
  104. data/src/main/java/processing/event/MouseEvent.java +88 -113
  105. data/src/main/java/processing/event/TouchEvent.java +10 -6
  106. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  107. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  108. data/src/main/java/processing/net/Client.java +20 -20
  109. data/src/main/java/processing/net/Server.java +9 -9
  110. data/src/main/java/processing/opengl/FontTexture.java +286 -266
  111. data/src/main/java/processing/opengl/FrameBuffer.java +389 -377
  112. data/src/main/java/processing/opengl/LinePath.java +132 -89
  113. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  114. data/src/main/java/processing/opengl/PGL.java +660 -567
  115. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  116. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  117. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  118. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  119. data/src/main/java/processing/opengl/PShader.java +369 -461
  120. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  121. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  122. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  123. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  124. data/test/create_test.rb +21 -20
  125. data/test/deglut_spec_test.rb +4 -2
  126. data/test/helper_methods_test.rb +49 -20
  127. data/test/math_tool_test.rb +39 -32
  128. data/test/native_folder.rb +47 -0
  129. data/test/respond_to_test.rb +3 -2
  130. data/test/sketches/key_event.rb +2 -2
  131. data/test/sketches/library/my_library/my_library.rb +3 -0
  132. data/test/test_helper.rb +2 -0
  133. data/test/vecmath_spec_test.rb +35 -22
  134. data/vendors/Rakefile +35 -40
  135. metadata +47 -23
  136. data/library/simplex_noise/simplex_noise.rb +0 -3
  137. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  138. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  139. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  140. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -13,300 +13,318 @@ 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 a
17
- * sorted copy, use list.copy().sort().
16
+ * Functions like sort() and shuffle() always act on the list itself. To get
17
+ * a 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
-
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) {
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) {
57
60
  // // Not gonna go with null values staying that way because perhaps
58
61
  // // the most common case here is to immediately call join() or similar.
59
62
  // data[index++] = String.valueOf(o);
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
- }
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
+ }
66
223
  }
224
+ return -1;
225
+ }
67
226
 
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);
78
- }
79
- }
80
227
 
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);
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];
90
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
+ }
91
243
  }
244
+ int removed = count - ii;
245
+ count = ii;
246
+ return removed;
247
+ }
92
248
 
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;
108
249
 
109
- } else if (length > count) {
110
- Arrays.fill(data, count, length, 0);
111
- }
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);
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;
134
257
  }
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;
258
+ }
259
+ } else {
260
+ for (int i = 0; i < count; i++) {
261
+ if (value.equals(data[i])) {
262
+ data[i] = newValue;
263
+ return i;
153
264
  }
154
- data[index] = what;
265
+ }
155
266
  }
267
+ return -1;
268
+ }
156
269
 
157
- /**
158
- * Just an alias for append(), but matches pop()
159
- */
160
- public void push(String value) {
161
- append(value);
162
- }
163
270
 
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
- }
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++;
211
279
  }
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
- }
280
+ }
281
+ } else {
282
+ for (int i = 0; i < count; i++) {
283
+ if (value.equals(data[i])) {
284
+ data[i] = newValue;
285
+ changed++;
230
286
  }
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;
287
+ }
288
288
  }
289
+ return changed;
290
+ }
289
291
 
290
- public void append(String[] values) {
291
- for (String v : values) {
292
- append(v);
293
- }
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);
294
302
  }
303
+ data[count++] = value;
304
+ }
295
305
 
296
- public void append(StringList list) {
297
- for (String v : list.values()) { // will concat the list...
298
- append(v);
299
- }
306
+
307
+ public void append(String[] values) {
308
+ for (String v : values) {
309
+ append(v);
300
310
  }
311
+ }
301
312
 
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
- }
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);
309
325
  }
326
+ }
327
+
310
328
 
311
329
  // public void insert(int index, int value) {
312
330
  // if (index+1 > count) {
@@ -336,44 +354,50 @@ public class StringList implements Iterable<String> {
336
354
  // count++;
337
355
  // }
338
356
  // }
339
- public void insert(int index, String value) {
340
- insert(index, new String[]{value});
341
- }
342
357
 
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
358
 
352
- String[] temp = new String[count + values.length];
359
+ public void insert(int index, String value) {
360
+ insert(index, new String[] { value });
361
+ }
362
+
353
363
 
354
- // Copy the old values, but not more than already exist
355
- System.arraycopy(data, 0, temp, 0, Math.min(count, index));
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
+ }
356
372
 
357
- // Copy the new values into the proper place
358
- System.arraycopy(values, 0, temp, index, values.length);
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);
359
380
 
360
381
  // if (index < count) {
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;
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;
364
385
  // } else {
365
386
  // // The index was past 'count', so the new count is weirder
366
387
  // count = index + values.length;
367
388
  // }
368
- data = temp;
369
- }
389
+ data = temp;
390
+ }
391
+
392
+
393
+ public void insert(int index, StringList list) {
394
+ insert(index, list.values());
395
+ }
370
396
 
371
- public void insert(int index, StringList list) {
372
- insert(index, list.values());
373
- }
374
397
 
375
398
  // below are aborted attempts at more optimized versions of the code
376
399
  // that are harder to read and debug...
400
+
377
401
  // if (index + values.length >= count) {
378
402
  // // We're past the current 'count', check to see if we're still allocated
379
403
  // // index 9, data.length = 10, values.length = 1
@@ -412,100 +436,108 @@ public class StringList implements Iterable<String> {
412
436
  // data[index] = value;
413
437
  // count++;
414
438
  // }
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
- }
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;
431
453
  }
432
- return -1;
454
+ }
433
455
  }
456
+ return -1;
457
+ }
434
458
 
435
- // !!! TODO this is not yet correct, because it's not being reset when
436
- // the rest of the entries are changed
459
+
460
+ // !!! TODO this is not yet correct, because it's not being reset when
461
+ // the rest of the entries are changed
437
462
  // protected void cacheIndices() {
438
463
  // indexCache = new HashMap<Integer, Integer>();
439
464
  // for (int i = 0; i < count; i++) {
440
465
  // indexCache.put(data[i], i);
441
466
  // }
442
467
  // }
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()
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()
507
537
  // public void splice(int index, int value) {
508
538
  // }
539
+
540
+
509
541
  // public void subset(int start) {
510
542
  // subset(start, count - start);
511
543
  // }
@@ -517,238 +549,252 @@ public class StringList implements Iterable<String> {
517
549
  // }
518
550
  // count = num;
519
551
  // }
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
- }
532
- }
533
552
 
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
- }
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;
552
661
 
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
- }
662
+ public void remove() {
663
+ StringList.this.remove(index);
664
+ index--;
665
+ }
567
666
 
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
- }
580
- }
667
+ public String next() {
668
+ return data[++index];
669
+ }
581
670
 
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
- }
671
+ public boolean hasNext() {
672
+ return index+1 < count;
673
+ }
674
+ };
675
+ }
595
676
 
596
- public StringList copy() {
597
- StringList outgoing = new StringList(data);
598
- outgoing.count = count;
599
- return outgoing;
600
- }
601
677
 
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
- }
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
+ }
611
688
 
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;
660
- }
661
689
 
662
- public StringList getSubset(int start) {
663
- return getSubset(start, count - start);
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];
664
698
  }
699
+ System.arraycopy(data, 0, array, 0, count);
700
+ return array;
701
+ }
665
702
 
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
- }
671
703
 
672
- /**
673
- * Get a list of all unique entries.
674
- */
675
- public String[] getUnique() {
676
- return getTally().keyArray();
677
- }
704
+ public StringList getSubset(int start) {
705
+ return getSubset(start, count - start);
706
+ }
678
707
 
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
- }
689
708
 
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
- }
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
+ }
700
714
 
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();
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]);
712
727
  }
728
+ return outgoing;
729
+ }
713
730
 
714
- public void print() {
715
- for (int i = 0; i < count; i++) {
716
- System.out.format("[%d] %s%n", i, data[i]);
717
- }
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);
718
737
  }
738
+ return outgoing;
739
+ }
740
+
719
741
 
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();
742
+ public String join(String separator) {
743
+ if (count == 0) {
744
+ return "";
727
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
+ }
728
754
 
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();
755
+
756
+ public void print() {
757
+ for (int i = 0; i < count; i++) {
758
+ System.out.format("[%d] %s%n", i, data[i]);
737
759
  }
760
+ }
738
761
 
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(", ") + " ]";
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]);
748
779
  }
780
+ writer.flush();
781
+ }
749
782
 
750
- @Override
751
- public String toString() {
752
- return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
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));
753
791
  }
792
+ return "[ " + temp.join(", ") + " ]";
793
+ }
794
+
795
+
796
+ @Override
797
+ public String toString() {
798
+ return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
799
+ }
754
800
  }