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

Method breadthFirst

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

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)

Source from the content-addressed store, hash-verified

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

Callers 15

hasMethod · 0.95
whereHasMethod · 0.95
findMethod · 0.95
firstMethod · 0.95
nextMethod · 0.95
callMethod · 0.95
getCompletionsForMethod · 0.95
dispatchMethod · 0.95
registerCommandsMethod · 0.95
MakeNewTextEditorMethod · 0.95
OpenMethod · 0.80
DefaultMenusMethod · 0.80

Calls 4

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

Tested by

no test coverage detected