returns breadth first Stream given a direction function. This function ignores "disconnected" states. It's typically used only for IO
(Function<Box, Collection<Box>> map)
| 359 | |
| 360 | /** |
| 361 | * returns breadth first Stream given a direction function. This function ignores "disconnected" states. It's typically used only for IO |
| 362 | */ |
| 363 | @HiddenInAutocomplete |
| 364 | public Stream<Box> breadthFirstAll(Function<Box, Collection<Box>> map) { |
| 365 | |
| 366 | if (this.all.size() == 0) |
| 367 | Log.log("box.warning", () -> " breadthFirst called on a box not connected to the box graph"); |
| 368 | |
| 369 | return new Lazy<Box>() { |
| 370 | LinkedHashSet<Box> ret = null; |
| 371 | Set<Box> thisLevel = null; |
| 372 | |
| 373 | protected Iterator<Box> initialize() { |
| 374 | |
| 375 | ret = new LinkedHashSet<>(); |
| 376 | ret.add(Box.this); |
| 377 | thisLevel = ret; |
| 378 | return ret.iterator(); |
| 379 | } |
| 380 | |
| 381 | @Override |
| 382 | protected Iterator<Box> pull() { |
| 383 | if (thisLevel.size() == 0) return null; |
| 384 | |
| 385 | Set<Box> nextLevel = new LinkedHashSet<>(); |
| 386 | for (Box b : thisLevel) |
| 387 | nextLevel.addAll(map.apply(b)); |
| 388 | nextLevel.removeAll(ret); |
| 389 | ret.addAll(nextLevel); |
| 390 | thisLevel = nextLevel; |
| 391 | |
| 392 | return thisLevel.iterator(); |
| 393 | |
| 394 | } |
| 395 | }.reset() |
| 396 | .stream(); |
| 397 | } |
| 398 |
no test coverage detected