(Box x, Function<Box, String> alias, Predicate<Box> save)
| 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 |
no test coverage detected