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

Method getCommandsAndDocs

src/main/java/fielded/Commands.java:174–227  ·  view source on GitHub ↗
(Box box)

Source from the content-addressed store, hash-verified

172 }
173
174 public static List<Triple<String, String, Runnable>> getCommandsAndDocs(Box box) {
175 List<Triple<String, String, Runnable>> commands = box.find(Commands.commands, box.both())
176 .flatMap(m -> {
177 try {
178 return m.get()
179 .entrySet()
180 .stream();
181 } catch (Throwable t) {
182 System.err.println(" Exception throw looking for commands, carrying on");
183 t.printStackTrace();
184 }
185 return null;
186 })
187 .map(x -> new Triple<>(x.getKey().first, x.getKey().second, x.getValue()))
188 .collect(Collectors.toList());
189
190
191 IdempotencyMap<Function<Box, Void>> map = box.find(command, box.upwards())
192 .reduce(new IdempotencyMap<Function<Box, Void>>(Function.class), (a1, a2) -> {
193 IdempotencyMap<Function<Box, Void>> q = new IdempotencyMap<>(Function.class);
194 q.putAll(a1);
195 q.putAll(a2);
196 return q;
197 });
198 IdempotencyMap<String> mapDoc = box.find(commandDoc, box.upwards())
199 .reduce(new IdempotencyMap<String>(String.class), (a1, a2) -> {
200 IdempotencyMap<String> q = new IdempotencyMap<>(String.class);
201 q.putAll(a1);
202 q.putAll(a2);
203 return q;
204 });
205
206 IdempotencyMap<Function<Box, Boolean>> guardDoc = box.find(commandGuard, box.upwards())
207 .reduce(new IdempotencyMap<Function<Box, Boolean>>(FunctionOfBox.class), (a1, a2) -> {
208 IdempotencyMap<Function<Box, Boolean>> q = new IdempotencyMap<>(FunctionOfBox.class);
209 q.putAll(a1);
210 q.putAll(a2);
211 return q;
212 });
213
214 map.entrySet()
215 .forEach(x -> {
216 Function<Box, Boolean> g = guardDoc.get(x.getKey());
217 if (g == null || g.apply(box)) {
218 String name = rewriteCamelCase(x.getKey());
219 String doc = mapDoc.getOrDefault(x.getKey(), "");
220 commands.add(new Triple<String, String, Runnable>(name, doc, () -> {
221 x.getValue()
222 .apply(box);
223 }));
224 }
225 });
226 return commands;
227 }
228
229 static private String rewriteCamelCase(String key) {
230 return key.replace("_", " ");

Callers 3

applyMethod · 0.95
requestCommandsMethod · 0.95

Calls 14

rewriteCamelCaseMethod · 0.95
collectMethod · 0.80
upwardsMethod · 0.80
putAllMethod · 0.80
getMethod · 0.65
applyMethod · 0.65
mapMethod · 0.45
findMethod · 0.45
bothMethod · 0.45
streamMethod · 0.45
printlnMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected