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

Method _loadBox

src/main/java/fieldbox/io/Raft.java:114–198  ·  view source on GitHub ↗
(Node vertex, Function<String, Box> alias, Predicate<Node> load)

Source from the content-addressed store, hash-verified

112
113
114 private Box _loadBox(Node vertex, Function<String, Box> alias, Predicate<Node> load) throws InstantiationException, IllegalAccessException, IOException, ClassNotFoundException {
115 if (insideLoad.containsKey(vertex)) {
116 return insideLoad.get(vertex);
117 }
118 if (!load.test(vertex)) return null;
119
120 Set<String> keys = vertex.values.keySet();
121 Class<? extends Box> boxClass = Box.class;
122
123 if (keys.contains("__class")) {
124 try {
125 boxClass = (Class<? extends Box>) this.getClass().getClassLoader().loadClass(""+fromValue(null, vertex.values.get("__class"), alias, load));
126 } catch (ClassNotFoundException e) {
127 Log.log("error", () -> "can't find class to instantiate box, continuing on anyway");
128 }
129 // keys.remove("__class");
130 }
131
132 Box b = boxClass.newInstance();
133
134
135 if (keys.contains("__class")) {
136 b.properties.put(IO.desiredBoxClass, (String)vertex.values.get("__class"));
137 keys.remove("__class");
138 }
139
140 insideLoad.put(vertex, b);
141
142 for (String s : keys) {
143 if (s.startsWith("__")) continue;
144
145 Dict.Prop p = new Dict.Prop(s);
146 Dict.Prop pc = p.findCanon();
147 if (pc != null) p = pc;
148
149 Object val = fromValue(p, vertex.values.get(s), alias, load);
150 if (val != null) {
151 b.properties.put(p, val);
152 p.getAttributes().put(IO.persistent, true);
153 }
154 }
155
156 for (Object c : vertex.children) {
157 if (c instanceof Node) {
158 Box c2 = _loadBox((Node)c, alias, load);
159 if (c2 != null) {
160 b.connect(c2);
161 }
162 } else if (c instanceof String) {
163 Box c2 = alias.apply((String) c);
164 if (c2 != null) {
165 b.connect(c2);
166 }
167 } else
168 throw new IllegalArgumentException(" don't know what to make of child " + c + " / " + (c == null ? null : c.getClass()));
169 }
170 for (Object c : vertex.parents) {
171 if (c instanceof Node) {

Callers 1

loadTopologyMethod · 0.95

Calls 13

fromValueMethod · 0.95
logMethod · 0.95
findCanonMethod · 0.95
getAttributesMethod · 0.95
connectMethod · 0.95
getMethod · 0.65
applyMethod · 0.65
containsKeyMethod · 0.45
testMethod · 0.45
containsMethod · 0.45
putMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected