picrate 0.5.0-java → 0.6.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.mvn/wrapper/maven-wrapper.properties +1 -1
- data/CHANGELOG.md +3 -1
- data/README.md +1 -1
- data/Rakefile +8 -6
- data/docs/_editors/geany.md +5 -4
- data/docs/_editors/vim.md +6 -0
- data/docs/_includes/head.html +1 -0
- data/docs/_libraries/control_panel.md +2 -2
- data/docs/_libraries/gl_video.md +21 -0
- data/docs/_posts/2018-05-06-getting_started.md +10 -9
- data/docs/_posts/2018-05-06-install_jruby.md +19 -2
- data/docs/_posts/2018-06-26-auto_install_picrate.md +19 -4
- data/docs/_posts/2018-11-18-building-gem.md +18 -0
- data/docs/_posts/2018-11-27-getting_started_geany.md +38 -0
- data/docs/about.md +21 -10
- data/docs/assets/android-chrome-192x192.png +0 -0
- data/docs/assets/android-chrome-512x512.png +0 -0
- data/docs/assets/favicon.ico +0 -0
- data/docs/assets/geany.png +0 -0
- data/docs/assets/jwishy_picrate.png +0 -0
- data/docs/assets/picrate.svg +251 -0
- data/docs/index.html +8 -14
- data/lib/picrate/runner.rb +6 -2
- data/lib/picrate/version.rb +1 -1
- data/library/boids/boids.rb +10 -13
- data/mvnw +234 -0
- data/picrate.gemspec +2 -1
- data/pom.rb +1 -1
- data/pom.xml +1 -1
- data/src/main/java/japplemenubar/JAppleMenuBar.java +10 -2
- data/src/main/java/monkstone/ColorUtil.java +11 -1
- data/src/main/java/monkstone/MathToolModule.java +1 -0
- data/src/main/java/monkstone/PicrateLibrary.java +1 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +1 -0
- data/src/main/java/monkstone/noise/SimplexNoise.java +3 -3
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleSlider.java +8 -8
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/Slider.java +3 -3
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/vecmath/AppRender.java +1 -0
- data/src/main/java/monkstone/vecmath/JRender.java +1 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +1 -0
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +8 -0
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +85 -16
- data/src/main/java/processing/awt/PSurfaceAWT.java +1 -1
- data/src/main/java/processing/core/PApplet.java +18 -12
- data/src/main/java/processing/core/PShape.java +1182 -305
- data/src/main/java/processing/core/PStyle.java +1 -1
- data/src/main/java/processing/core/PSurface.java +1 -1
- data/src/main/java/processing/data/FloatDict.java +196 -54
- data/src/main/java/processing/data/FloatList.java +167 -54
- data/src/main/java/processing/data/IntDict.java +211 -56
- data/src/main/java/processing/data/IntList.java +185 -52
- data/src/main/java/processing/data/JSONArray.java +69 -20
- data/src/main/java/processing/data/JSONObject.java +53 -12
- data/src/main/java/processing/data/Sort.java +40 -10
- data/src/main/java/processing/data/StringDict.java +159 -49
- data/src/main/java/processing/data/StringList.java +147 -42
- data/src/main/java/processing/data/Table.java +778 -223
- data/src/main/java/processing/data/TableRow.java +26 -2
- data/src/main/java/processing/data/XML.java +190 -50
- data/src/main/java/processing/event/Event.java +93 -0
- data/src/main/java/processing/event/KeyEvent.java +55 -13
- data/src/main/java/processing/event/MouseEvent.java +77 -1
- data/src/main/java/processing/event/TouchEvent.java +14 -1
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +8 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +228 -66
- data/src/main/java/processing/opengl/LinePath.java +131 -27
- data/src/main/java/processing/opengl/LineStroker.java +30 -5
- data/src/main/java/processing/opengl/PGL.java +4066 -865
- data/src/main/java/processing/opengl/PGraphics2D.java +38 -10
- data/src/main/java/processing/opengl/PGraphics3D.java +38 -6
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +1980 -474
- data/src/main/java/processing/opengl/PJOGL.java +1460 -248
- data/src/main/java/processing/opengl/PShader.java +904 -217
- data/src/main/java/processing/opengl/PShapeOpenGL.java +1811 -487
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +278 -71
- data/src/main/java/processing/opengl/Texture.java +610 -135
- data/src/main/java/processing/opengl/VertexBuffer.java +45 -9
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/vendors/Rakefile +1 -1
- metadata +13 -6
- data/docs/assets/circle_collisions.png +0 -0
- data/docs/favicon.ico +0 -0
|
@@ -19,14 +19,23 @@ public class IntDict {
|
|
|
19
19
|
/** Number of elements in the table */
|
|
20
20
|
protected int count;
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
protected String[] keys;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
protected int[] values;
|
|
24
31
|
|
|
25
32
|
/** Internal implementation for faster lookups */
|
|
26
33
|
private HashMap<String, Integer> indices = new HashMap<>();
|
|
27
34
|
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
public IntDict() {
|
|
30
39
|
count = 0;
|
|
31
40
|
keys = new String[10];
|
|
32
41
|
values = new int[10];
|
|
@@ -34,9 +43,10 @@ public class IntDict {
|
|
|
34
43
|
|
|
35
44
|
|
|
36
45
|
/**
|
|
37
|
-
* Create a new lookup with a specific size.
|
|
38
|
-
|
|
46
|
+
* Create a new lookup with a specific size.This is more efficient than not
|
|
47
|
+
specifying a size. Use it when you know the rough size of the thing you're creating.
|
|
39
48
|
*
|
|
49
|
+
* @param length
|
|
40
50
|
* @nowebref
|
|
41
51
|
*/
|
|
42
52
|
public IntDict(int length) {
|
|
@@ -50,6 +60,7 @@ public class IntDict {
|
|
|
50
60
|
* Read a set of entries from a Reader that has each key/value pair on
|
|
51
61
|
* a single line, separated by a tab.
|
|
52
62
|
*
|
|
63
|
+
* @param reader
|
|
53
64
|
* @nowebref
|
|
54
65
|
*/
|
|
55
66
|
public IntDict(BufferedReader reader) {
|
|
@@ -69,6 +80,8 @@ public class IntDict {
|
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
/**
|
|
83
|
+
* @param keys
|
|
84
|
+
* @param values
|
|
72
85
|
* @nowebref
|
|
73
86
|
*/
|
|
74
87
|
public IntDict(String[] keys, int[] values) {
|
|
@@ -92,6 +105,7 @@ public class IntDict {
|
|
|
92
105
|
* { "key2", 2 }
|
|
93
106
|
* });
|
|
94
107
|
* </pre>
|
|
108
|
+
* @param pairs
|
|
95
109
|
*/
|
|
96
110
|
public IntDict(Object[][] pairs) {
|
|
97
111
|
count = pairs.length;
|
|
@@ -108,6 +122,7 @@ public class IntDict {
|
|
|
108
122
|
/**
|
|
109
123
|
* Returns the number of key/value pairs
|
|
110
124
|
*
|
|
125
|
+
* @return
|
|
111
126
|
* @webref intdict:method
|
|
112
127
|
* @brief Returns the number of key/value pairs
|
|
113
128
|
*/
|
|
@@ -117,8 +132,8 @@ public class IntDict {
|
|
|
117
132
|
|
|
118
133
|
|
|
119
134
|
/**
|
|
120
|
-
* Resize the internal data, this can only be used to shrink the list.
|
|
121
|
-
|
|
135
|
+
* Resize the internal data, this can only be used to shrink the list.Helpful for situations like sorting and then grabbing the top 50 entries.
|
|
136
|
+
* @param arg0
|
|
122
137
|
*/
|
|
123
138
|
public void resize(int length) {
|
|
124
139
|
if (length > count) {
|
|
@@ -161,10 +176,22 @@ public class IntDict {
|
|
|
161
176
|
|
|
162
177
|
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
|
163
178
|
|
|
179
|
+
/**
|
|
180
|
+
*
|
|
181
|
+
*/
|
|
182
|
+
|
|
164
183
|
|
|
165
184
|
public class Entry {
|
|
166
|
-
|
|
167
|
-
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
*
|
|
188
|
+
*/
|
|
189
|
+
public String key;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
*
|
|
193
|
+
*/
|
|
194
|
+
public int value;
|
|
168
195
|
|
|
169
196
|
Entry(String key, int value) {
|
|
170
197
|
this.key = key;
|
|
@@ -172,8 +199,11 @@ public class IntDict {
|
|
|
172
199
|
}
|
|
173
200
|
}
|
|
174
201
|
|
|
175
|
-
|
|
176
|
-
|
|
202
|
+
/**
|
|
203
|
+
*
|
|
204
|
+
* @return
|
|
205
|
+
*/
|
|
206
|
+
public Iterable<Entry> entries() {
|
|
177
207
|
return new Iterable<Entry>() {
|
|
178
208
|
|
|
179
209
|
public Iterator<Entry> iterator() {
|
|
@@ -182,8 +212,11 @@ public class IntDict {
|
|
|
182
212
|
};
|
|
183
213
|
}
|
|
184
214
|
|
|
185
|
-
|
|
186
|
-
|
|
215
|
+
/**
|
|
216
|
+
*
|
|
217
|
+
* @return
|
|
218
|
+
*/
|
|
219
|
+
public Iterator<Entry> entryIterator() {
|
|
187
220
|
return new Iterator<Entry>() {
|
|
188
221
|
int index = -1;
|
|
189
222
|
|
|
@@ -207,21 +240,32 @@ public class IntDict {
|
|
|
207
240
|
|
|
208
241
|
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
|
209
242
|
|
|
243
|
+
/**
|
|
244
|
+
*
|
|
245
|
+
* @param index
|
|
246
|
+
* @return
|
|
247
|
+
*/
|
|
248
|
+
|
|
210
249
|
|
|
211
250
|
public String key(int index) {
|
|
212
251
|
return keys[index];
|
|
213
252
|
}
|
|
214
253
|
|
|
215
|
-
|
|
216
|
-
|
|
254
|
+
/**
|
|
255
|
+
*
|
|
256
|
+
*/
|
|
257
|
+
protected void crop() {
|
|
217
258
|
if (count != keys.length) {
|
|
218
259
|
keys = PApplet.subset(keys, 0, count);
|
|
219
260
|
values = PApplet.subset(values, 0, count);
|
|
220
261
|
}
|
|
221
262
|
}
|
|
222
263
|
|
|
223
|
-
|
|
224
|
-
|
|
264
|
+
/**
|
|
265
|
+
*
|
|
266
|
+
* @return
|
|
267
|
+
*/
|
|
268
|
+
public Iterable<String> keys() {
|
|
225
269
|
return new Iterable<String>() {
|
|
226
270
|
|
|
227
271
|
@Override
|
|
@@ -233,6 +277,11 @@ public class IntDict {
|
|
|
233
277
|
|
|
234
278
|
|
|
235
279
|
// Use this to iterate when you want to be able to remove elements along the way
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
*
|
|
283
|
+
* @return
|
|
284
|
+
*/
|
|
236
285
|
public Iterator<String> keyIterator() {
|
|
237
286
|
return new Iterator<String>() {
|
|
238
287
|
int index = -1;
|
|
@@ -254,8 +303,9 @@ public class IntDict {
|
|
|
254
303
|
|
|
255
304
|
|
|
256
305
|
/**
|
|
257
|
-
* Return a copy of the internal keys array.
|
|
306
|
+
* Return a copy of the internal keys array.This array can be modified.
|
|
258
307
|
*
|
|
308
|
+
* @return
|
|
259
309
|
* @webref intdict:method
|
|
260
310
|
* @brief Return a copy of the internal keys array
|
|
261
311
|
*/
|
|
@@ -264,8 +314,12 @@ public class IntDict {
|
|
|
264
314
|
return keyArray(null);
|
|
265
315
|
}
|
|
266
316
|
|
|
267
|
-
|
|
268
|
-
|
|
317
|
+
/**
|
|
318
|
+
*
|
|
319
|
+
* @param outgoing
|
|
320
|
+
* @return
|
|
321
|
+
*/
|
|
322
|
+
public String[] keyArray(String[] outgoing) {
|
|
269
323
|
if (outgoing == null || outgoing.length != count) {
|
|
270
324
|
outgoing = new String[count];
|
|
271
325
|
}
|
|
@@ -273,13 +327,18 @@ public class IntDict {
|
|
|
273
327
|
return outgoing;
|
|
274
328
|
}
|
|
275
329
|
|
|
276
|
-
|
|
277
|
-
|
|
330
|
+
/**
|
|
331
|
+
*
|
|
332
|
+
* @param index
|
|
333
|
+
* @return
|
|
334
|
+
*/
|
|
335
|
+
public int value(int index) {
|
|
278
336
|
return values[index];
|
|
279
337
|
}
|
|
280
338
|
|
|
281
339
|
|
|
282
340
|
/**
|
|
341
|
+
* @return
|
|
283
342
|
* @webref intdict:method
|
|
284
343
|
* @brief Return the internal array being used to store the values
|
|
285
344
|
*/
|
|
@@ -293,8 +352,11 @@ public class IntDict {
|
|
|
293
352
|
};
|
|
294
353
|
}
|
|
295
354
|
|
|
296
|
-
|
|
297
|
-
|
|
355
|
+
/**
|
|
356
|
+
*
|
|
357
|
+
* @return
|
|
358
|
+
*/
|
|
359
|
+
public Iterator<Integer> valueIterator() {
|
|
298
360
|
return new Iterator<Integer>() {
|
|
299
361
|
int index = -1;
|
|
300
362
|
|
|
@@ -317,6 +379,7 @@ public class IntDict {
|
|
|
317
379
|
/**
|
|
318
380
|
* Create a new array and copy each of the values into it.
|
|
319
381
|
*
|
|
382
|
+
* @return
|
|
320
383
|
* @webref intdict:method
|
|
321
384
|
* @brief Create a new array and copy each of the values into it
|
|
322
385
|
*/
|
|
@@ -328,10 +391,11 @@ public class IntDict {
|
|
|
328
391
|
|
|
329
392
|
/**
|
|
330
393
|
* Fill an already-allocated array with the values (more efficient than
|
|
331
|
-
* creating a new array each time).
|
|
332
|
-
|
|
394
|
+
* creating a new array each time).If 'array' is null, or not the same
|
|
395
|
+
size as the number of values, a new array will be allocated and returned.
|
|
333
396
|
*
|
|
334
397
|
* @param array values to copy into the array
|
|
398
|
+
* @return
|
|
335
399
|
*/
|
|
336
400
|
public int[] valueArray(int[] array) {
|
|
337
401
|
if (array == null || array.length != size()) {
|
|
@@ -345,6 +409,8 @@ public class IntDict {
|
|
|
345
409
|
/**
|
|
346
410
|
* Return a value for the specified key.
|
|
347
411
|
*
|
|
412
|
+
* @param key
|
|
413
|
+
* @return
|
|
348
414
|
* @webref intdict:method
|
|
349
415
|
* @brief Return a value for the specified key
|
|
350
416
|
*/
|
|
@@ -356,8 +422,13 @@ public class IntDict {
|
|
|
356
422
|
return values[index];
|
|
357
423
|
}
|
|
358
424
|
|
|
359
|
-
|
|
360
|
-
|
|
425
|
+
/**
|
|
426
|
+
*
|
|
427
|
+
* @param key
|
|
428
|
+
* @param alternate
|
|
429
|
+
* @return
|
|
430
|
+
*/
|
|
431
|
+
public int get(String key, int alternate) {
|
|
361
432
|
int index = index(key);
|
|
362
433
|
if (index == -1) return alternate;
|
|
363
434
|
return values[index];
|
|
@@ -367,6 +438,8 @@ public class IntDict {
|
|
|
367
438
|
/**
|
|
368
439
|
* Create a new key/value pair or change the value of one.
|
|
369
440
|
*
|
|
441
|
+
* @param key
|
|
442
|
+
* @param amount
|
|
370
443
|
* @webref intdict:method
|
|
371
444
|
* @brief Create a new key/value pair or change the value of one
|
|
372
445
|
*/
|
|
@@ -379,8 +452,13 @@ public class IntDict {
|
|
|
379
452
|
}
|
|
380
453
|
}
|
|
381
454
|
|
|
382
|
-
|
|
383
|
-
|
|
455
|
+
/**
|
|
456
|
+
*
|
|
457
|
+
* @param index
|
|
458
|
+
* @param key
|
|
459
|
+
* @param value
|
|
460
|
+
*/
|
|
461
|
+
public void setIndex(int index, String key, int value) {
|
|
384
462
|
if (index < 0 || index >= count) {
|
|
385
463
|
throw new ArrayIndexOutOfBoundsException(index);
|
|
386
464
|
}
|
|
@@ -390,6 +468,8 @@ public class IntDict {
|
|
|
390
468
|
|
|
391
469
|
|
|
392
470
|
/**
|
|
471
|
+
* @param key
|
|
472
|
+
* @return
|
|
393
473
|
* @webref intdict:method
|
|
394
474
|
* @brief Check if a key is a part of the data structure
|
|
395
475
|
*/
|
|
@@ -401,6 +481,7 @@ public class IntDict {
|
|
|
401
481
|
/**
|
|
402
482
|
* Increase the value associated with a specific key by 1.
|
|
403
483
|
*
|
|
484
|
+
* @param key
|
|
404
485
|
* @webref intdict:method
|
|
405
486
|
* @brief Increase the value of a specific key value by 1
|
|
406
487
|
*/
|
|
@@ -410,9 +491,10 @@ public class IntDict {
|
|
|
410
491
|
|
|
411
492
|
|
|
412
493
|
/**
|
|
413
|
-
* Merge another dictionary into this one.
|
|
414
|
-
|
|
415
|
-
|
|
494
|
+
* Merge another dictionary into this one.Calling this increment()
|
|
495
|
+
since it doesn't make sense in practice for the other dictionary types,
|
|
496
|
+
even though it's technically an add().
|
|
497
|
+
* @param arg0
|
|
416
498
|
*/
|
|
417
499
|
public void increment(IntDict dict) {
|
|
418
500
|
for (int i = 0; i < dict.count; i++) {
|
|
@@ -422,6 +504,8 @@ public class IntDict {
|
|
|
422
504
|
|
|
423
505
|
|
|
424
506
|
/**
|
|
507
|
+
* @param key
|
|
508
|
+
* @param amount
|
|
425
509
|
* @webref intdict:method
|
|
426
510
|
* @brief Add to a value
|
|
427
511
|
*/
|
|
@@ -436,6 +520,8 @@ public class IntDict {
|
|
|
436
520
|
|
|
437
521
|
|
|
438
522
|
/**
|
|
523
|
+
* @param key
|
|
524
|
+
* @param amount
|
|
439
525
|
* @webref intdict:method
|
|
440
526
|
* @brief Subtract from a value
|
|
441
527
|
*/
|
|
@@ -445,6 +531,8 @@ public class IntDict {
|
|
|
445
531
|
|
|
446
532
|
|
|
447
533
|
/**
|
|
534
|
+
* @param key
|
|
535
|
+
* @param amount
|
|
448
536
|
* @webref intdict:method
|
|
449
537
|
* @brief Multiply a value
|
|
450
538
|
*/
|
|
@@ -457,6 +545,8 @@ public class IntDict {
|
|
|
457
545
|
|
|
458
546
|
|
|
459
547
|
/**
|
|
548
|
+
* @param key
|
|
549
|
+
* @param amount
|
|
460
550
|
* @webref intdict:method
|
|
461
551
|
* @brief Divide a value
|
|
462
552
|
*/
|
|
@@ -479,6 +569,11 @@ public class IntDict {
|
|
|
479
569
|
|
|
480
570
|
|
|
481
571
|
// return the index of the minimum value
|
|
572
|
+
|
|
573
|
+
/**
|
|
574
|
+
*
|
|
575
|
+
* @return
|
|
576
|
+
*/
|
|
482
577
|
public int minIndex() {
|
|
483
578
|
//checkMinMax("minIndex");
|
|
484
579
|
if (count == 0) return -1;
|
|
@@ -496,6 +591,11 @@ public class IntDict {
|
|
|
496
591
|
|
|
497
592
|
|
|
498
593
|
// return the key for the minimum value
|
|
594
|
+
|
|
595
|
+
/**
|
|
596
|
+
*
|
|
597
|
+
* @return
|
|
598
|
+
*/
|
|
499
599
|
public String minKey() {
|
|
500
600
|
checkMinMax("minKey");
|
|
501
601
|
int index = minIndex();
|
|
@@ -507,6 +607,11 @@ public class IntDict {
|
|
|
507
607
|
|
|
508
608
|
|
|
509
609
|
// return the minimum value, or throw an error if there are no values
|
|
610
|
+
|
|
611
|
+
/**
|
|
612
|
+
*
|
|
613
|
+
* @return
|
|
614
|
+
*/
|
|
510
615
|
public int minValue() {
|
|
511
616
|
checkMinMax("minValue");
|
|
512
617
|
return values[minIndex()];
|
|
@@ -514,6 +619,11 @@ public class IntDict {
|
|
|
514
619
|
|
|
515
620
|
|
|
516
621
|
// return the index of the max value
|
|
622
|
+
|
|
623
|
+
/**
|
|
624
|
+
*
|
|
625
|
+
* @return
|
|
626
|
+
*/
|
|
517
627
|
public int maxIndex() {
|
|
518
628
|
//checkMinMax("maxIndex");
|
|
519
629
|
if (count == 0) {
|
|
@@ -531,7 +641,8 @@ public class IntDict {
|
|
|
531
641
|
}
|
|
532
642
|
|
|
533
643
|
|
|
534
|
-
/** return the key corresponding to the maximum value or null if no entries
|
|
644
|
+
/** return the key corresponding to the maximum value or null if no entries
|
|
645
|
+
* @return */
|
|
535
646
|
public String maxKey() {
|
|
536
647
|
//checkMinMax("maxKey");
|
|
537
648
|
int index = maxIndex();
|
|
@@ -543,13 +654,21 @@ public class IntDict {
|
|
|
543
654
|
|
|
544
655
|
|
|
545
656
|
// return the maximum value or throw an error if zero length
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
*
|
|
660
|
+
* @return
|
|
661
|
+
*/
|
|
546
662
|
public int maxValue() {
|
|
547
663
|
checkMinMax("maxIndex");
|
|
548
664
|
return values[maxIndex()];
|
|
549
665
|
}
|
|
550
666
|
|
|
551
|
-
|
|
552
|
-
|
|
667
|
+
/**
|
|
668
|
+
*
|
|
669
|
+
* @return
|
|
670
|
+
*/
|
|
671
|
+
public int sum() {
|
|
553
672
|
long amount = sumLong();
|
|
554
673
|
if (amount > Integer.MAX_VALUE) {
|
|
555
674
|
throw new RuntimeException("sum() exceeds " + Integer.MAX_VALUE + ", use sumLong()");
|
|
@@ -560,8 +679,11 @@ public class IntDict {
|
|
|
560
679
|
return (int) amount;
|
|
561
680
|
}
|
|
562
681
|
|
|
563
|
-
|
|
564
|
-
|
|
682
|
+
/**
|
|
683
|
+
*
|
|
684
|
+
* @return
|
|
685
|
+
*/
|
|
686
|
+
public long sumLong() {
|
|
565
687
|
long sum = 0;
|
|
566
688
|
for (int i = 0; i < count; i++) {
|
|
567
689
|
sum += values[i];
|
|
@@ -569,14 +691,22 @@ public class IntDict {
|
|
|
569
691
|
return sum;
|
|
570
692
|
}
|
|
571
693
|
|
|
572
|
-
|
|
573
|
-
|
|
694
|
+
/**
|
|
695
|
+
*
|
|
696
|
+
* @param what
|
|
697
|
+
* @return
|
|
698
|
+
*/
|
|
699
|
+
public int index(String what) {
|
|
574
700
|
Integer found = indices.get(what);
|
|
575
701
|
return (found == null) ? -1 : found.intValue();
|
|
576
702
|
}
|
|
577
703
|
|
|
578
|
-
|
|
579
|
-
|
|
704
|
+
/**
|
|
705
|
+
*
|
|
706
|
+
* @param what
|
|
707
|
+
* @param much
|
|
708
|
+
*/
|
|
709
|
+
protected void create(String what, int much) {
|
|
580
710
|
if (count == keys.length) {
|
|
581
711
|
keys = PApplet.expand(keys);
|
|
582
712
|
values = PApplet.expand(values);
|
|
@@ -588,6 +718,8 @@ public class IntDict {
|
|
|
588
718
|
}
|
|
589
719
|
|
|
590
720
|
/**
|
|
721
|
+
* @param key
|
|
722
|
+
* @return
|
|
591
723
|
* @webref intdict:method
|
|
592
724
|
* @brief Remove a key/value pair
|
|
593
725
|
*/
|
|
@@ -599,8 +731,12 @@ public class IntDict {
|
|
|
599
731
|
return index;
|
|
600
732
|
}
|
|
601
733
|
|
|
602
|
-
|
|
603
|
-
|
|
734
|
+
/**
|
|
735
|
+
*
|
|
736
|
+
* @param index
|
|
737
|
+
* @return
|
|
738
|
+
*/
|
|
739
|
+
public String removeIndex(int index) {
|
|
604
740
|
if (index < 0 || index >= count) {
|
|
605
741
|
throw new ArrayIndexOutOfBoundsException(index);
|
|
606
742
|
}
|
|
@@ -618,8 +754,12 @@ public class IntDict {
|
|
|
618
754
|
return key;
|
|
619
755
|
}
|
|
620
756
|
|
|
621
|
-
|
|
622
|
-
|
|
757
|
+
/**
|
|
758
|
+
*
|
|
759
|
+
* @param a
|
|
760
|
+
* @param b
|
|
761
|
+
*/
|
|
762
|
+
public void swap(int a, int b) {
|
|
623
763
|
String tkey = keys[a];
|
|
624
764
|
int tvalue = values[a];
|
|
625
765
|
keys[a] = keys[b];
|
|
@@ -686,13 +826,21 @@ public class IntDict {
|
|
|
686
826
|
sortValuesReverse(true);
|
|
687
827
|
}
|
|
688
828
|
|
|
689
|
-
|
|
690
|
-
|
|
829
|
+
/**
|
|
830
|
+
*
|
|
831
|
+
* @param stable
|
|
832
|
+
*/
|
|
833
|
+
public void sortValuesReverse(boolean stable) {
|
|
691
834
|
sortImpl(false, true, stable);
|
|
692
835
|
}
|
|
693
836
|
|
|
694
|
-
|
|
695
|
-
|
|
837
|
+
/**
|
|
838
|
+
*
|
|
839
|
+
* @param useKeys
|
|
840
|
+
* @param reverse
|
|
841
|
+
* @param stable
|
|
842
|
+
*/
|
|
843
|
+
protected void sortImpl(final boolean useKeys, final boolean reverse,
|
|
696
844
|
final boolean stable) {
|
|
697
845
|
Sort s = new Sort() {
|
|
698
846
|
@Override
|
|
@@ -745,7 +893,8 @@ public class IntDict {
|
|
|
745
893
|
}
|
|
746
894
|
|
|
747
895
|
|
|
748
|
-
/** Returns a duplicate copy of this object.
|
|
896
|
+
/** Returns a duplicate copy of this object.
|
|
897
|
+
* @return */
|
|
749
898
|
public IntDict copy() {
|
|
750
899
|
IntDict outgoing = new IntDict(count);
|
|
751
900
|
System.arraycopy(keys, 0, outgoing.keys, 0, count);
|
|
@@ -757,8 +906,10 @@ public class IntDict {
|
|
|
757
906
|
return outgoing;
|
|
758
907
|
}
|
|
759
908
|
|
|
760
|
-
|
|
761
|
-
|
|
909
|
+
/**
|
|
910
|
+
*
|
|
911
|
+
*/
|
|
912
|
+
public void print() {
|
|
762
913
|
for (int i = 0; i < size(); i++) {
|
|
763
914
|
System.out.println(keys[i] + " = " + values[i]);
|
|
764
915
|
}
|
|
@@ -779,6 +930,7 @@ public class IntDict {
|
|
|
779
930
|
|
|
780
931
|
/**
|
|
781
932
|
* Return this dictionary as a String in JSON format.
|
|
933
|
+
* @return
|
|
782
934
|
*/
|
|
783
935
|
public String toJSON() {
|
|
784
936
|
StringList items = new StringList();
|
|
@@ -788,8 +940,11 @@ public class IntDict {
|
|
|
788
940
|
return "{ " + items.join(", ") + " }";
|
|
789
941
|
}
|
|
790
942
|
|
|
791
|
-
|
|
792
|
-
|
|
943
|
+
/**
|
|
944
|
+
*
|
|
945
|
+
* @return
|
|
946
|
+
*/
|
|
947
|
+
@Override
|
|
793
948
|
public String toString() {
|
|
794
949
|
return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
|
|
795
950
|
}
|