propane 3.4.2-java → 3.5.0-java

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