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,802 +0,0 @@
1
- package processing.data;
2
-
3
- import java.io.*;
4
- import java.util.HashMap;
5
- import java.util.Iterator;
6
- import java.util.NoSuchElementException;
7
-
8
- import processing.core.PApplet;
9
-
10
-
11
- /**
12
- * A simple class to use a String as a lookup for an int value.
13
- *
14
- * @nowebref
15
- * @see FloatDict
16
- * @see StringDict
17
- */
18
- public class LongDict {
19
-
20
- /** Number of elements in the table */
21
- protected int count;
22
-
23
- protected String[] keys;
24
- protected long[] values;
25
-
26
- /** Internal implementation for faster lookups */
27
- private HashMap<String, Integer> indices = new HashMap<>();
28
-
29
-
30
- public LongDict() {
31
- count = 0;
32
- keys = new String[10];
33
- values = new long[10];
34
- }
35
-
36
-
37
- /**
38
- * Create a new lookup with a specific size. This is more efficient than not
39
- * specifying a size. Use it when you know the rough size of the thing you're creating.
40
- *
41
- * @nowebref
42
- */
43
- public LongDict(int length) {
44
- count = 0;
45
- keys = new String[length];
46
- values = new long[length];
47
- }
48
-
49
-
50
- /**
51
- * Read a set of entries from a Reader that has each key/value pair on
52
- * a single line, separated by a tab.
53
- *
54
- * @nowebref
55
- */
56
- public LongDict(BufferedReader reader) {
57
- String[] lines = PApplet.loadStrings(reader);
58
- keys = new String[lines.length];
59
- values = new long[lines.length];
60
-
61
- for (int i = 0; i < lines.length; i++) {
62
- String[] pieces = PApplet.split(lines[i], '\t');
63
- if (pieces.length == 2) {
64
- keys[count] = pieces[0];
65
- values[count] = PApplet.parseInt(pieces[1]);
66
- indices.put(pieces[0], count);
67
- count++;
68
- }
69
- }
70
- }
71
-
72
- /**
73
- * @nowebref
74
- */
75
- public LongDict(String[] keys, long[] values) {
76
- if (keys.length != values.length) {
77
- throw new IllegalArgumentException("key and value arrays must be the same length");
78
- }
79
- this.keys = keys;
80
- this.values = values;
81
- count = keys.length;
82
- for (int i = 0; i < count; i++) {
83
- indices.put(keys[i], i);
84
- }
85
- }
86
-
87
-
88
- /**
89
- * Constructor to allow (more intuitive) inline initialization, e.g.:
90
- * <pre>
91
- * new FloatDict(new Object[][] {
92
- * { "key1", 1 },
93
- * { "key2", 2 }
94
- * });
95
- * </pre>
96
- */
97
- public LongDict(Object[][] pairs) {
98
- count = pairs.length;
99
- this.keys = new String[count];
100
- this.values = new long[count];
101
- for (int i = 0; i < count; i++) {
102
- keys[i] = (String) pairs[i][0];
103
- values[i] = (Integer) pairs[i][1];
104
- indices.put(keys[i], i);
105
- }
106
- }
107
-
108
-
109
- /**
110
- * Returns the number of key/value pairs
111
- *
112
- * @webref intdict:method
113
- * @brief Returns the number of key/value pairs
114
- */
115
- public int size() {
116
- return count;
117
- }
118
-
119
-
120
- /**
121
- * Resize the internal data, this can only be used to shrink the list.
122
- * Helpful for situations like sorting and then grabbing the top 50 entries.
123
- */
124
- public void resize(int length) {
125
- if (length > count) {
126
- throw new IllegalArgumentException("resize() can only be used to shrink the dictionary");
127
- }
128
- if (length < 1) {
129
- throw new IllegalArgumentException("resize(" + length + ") is too small, use 1 or higher");
130
- }
131
-
132
- String[] newKeys = new String[length];
133
- long[] newValues = new long[length];
134
- PApplet.arrayCopy(keys, newKeys, length);
135
- PApplet.arrayCopy(values, newValues, length);
136
- keys = newKeys;
137
- values = newValues;
138
- count = length;
139
- resetIndices();
140
- }
141
-
142
-
143
- /**
144
- * Remove all entries.
145
- *
146
- * @webref intdict:method
147
- * @brief Remove all entries
148
- */
149
- public void clear() {
150
- count = 0;
151
- indices = new HashMap<>();
152
- }
153
-
154
-
155
- private void resetIndices() {
156
- indices = new HashMap<>(count);
157
- for (int i = 0; i < count; i++) {
158
- indices.put(keys[i], i);
159
- }
160
- }
161
-
162
-
163
- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
164
-
165
-
166
- public class Entry {
167
- public String key;
168
- public long value;
169
-
170
- Entry(String key, long value) {
171
- this.key = key;
172
- this.value = value;
173
- }
174
- }
175
-
176
-
177
- public Iterable<Entry> entries() {
178
- return new Iterable<Entry>() {
179
-
180
- public Iterator<Entry> iterator() {
181
- return entryIterator();
182
- }
183
- };
184
- }
185
-
186
-
187
- public Iterator<Entry> entryIterator() {
188
- return new Iterator<Entry>() {
189
- int index = -1;
190
-
191
- public void remove() {
192
- removeIndex(index);
193
- index--;
194
- }
195
-
196
- public Entry next() {
197
- ++index;
198
- Entry e = new Entry(keys[index], values[index]);
199
- return e;
200
- }
201
-
202
- public boolean hasNext() {
203
- return index+1 < size();
204
- }
205
- };
206
- }
207
-
208
-
209
- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
210
-
211
-
212
- public String key(int index) {
213
- return keys[index];
214
- }
215
-
216
-
217
- protected void crop() {
218
- if (count != keys.length) {
219
- keys = PApplet.subset(keys, 0, count);
220
- values = PApplet.subset(values, 0, count);
221
- }
222
- }
223
-
224
-
225
- public Iterable<String> keys() {
226
- return new Iterable<String>() {
227
-
228
- @Override
229
- public Iterator<String> iterator() {
230
- return keyIterator();
231
- }
232
- };
233
- }
234
-
235
-
236
- // Use this to iterate when you want to be able to remove elements along the way
237
- public Iterator<String> keyIterator() {
238
- return new Iterator<String>() {
239
- int index = -1;
240
-
241
- public void remove() {
242
- removeIndex(index);
243
- index--;
244
- }
245
-
246
- public String next() {
247
- return key(++index);
248
- }
249
-
250
- public boolean hasNext() {
251
- return index+1 < size();
252
- }
253
- };
254
- }
255
-
256
-
257
- /**
258
- * Return a copy of the internal keys array. This array can be modified.
259
- *
260
- * @webref intdict:method
261
- * @brief Return a copy of the internal keys array
262
- */
263
- public String[] keyArray() {
264
- crop();
265
- return keyArray(null);
266
- }
267
-
268
-
269
- public String[] keyArray(String[] outgoing) {
270
- if (outgoing == null || outgoing.length != count) {
271
- outgoing = new String[count];
272
- }
273
- System.arraycopy(keys, 0, outgoing, 0, count);
274
- return outgoing;
275
- }
276
-
277
-
278
- public long value(int index) {
279
- return values[index];
280
- }
281
-
282
-
283
- /**
284
- * @webref intdict:method
285
- * @brief Return the internal array being used to store the values
286
- */
287
- public Iterable<Long> values() {
288
- return new Iterable<Long>() {
289
-
290
- @Override
291
- public Iterator<Long> iterator() {
292
- return valueIterator();
293
- }
294
- };
295
- }
296
-
297
-
298
- public Iterator<Long> valueIterator() {
299
- return new Iterator<Long>() {
300
- int index = -1;
301
-
302
- public void remove() {
303
- removeIndex(index);
304
- index--;
305
- }
306
-
307
- public Long next() {
308
- return value(++index);
309
- }
310
-
311
- public boolean hasNext() {
312
- return index+1 < size();
313
- }
314
- };
315
- }
316
-
317
-
318
- /**
319
- * Create a new array and copy each of the values into it.
320
- *
321
- * @webref intdict:method
322
- * @brief Create a new array and copy each of the values into it
323
- */
324
- public int[] valueArray() {
325
- crop();
326
- return valueArray(null);
327
- }
328
-
329
-
330
- /**
331
- * Fill an already-allocated array with the values (more efficient than
332
- * creating a new array each time). If 'array' is null, or not the same
333
- * size as the number of values, a new array will be allocated and returned.
334
- *
335
- * @param array values to copy into the array
336
- */
337
- public int[] valueArray(int[] array) {
338
- if (array == null || array.length != size()) {
339
- array = new int[count];
340
- }
341
- System.arraycopy(values, 0, array, 0, count);
342
- return array;
343
- }
344
-
345
-
346
- /**
347
- * Return a value for the specified key.
348
- *
349
- * @webref intdict:method
350
- * @brief Return a value for the specified key
351
- */
352
- public long get(String key) {
353
- int index = index(key);
354
- if (index == -1) {
355
- throw new IllegalArgumentException("No key named '" + key + "'");
356
- }
357
- return values[index];
358
- }
359
-
360
-
361
- public long get(String key, long alternate) {
362
- int index = index(key);
363
- if (index == -1) return alternate;
364
- return values[index];
365
- }
366
-
367
-
368
- /**
369
- * Create a new key/value pair or change the value of one.
370
- *
371
- * @webref intdict:method
372
- * @brief Create a new key/value pair or change the value of one
373
- */
374
- public void set(String key, long amount) {
375
- int index = index(key);
376
- if (index == -1) {
377
- create(key, amount);
378
- } else {
379
- values[index] = amount;
380
- }
381
- }
382
-
383
-
384
- public void setIndex(int index, String key, long value) {
385
- if (index < 0 || index >= count) {
386
- throw new ArrayIndexOutOfBoundsException(index);
387
- }
388
- keys[index] = key;
389
- values[index] = value;
390
- }
391
-
392
-
393
- /**
394
- * @webref intdict:method
395
- * @brief Check if a key is a part of the data structure
396
- */
397
- public boolean hasKey(String key) {
398
- return index(key) != -1;
399
- }
400
-
401
-
402
- /**
403
- * Increase the value associated with a specific key by 1.
404
- *
405
- * @webref intdict:method
406
- * @brief Increase the value of a specific key value by 1
407
- */
408
- public void increment(String key) {
409
- add(key, 1);
410
- }
411
-
412
-
413
- /**
414
- * Merge another dictionary into this one. Calling this increment()
415
- * since it doesn't make sense in practice for the other dictionary types,
416
- * even though it's technically an add().
417
- */
418
- public void increment(LongDict dict) {
419
- for (int i = 0; i < dict.count; i++) {
420
- add(dict.key(i), dict.value(i));
421
- }
422
- }
423
-
424
-
425
- /**
426
- * @webref intdict:method
427
- * @brief Add to a value
428
- */
429
- public void add(String key, long amount) {
430
- int index = index(key);
431
- if (index == -1) {
432
- create(key, amount);
433
- } else {
434
- values[index] += amount;
435
- }
436
- }
437
-
438
-
439
- /**
440
- * @webref intdict:method
441
- * @brief Subtract from a value
442
- */
443
- public void sub(String key, long amount) {
444
- add(key, -amount);
445
- }
446
-
447
-
448
- /**
449
- * @webref intdict:method
450
- * @brief Multiply a value
451
- */
452
- public void mult(String key, long amount) {
453
- int index = index(key);
454
- if (index != -1) {
455
- values[index] *= amount;
456
- }
457
- }
458
-
459
-
460
- /**
461
- * @webref intdict:method
462
- * @brief Divide a value
463
- */
464
- public void div(String key, long amount) {
465
- int index = index(key);
466
- if (index != -1) {
467
- values[index] /= amount;
468
- }
469
- }
470
-
471
-
472
- private void checkMinMax(String functionName) {
473
- if (count == 0) {
474
- String msg =
475
- String.format("Cannot use %s() on an empty %s.",
476
- functionName, getClass().getSimpleName());
477
- throw new RuntimeException(msg);
478
- }
479
- }
480
-
481
-
482
- // return the index of the minimum value
483
- public int minIndex() {
484
- //checkMinMax("minIndex");
485
- if (count == 0) return -1;
486
-
487
- int index = 0;
488
- long value = values[0];
489
- for (int i = 1; i < count; i++) {
490
- if (values[i] < value) {
491
- index = i;
492
- value = values[i];
493
- }
494
- }
495
- return index;
496
- }
497
-
498
-
499
- // return the key for the minimum value
500
- public String minKey() {
501
- checkMinMax("minKey");
502
- int index = minIndex();
503
- if (index == -1) {
504
- return null;
505
- }
506
- return keys[index];
507
- }
508
-
509
-
510
- // return the minimum value, or throw an error if there are no values
511
- public long minValue() {
512
- checkMinMax("minValue");
513
- return values[minIndex()];
514
- }
515
-
516
-
517
- // return the index of the max value
518
- public int maxIndex() {
519
- //checkMinMax("maxIndex");
520
- if (count == 0) {
521
- return -1;
522
- }
523
- int index = 0;
524
- long value = values[0];
525
- for (int i = 1; i < count; i++) {
526
- if (values[i] > value) {
527
- index = i;
528
- value = values[i];
529
- }
530
- }
531
- return index;
532
- }
533
-
534
-
535
- /** return the key corresponding to the maximum value or null if no entries */
536
- public String maxKey() {
537
- //checkMinMax("maxKey");
538
- int index = maxIndex();
539
- if (index == -1) {
540
- return null;
541
- }
542
- return keys[index];
543
- }
544
-
545
-
546
- // return the maximum value or throw an error if zero length
547
- public long maxValue() {
548
- checkMinMax("maxIndex");
549
- return values[maxIndex()];
550
- }
551
-
552
-
553
- public long sum() {
554
- long sum = 0;
555
- for (int i = 0; i < count; i++) {
556
- sum += values[i];
557
- }
558
- return sum;
559
- }
560
-
561
-
562
- public int index(String what) {
563
- Integer found = indices.get(what);
564
- return (found == null) ? -1 : found.intValue();
565
- }
566
-
567
-
568
- protected void create(String what, long much) {
569
- if (count == keys.length) {
570
- keys = PApplet.expand(keys);
571
- values = PApplet.expand(values);
572
- }
573
- indices.put(what, Integer.valueOf(count));
574
- keys[count] = what;
575
- values[count] = much;
576
- count++;
577
- }
578
-
579
-
580
- /**
581
- * @webref intdict:method
582
- * @brief Remove a key/value pair
583
- */
584
- public long remove(String key) {
585
- int index = index(key);
586
- if (index == -1) {
587
- throw new NoSuchElementException("'" + key + "' not found");
588
- }
589
- long value = values[index];
590
- removeIndex(index);
591
- return value;
592
- }
593
-
594
-
595
- public long removeIndex(int index) {
596
- if (index < 0 || index >= count) {
597
- throw new ArrayIndexOutOfBoundsException(index);
598
- }
599
- long value = values[index];
600
- indices.remove(keys[index]);
601
- for (int i = index; i < count-1; i++) {
602
- keys[i] = keys[i+1];
603
- values[i] = values[i+1];
604
- indices.put(keys[i], i);
605
- }
606
- count--;
607
- keys[count] = null;
608
- values[count] = 0;
609
- return value;
610
- }
611
-
612
-
613
- public void swap(int a, int b) {
614
- String tkey = keys[a];
615
- long tvalue = values[a];
616
- keys[a] = keys[b];
617
- values[a] = values[b];
618
- keys[b] = tkey;
619
- values[b] = tvalue;
620
-
621
- // indices.put(keys[a], Integer.valueOf(a));
622
- // indices.put(keys[b], Integer.valueOf(b));
623
- }
624
-
625
-
626
- /**
627
- * Sort the keys alphabetically (ignoring case). Uses the value as a
628
- * tie-breaker (only really possible with a key that has a case change).
629
- *
630
- * @webref intdict:method
631
- * @brief Sort the keys alphabetically
632
- */
633
- public void sortKeys() {
634
- sortImpl(true, false, true);
635
- }
636
-
637
- /**
638
- * Sort the keys alphabetically in reverse (ignoring case). Uses the value as a
639
- * tie-breaker (only really possible with a key that has a case change).
640
- *
641
- * @webref intdict:method
642
- * @brief Sort the keys alphabetically in reverse
643
- */
644
- public void sortKeysReverse() {
645
- sortImpl(true, true, true);
646
- }
647
-
648
-
649
- /**
650
- * Sort by values in ascending order. The smallest value will be at [0].
651
- *
652
- * @webref intdict:method
653
- * @brief Sort by values in ascending order
654
- */
655
- public void sortValues() {
656
- sortValues(true);
657
- }
658
-
659
-
660
- /**
661
- * Set true to ensure that the order returned is identical. Slightly
662
- * slower because the tie-breaker for identical values compares the keys.
663
- * @param stable
664
- */
665
- public void sortValues(boolean stable) {
666
- sortImpl(false, false, stable);
667
- }
668
-
669
-
670
- /**
671
- * Sort by values in descending order. The largest value will be at [0].
672
- *
673
- * @webref intdict:method
674
- * @brief Sort by values in descending order
675
- */
676
- public void sortValuesReverse() {
677
- sortValuesReverse(true);
678
- }
679
-
680
-
681
- public void sortValuesReverse(boolean stable) {
682
- sortImpl(false, true, stable);
683
- }
684
-
685
-
686
- protected void sortImpl(final boolean useKeys, final boolean reverse,
687
- final boolean stable) {
688
- Sort s = new Sort() {
689
- @Override
690
- public int size() {
691
- return count;
692
- }
693
-
694
- @Override
695
- public int compare(int a, int b) {
696
- long diff = 0;
697
- if (useKeys) {
698
- diff = keys[a].compareToIgnoreCase(keys[b]);
699
- if (diff == 0) {
700
- diff = values[a] - values[b];
701
- }
702
- } else { // sort values
703
- diff = values[a] - values[b];
704
- if (diff == 0 && stable) {
705
- diff = keys[a].compareToIgnoreCase(keys[b]);
706
- }
707
- }
708
- if (diff == 0) {
709
- return 0;
710
- } else if (reverse) {
711
- return diff < 0 ? 1 : -1;
712
- } else {
713
- return diff < 0 ? -1 : 1;
714
- }
715
- }
716
-
717
- @Override
718
- public void swap(int a, int b) {
719
- LongDict.this.swap(a, b);
720
- }
721
- };
722
- s.run();
723
-
724
- // Set the indices after sort/swaps (performance fix 160411)
725
- resetIndices();
726
- }
727
-
728
-
729
- /**
730
- * Sum all of the values in this dictionary, then return a new FloatDict of
731
- * each key, divided by the total sum. The total for all values will be ~1.0.
732
- * @return an IntDict with the original keys, mapped to their pct of the total
733
- */
734
- public FloatDict getPercent() {
735
- double sum = sum(); // a little more accuracy
736
- FloatDict outgoing = new FloatDict();
737
- for (int i = 0; i < size(); i++) {
738
- double percent = value(i) / sum;
739
- outgoing.set(key(i), (float) percent);
740
- }
741
- return outgoing;
742
- }
743
-
744
-
745
- /** Returns a duplicate copy of this object. */
746
- public LongDict copy() {
747
- LongDict outgoing = new LongDict(count);
748
- System.arraycopy(keys, 0, outgoing.keys, 0, count);
749
- System.arraycopy(values, 0, outgoing.values, 0, count);
750
- for (int i = 0; i < count; i++) {
751
- outgoing.indices.put(keys[i], i);
752
- }
753
- outgoing.count = count;
754
- return outgoing;
755
- }
756
-
757
-
758
- public void print() {
759
- for (int i = 0; i < size(); i++) {
760
- System.out.println(keys[i] + " = " + values[i]);
761
- }
762
- }
763
-
764
-
765
- /**
766
- * Save tab-delimited entries to a file (TSV format, UTF-8 encoding)
767
- */
768
- public void save(File file) {
769
- PrintWriter writer = PApplet.createWriter(file);
770
- write(writer);
771
- writer.close();
772
- }
773
-
774
-
775
- /**
776
- * Write tab-delimited entries to a PrintWriter
777
- */
778
- public void write(PrintWriter writer) {
779
- for (int i = 0; i < count; i++) {
780
- writer.println(keys[i] + "\t" + values[i]);
781
- }
782
- writer.flush();
783
- }
784
-
785
-
786
- /**
787
- * Return this dictionary as a String in JSON format.
788
- */
789
- public String toJSON() {
790
- StringList items = new StringList();
791
- for (int i = 0; i < count; i++) {
792
- items.append(JSONObject.quote(keys[i])+ ": " + values[i]);
793
- }
794
- return "{ " + items.join(", ") + " }";
795
- }
796
-
797
-
798
- @Override
799
- public String toString() {
800
- return getClass().getSimpleName() + " size=" + size() + " " + toJSON();
801
- }
802
- }