MCPcopy
hub / github.com/xpipe-io/xpipe / get

Method get

app/src/main/java/io/xpipe/app/test/TestModule.java:15–43  ·  view source on GitHub ↗
(Class<T> c, Module module, String... classes)

Source from the content-addressed store, hash-verified

13 private static final Map<Class<?>, Map<String, ?>> values = new LinkedHashMap<>();
14
15 @SuppressWarnings({"unchecked", "rawtypes"})
16 @SneakyThrows
17 public static <T> Map<String, T> get(Class<T> c, Module module, String... classes) {
18 if (!values.containsKey(c)) {
19 List<Class<?>> loadedClasses = Arrays.stream(classes)
20 .map(s -> {
21 return Optional.<Class<?>>of(Class.forName(module, s));
22 })
23 .flatMap(Optional::stream)
24 .toList();
25 loadedClasses.forEach(o -> {
26 try {
27 var instance = (TestModule<?>) o.getConstructor().newInstance();
28 Map list = values.computeIfAbsent(instance.getValueClass(), aClass -> new LinkedHashMap());
29 instance.init(list);
30 } catch (Exception e) {
31 throw new RuntimeException(e);
32 }
33 });
34 }
35
36 Map<String, Object> map = new HashMap<>();
37 for (Map.Entry<String, ?> o : values.get(c).entrySet()) {
38 if (map.put(o.getKey(), ((FailableSupplier<?>) o.getValue()).get()) != null) {
39 throw new IllegalStateException("Duplicate key");
40 }
41 }
42 return (Map<String, T>) map;
43 }
44
45 public static <T> Stream<Named<T>> getArguments(Class<T> c, Module module, String... classes) {
46 Stream.Builder<Named<T>> argumentBuilder = Stream.builder();

Callers 1

getArgumentsMethod · 0.95

Calls 8

flatMapMethod · 0.80
getValueClassMethod · 0.80
getKeyMethod · 0.80
ofMethod · 0.65
initMethod · 0.65
getMethod · 0.65
mapMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected