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