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

Method _saveBox

src/main/java/fieldbox/io/Raft.java:255–304  ·  view source on GitHub ↗
(Box x, Function<Box, String> alias, Predicate<Box> save)

Source from the content-addressed store, hash-verified

253 }
254
255 protected Node _saveBox(Box x, Function<Box, String> alias, Predicate<Box> save) throws IOException {
256
257 if (insideSave.containsKey(x)) return insideSave.get(x);
258 if (!save.test(x)) return null;
259 if (alias.apply(x) != null)
260 throw new IllegalArgumentException(" can't save a box called " + alias.apply(x) + " / " + x);
261
262 String uid = x.properties.getOrConstruct(IO.id);
263
264 Node at = new Node();
265 insideSave.put(x, at);
266
267 Map<Dict.Prop, Object> q = x.properties.getMap();
268 for (Map.Entry<Dict.Prop, Object> e : q.entrySet()) {
269 if (IO.isPeristant(e.getKey()) || e.getKey().getName().equals("code")) { // code is aliased in IO1
270 at.values.put(e.getKey().getName(), toValue(e.getKey(), e.getValue(), alias, save));
271 }
272 }
273
274 if (x.properties.get(IO.desiredBoxClass)!=null)
275 at.values.put("__class", x.properties.get(IO.desiredBoxClass));
276 else
277 at.values.put("__class", x.getClass().toString());
278
279 // disconnected?
280
281 at.children = x.children().stream().filter(z -> save.test(z)).map(z -> {
282 try {
283 String name = alias.apply(z);
284 if (name != null) return name;
285 return _saveBox(z, alias, save);
286 } catch (IOException e) {
287 e.printStackTrace();
288 }
289 return null;
290 }).filter(z -> z != null).collect(Collectors.toList());
291
292 at.parents = x.parents().stream().filter(z -> save.test(z)).map(z -> {
293 try {
294 String name = alias.apply(z);
295 if (name != null) return name;
296 return _saveBox(z, alias, save);
297 } catch (IOException e) {
298 e.printStackTrace();
299 }
300 return null;
301 }).filter(z -> z != null).collect(Collectors.toList());
302
303 return at;
304 }
305
306 private Object toValue(Dict.Prop key, Object value, Function<Box, String> alias, Predicate<Box> save) throws IOException {
307

Callers 3

saveTopologyMethod · 0.95
saveBoxMethod · 0.95
toValueMethod · 0.95

Calls 15

isPeristantMethod · 0.95
toValueMethod · 0.95
getMapMethod · 0.80
collectMethod · 0.80
childrenMethod · 0.80
parentsMethod · 0.80
getMethod · 0.65
applyMethod · 0.65
containsKeyMethod · 0.45
testMethod · 0.45
getOrConstructMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected