returns breadth first Stream given a direction function. It is an error to call this when this box is not connected to anything (which is a common error --- calling this method at construction time).
(Function<Box, Collection<Box>> map)
| 319 | /** |
| 320 | * returns breadth first Stream given a direction function. It is an error to call this when this box is not connected to anything (which is a common error --- calling this method at |
| 321 | * construction time). |
| 322 | */ |
| 323 | @HiddenInAutocomplete |
| 324 | public Stream<Box> breadthFirst(Function<Box, Collection<Box>> map) { |
| 325 | |
| 326 | if (this.all.size() == 0) |
| 327 | Log.log("box.warning", () -> " breadthFirst called on a box not connected to the box graph"); |
| 328 | |
| 329 | return new Lazy<Box>() { |
| 330 | LinkedHashSet<Box> ret = null; |
| 331 | Set<Box> thisLevel = null; |
| 332 | |
| 333 | protected Iterator<Box> initialize() { |
| 334 | |
| 335 | ret = new LinkedHashSet<>(); |
| 336 | ret.add(Box.this); |
| 337 | thisLevel = ret; |
| 338 | return ret.iterator(); |
| 339 | } |
| 340 | |
| 341 | @Override |
| 342 | protected Iterator<Box> pull() { |
| 343 | if (thisLevel.size() == 0) return null; |
| 344 | |
| 345 | Set<Box> nextLevel = new LinkedHashSet<>(); |
| 346 | for (Box b : thisLevel) |
| 347 | if (!b.disconnected) |
| 348 | nextLevel.addAll(map.apply(b)); |
| 349 | nextLevel.removeAll(ret); |
| 350 | ret.addAll(nextLevel); |
| 351 | thisLevel = nextLevel; |
| 352 | |
| 353 | return thisLevel.iterator(); |
| 354 | |
| 355 | } |
| 356 | }.reset() |
| 357 | .stream().filter(x -> !x.disconnected); |
| 358 | } |
| 359 |
no test coverage detected