propane 3.4.0-java → 3.7.0.pre-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.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -2
- data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
- data/.mvn/wrapper/maven-wrapper.properties +2 -2
- data/.travis.yml +2 -2
- data/CHANGELOG.md +12 -0
- data/Gemfile +2 -0
- data/README.md +17 -8
- data/Rakefile +10 -11
- data/bin/propane +3 -1
- data/lib/propane.rb +6 -4
- data/lib/propane/app.rb +20 -10
- data/lib/propane/creators/sketch_class.rb +7 -1
- data/lib/propane/creators/sketch_factory.rb +4 -2
- data/lib/propane/creators/sketch_writer.rb +1 -0
- data/lib/propane/helper_methods.rb +23 -24
- data/lib/propane/helpers/numeric.rb +2 -0
- data/lib/propane/helpers/version_error.rb +1 -0
- data/lib/propane/library.rb +5 -1
- data/lib/propane/library_loader.rb +2 -0
- data/lib/propane/native_folder.rb +10 -9
- data/lib/propane/native_loader.rb +3 -0
- data/lib/propane/runner.rb +14 -6
- data/lib/propane/version.rb +2 -1
- data/library/boids/boids.rb +21 -11
- data/library/color_group/color_group.rb +28 -0
- data/library/control_panel/control_panel.rb +8 -5
- data/library/dxf/dxf.rb +6 -0
- data/library/file_chooser/chooser.rb +10 -9
- data/library/file_chooser/file_chooser.rb +10 -9
- data/library/library_proxy/library_proxy.rb +2 -0
- data/library/net/net.rb +7 -0
- data/library/simplex_noise/simplex_noise.rb +2 -0
- data/library/slider/slider.rb +23 -22
- data/library/vector_utils/vector_utils.rb +4 -0
- data/library/video_event/video_event.rb +4 -1
- data/pom.rb +37 -36
- data/pom.xml +7 -7
- data/propane.gemspec +16 -12
- data/src/main/java/monkstone/ColorUtil.java +13 -1
- data/src/main/java/monkstone/MathToolModule.java +253 -203
- data/src/main/java/monkstone/PropaneLibrary.java +2 -2
- data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
- data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -3
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
- data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
- data/src/main/java/processing/awt/PImageAWT.java +377 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
- data/src/main/java/processing/awt/PSurfaceAWT.java +309 -209
- data/src/main/java/processing/awt/ShimAWT.java +581 -0
- data/src/main/java/processing/core/PApplet.java +4510 -4503
- data/src/main/java/processing/core/PConstants.java +477 -447
- data/src/main/java/processing/core/PFont.java +914 -880
- data/src/main/java/processing/core/PGraphics.java +193 -177
- data/src/main/java/processing/core/PImage.java +611 -309
- data/src/main/java/processing/core/PMatrix.java +172 -159
- data/src/main/java/processing/core/PMatrix2D.java +478 -415
- data/src/main/java/processing/core/PMatrix3D.java +762 -735
- data/src/main/java/processing/core/PShape.java +2888 -2652
- data/src/main/java/processing/core/PShapeOBJ.java +97 -92
- data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
- data/src/main/java/processing/core/PStyle.java +40 -37
- data/src/main/java/processing/core/PSurface.java +139 -97
- data/src/main/java/processing/core/PSurfaceNone.java +296 -218
- data/src/main/java/processing/core/PVector.java +997 -965
- data/src/main/java/processing/core/ThinkDifferent.java +15 -13
- data/src/main/java/processing/data/DoubleDict.java +756 -710
- data/src/main/java/processing/data/DoubleList.java +749 -696
- data/src/main/java/processing/data/FloatDict.java +748 -702
- data/src/main/java/processing/data/FloatList.java +751 -697
- data/src/main/java/processing/data/IntDict.java +720 -673
- data/src/main/java/processing/data/IntList.java +699 -633
- data/src/main/java/processing/data/JSONArray.java +931 -873
- data/src/main/java/processing/data/JSONObject.java +1262 -1165
- data/src/main/java/processing/data/JSONTokener.java +351 -341
- data/src/main/java/processing/data/LongDict.java +710 -663
- data/src/main/java/processing/data/LongList.java +701 -635
- data/src/main/java/processing/data/Sort.java +37 -41
- data/src/main/java/processing/data/StringDict.java +525 -486
- data/src/main/java/processing/data/StringList.java +626 -580
- data/src/main/java/processing/data/Table.java +3690 -3510
- data/src/main/java/processing/data/TableRow.java +182 -183
- data/src/main/java/processing/data/XML.java +957 -883
- data/src/main/java/processing/dxf/RawDXF.java +404 -0
- data/src/main/java/processing/event/Event.java +87 -67
- data/src/main/java/processing/event/KeyEvent.java +48 -41
- data/src/main/java/processing/event/MouseEvent.java +88 -113
- data/src/main/java/processing/event/TouchEvent.java +10 -6
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
- data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
- data/src/main/java/processing/net/Client.java +744 -0
- data/src/main/java/processing/net/Server.java +388 -0
- data/src/main/java/processing/opengl/FontTexture.java +289 -270
- data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
- data/src/main/java/processing/opengl/LinePath.java +547 -500
- data/src/main/java/processing/opengl/LineStroker.java +588 -581
- data/src/main/java/processing/opengl/PGL.java +3047 -2914
- data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
- data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
- data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
- data/src/main/java/processing/opengl/PShader.java +1266 -1257
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
- data/src/main/java/processing/opengl/Texture.java +1492 -1401
- data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
- data/test/create_test.rb +21 -20
- data/test/deglut_spec_test.rb +4 -2
- data/test/helper_methods_test.rb +49 -20
- data/test/math_tool_test.rb +39 -32
- data/test/native_folder.rb +47 -0
- data/test/respond_to_test.rb +3 -2
- data/test/sketches/key_event.rb +2 -2
- data/test/sketches/library/my_library/my_library.rb +3 -0
- data/test/test_helper.rb +2 -0
- data/test/vecmath_spec_test.rb +35 -22
- data/vendors/Rakefile +33 -62
- metadata +56 -48
- data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
- data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
- data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
- data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
- data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
- data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
- data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
- data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
- data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
- data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
- data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
- data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
- data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
- data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
- data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
- data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
- data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
- data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
- data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
- data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
- data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
- 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
|
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
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
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
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
136
|
-
}
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
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
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
data[
|
170
|
-
|
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
|
-
|
213
|
-
}
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
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
|
-
|
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
|
-
|
291
|
-
|
292
|
-
|
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
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
306
|
+
|
307
|
+
public void append(String[] values) {
|
308
|
+
for (String v : values) {
|
309
|
+
append(v);
|
300
310
|
}
|
311
|
+
}
|
301
312
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
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
|
-
|
359
|
+
public void insert(int index, String value) {
|
360
|
+
insert(index, new String[] { value });
|
361
|
+
}
|
362
|
+
|
353
363
|
|
354
|
-
|
355
|
-
|
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
|
-
|
358
|
-
|
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
|
-
|
362
|
-
|
363
|
-
|
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
|
-
|
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
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
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
|
-
|
454
|
+
}
|
433
455
|
}
|
456
|
+
return -1;
|
457
|
+
}
|
434
458
|
|
435
|
-
|
436
|
-
|
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
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
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
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
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
|
-
|
555
|
-
|
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
|
-
|
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
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
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
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
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
|
-
|
663
|
-
|
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
|
-
|
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
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
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
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
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
|
-
|
715
|
-
|
716
|
-
|
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
|
-
|
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
|
-
|
731
|
-
|
732
|
-
|
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
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
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
|
-
|
751
|
-
|
752
|
-
|
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
|
}
|