|
37 | 37 | import java.util.Collections; |
38 | 38 | import java.util.HashMap; |
39 | 39 | import java.util.HashSet; |
| 40 | +import java.util.Iterator; |
40 | 41 | import java.util.LinkedHashMap; |
41 | 42 | import java.util.List; |
42 | 43 | import java.util.Map; |
| 44 | +import java.util.NoSuchElementException; |
43 | 45 | import java.util.Optional; |
44 | 46 | import java.util.Set; |
45 | 47 | import java.util.concurrent.Callable; |
46 | 48 | import java.util.concurrent.locks.Lock; |
47 | 49 | import java.util.concurrent.locks.ReadWriteLock; |
48 | 50 | import java.util.concurrent.locks.ReentrantReadWriteLock; |
| 51 | +import java.util.function.Consumer; |
49 | 52 | import java.util.stream.Stream; |
50 | 53 |
|
51 | 54 | import static jdk.graal.compiler.graphio.parsing.model.KnownPropertyNames.PROPNAME_NAME; |
@@ -399,6 +402,57 @@ public InputGraph getGraph() { |
399 | 402 | return graph; |
400 | 403 | } |
401 | 404 |
|
| 405 | + |
| 406 | + public Iterable<Connection> iterateConnections() { |
| 407 | + return new Iterable<>() { |
| 408 | + @Override |
| 409 | + public Iterator<Connection> iterator() { |
| 410 | + return new Iterator<>() { |
| 411 | + |
| 412 | + final Iterator<Figure> figureMapIterator = figureMap.values().iterator(); |
| 413 | + Iterator<InputSlot> inputSlotIterator = Collections.emptyIterator(); |
| 414 | + Iterator<Connection> connectionIterator = Collections.emptyIterator(); |
| 415 | + |
| 416 | + @Override |
| 417 | + public boolean hasNext() { |
| 418 | + while (true) { |
| 419 | + if (connectionIterator.hasNext()) { |
| 420 | + return true; |
| 421 | + } |
| 422 | + if (inputSlotIterator.hasNext()) { |
| 423 | + connectionIterator = inputSlotIterator.next().getConnections().iterator(); |
| 424 | + continue; |
| 425 | + } |
| 426 | + if (figureMapIterator.hasNext()) { |
| 427 | + inputSlotIterator = figureMapIterator.next().getInputSlots().iterator(); |
| 428 | + continue; |
| 429 | + } |
| 430 | + return false; |
| 431 | + } |
| 432 | + } |
| 433 | + |
| 434 | + @Override |
| 435 | + public Connection next() { |
| 436 | + if (!hasNext()) { |
| 437 | + throw new NoSuchElementException(); |
| 438 | + } |
| 439 | + return connectionIterator.next(); |
| 440 | + } |
| 441 | + |
| 442 | + @Override |
| 443 | + public void remove() { |
| 444 | + throw new UnsupportedOperationException(); |
| 445 | + } |
| 446 | + |
| 447 | + @Override |
| 448 | + public void forEachRemaining(Consumer<? super Connection> action) { |
| 449 | + throw new UnsupportedOperationException(); |
| 450 | + } |
| 451 | + }; |
| 452 | + } |
| 453 | + }; |
| 454 | + } |
| 455 | + |
402 | 456 | public Set<Connection> getConnections() { |
403 | 457 |
|
404 | 458 | Set<Connection> connections = new HashSet<>(); |
|
0 commit comments