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