26
26
27
27
import org .graalvm .visualvm .heapviewer .HeapContext ;
28
28
import java .util .Collection ;
29
- import java .util .Collections ;
30
29
import java .util .Iterator ;
31
30
import org .graalvm .visualvm .lib .jfluid .heap .Heap ;
32
31
import org .graalvm .visualvm .lib .jfluid .heap .Instance ;
@@ -174,18 +173,16 @@ protected void addingObject(long size, long retained, String type) {
174
173
types = computer .getTypes ();
175
174
}
176
175
177
-
178
-
179
176
180
177
protected final Iterator <Instance > instancesIterator (String javaClassFqn ) {
181
- return new InstancesIterator (HeapUtils .getSubclasses (heap , javaClassFqn ));
178
+ return HeapUtils . instancesIterator (HeapUtils .getSubclasses (heap , javaClassFqn ));
182
179
}
183
180
184
181
protected final Iterator <Instance > instancesIterator (String [] javaClassFqns ) {
185
182
List classes = new ArrayList ();
186
183
for (String fqn : javaClassFqns )
187
184
classes .addAll (HeapUtils .getSubclasses (heap , fqn ));
188
- return new InstancesIterator (classes );
185
+ return HeapUtils . instancesIterator (classes );
189
186
}
190
187
191
188
@@ -194,65 +191,6 @@ protected static String fragmentDescription(Instance langID, Heap heap) {
194
191
}
195
192
196
193
197
- protected static class InstancesIterator implements Iterator <Instance > {
198
- private final Iterator <JavaClass > classIt ;
199
- private Iterator <Instance > instanceIt ;
200
-
201
- public InstancesIterator (Collection <JavaClass > cls ) {
202
- classIt = cls .iterator ();
203
- instanceIt = Collections .EMPTY_LIST .iterator ();
204
- }
205
-
206
- @ Override
207
- public boolean hasNext () {
208
- if (instanceIt .hasNext ()) {
209
- return true ;
210
- }
211
- if (!classIt .hasNext ()) {
212
- return false ;
213
- }
214
- instanceIt = classIt .next ().getInstancesIterator ();
215
- return hasNext ();
216
- }
217
-
218
- @ Override
219
- public Instance next () {
220
- return instanceIt .next ();
221
- }
222
- }
223
-
224
- protected static abstract class ExcludingInstancesIterator implements Iterator <Instance > {
225
- private final Iterator <Instance > instancesIt ;
226
- private Instance next ;
227
-
228
- protected ExcludingInstancesIterator (Iterator <Instance > it ) {
229
- instancesIt = it ;
230
- computeNext ();
231
- }
232
-
233
- @ Override
234
- public boolean hasNext () {
235
- return next != null ;
236
- }
237
-
238
- @ Override
239
- public Instance next () {
240
- Instance ret = next ;
241
- computeNext ();
242
- return ret ;
243
- }
244
-
245
- private void computeNext () {
246
- while (instancesIt .hasNext ()) {
247
- next = instancesIt .next ();
248
- if (!exclude (next )) return ;
249
- }
250
- next = null ;
251
- }
252
-
253
- protected abstract boolean exclude (Instance instance );
254
- }
255
-
256
194
protected class ObjectsIterator implements Iterator <O > {
257
195
private final Iterator <Instance > instancesIter ;
258
196
@@ -261,7 +199,7 @@ public ObjectsIterator(Iterator<Instance> iter) {
261
199
}
262
200
263
201
public ObjectsIterator (Collection <JavaClass > cls ) {
264
- instancesIter = new InstancesIterator (cls );
202
+ instancesIter = HeapUtils . instancesIterator (cls );
265
203
}
266
204
267
205
@ Override
@@ -275,36 +213,4 @@ public O next() {
275
213
}
276
214
}
277
215
278
- protected abstract class ExcludingObjectsIterator implements Iterator <O > {
279
- private final Iterator <O > objectsIt ;
280
- private O next ;
281
-
282
- protected ExcludingObjectsIterator (Iterator <O > it ) {
283
- objectsIt = it ;
284
- computeNext ();
285
- }
286
-
287
- @ Override
288
- public boolean hasNext () {
289
- return next != null ;
290
- }
291
-
292
- @ Override
293
- public O next () {
294
- O ret = next ;
295
- computeNext ();
296
- return ret ;
297
- }
298
-
299
- private void computeNext () {
300
- while (objectsIt .hasNext ()) {
301
- next = objectsIt .next ();
302
- if (!exclude (next )) return ;
303
- }
304
- next = null ;
305
- }
306
-
307
- protected abstract boolean exclude (O object );
308
- }
309
-
310
216
}
0 commit comments