| 958 | if (calling == null) throw new Error(); |
| 959 | return calling.apply(this, a); |
| 960 | } |
| 961 | |
| 962 | @Override |
| 963 | public Object asMap_get(String p) { |
| 964 | |
| 965 | Optional<Box> q = startFrom.breadthFirst(startFrom.upwards()) |
| 966 | .flatMap(x -> x.children() |
| 967 | .stream() |
| 968 | .filter(bx -> clazz.isInstance(bx) && bx.properties.getOr(Box.name, () -> "") |
| 969 | .equals(namePrefix + ":" + p))) |
| 970 | .findFirst(); |
| 971 | |
| 972 | |
| 973 | if (q.isPresent()) return q.get(); |
| 974 | |
| 975 | Box b = autoconstructor.apply(startFrom); |
| 976 | b.properties.put(Box.name, namePrefix + ":" + p); |
| 977 | if (!clazz.isInstance(b)) |
| 978 | throw new IllegalArgumentException(" autoconstructor didn't return an object of the correct class <" + b.getClass() + "> <" + clazz + ">"); |
| 979 | |
| 980 | startFrom.connect(b); |
| 981 | |
| 982 | return b; |
| 983 | } |
| 984 | |