MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / breadthFirstAll

Method breadthFirstAll

src/main/java/fieldbox/boxes/Box.java:361–395  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

checkForDeletionMethod · 0.95
DrawingMethod · 0.80
freezeGraphMethod · 0.80
connectAllMethod · 0.80
allMethod · 0.80
isProgenyMethod · 0.80
goModalMethod · 0.80
DeleteMethod · 0.80
recursivelyShowFromMethod · 0.80
saveTopologyMethod · 0.80
uniqifyIfNecessaryMethod · 0.80

Calls 4

logMethod · 0.95
resetMethod · 0.65
sizeMethod · 0.45
streamMethod · 0.45

Tested by

no test coverage detected