propane 2.7.2-java → 2.8.0.pre-java

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