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

Method callFunction

src/main/java/fieldbox/boxes/Callbacks.java:395–466  ·  view source on GitHub ↗
(Box box, Dict.Prop<IdempotencyMap<Function<Object, Object>>> main, Object argMap)

Source from the content-addressed store, hash-verified

393
394 return ret;
395 }
396
397 public static Object callFunction(Box box, Dict.Prop<IdempotencyMap<Function<Object, Object>>> main, Object argMap) {
398 Map<String, Object> undoMap = new LinkedHashMap<>();
399
400
401 Object ret = null;
402
403
404 boolean success = false;
405 try {
406 Map<?, ?> m = (Map<?, ?>) ScriptUtils.convert(argMap, Map.class);
407 for (Map.Entry<?, ?> e : m.entrySet()) {
408 Object was = box.properties.get(new Dict.Prop("" + e.getKey()));
409 if (box.properties.has(new Dict.Prop("" + e.getKey())))
410 undoMap.put("" + e.getKey(), was);
411
412 box.asMap_set("" + e.getKey(), e.getValue());
413 }
414 success = true;
415
416 try {
417
418 if (!box.properties.has(main) || box.properties.get(main)
419 .values()
420 .size() == 0) {
421 if (Execution.context.get()
422 .stream()
423 .filter(x -> x == box)
424 .count() > 1 && !box.properties.isTrue(new Dict.Prop("recur"), false))
425 return null;
426
427// String code = box.properties.get(Execution.code);
428 String code = DisabledRangeHelper.getStringWithDisabledRanges(box, Execution.code, "/* -- start -- ", "-- end -- */");
429 if (code != null) box.first(Execution.execution)
430 .ifPresent(x -> x.support(box, Execution.code)
431 .executeAll(code, box));
432
433 }
434
435 IdempotencyMap<Function<Object, Object>> map = box.find(main, box.upwards())
436 .reduce(new IdempotencyMap<Function<Object, Object>>(Function.class), (a1, a2) -> {
437 IdempotencyMap<Function<Object, Object>> q = new IdempotencyMap<>(Function.class);
438 q.putAll(a1);
439 q.putAll(a2);
440 return q;
441 });
442
443
444 Object[] firstRet = {null};
445 map.values()
446 .forEach(x -> {
447 firstRet[0] = x.apply(firstRet[0]);
448 });
449
450 return firstRet[0];
451
452 } finally {

Callers

nothing calls this directly

Calls 15

countMethod · 0.80
isTrueMethod · 0.80
firstMethod · 0.80
upwardsMethod · 0.80
putAllMethod · 0.80
getMethod · 0.65
asMap_setMethod · 0.65
executeAllMethod · 0.65
applyMethod · 0.65
convertMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected