@Override public boolean isDefined(String name) { return getCurrentEntries().containsKey(name); }
public static Object stubDMNResult(Object result) { if ( result instanceof DMNContext ) { Map<String, Object> stubbedContextValues = new HashMap<>(); for (Entry<String, Object> kv : ((DMNContext) result).getAll().entrySet()) { stubbedContextValues.put(kv.getKey(), stubDMNResult(kv.getValue())); } return MapBackedDMNContext.of(stubbedContextValues); } else if ( result instanceof Map<?, ?> ) { Map<Object, Object> stubbedValues = new HashMap<>(); for (Entry<?, ?> kv : ((Map<?, ?>) result).entrySet()) { stubbedValues.put(kv.getKey(), stubDMNResult(kv.getValue())); } return stubbedValues; } else if ( result instanceof List<?> ) { List<?> stubbedValues = ((List<?>) result).stream().map(DMNResultKS::stubDMNResult).collect(Collectors.toList()); return stubbedValues; } else if ( result instanceof Set<?> ) { Set<?> stubbedValues = ((Set<?>) result).stream().map(DMNResultKS::stubDMNResult).collect(Collectors.toSet()); return stubbedValues; } else if ( result != null && result.getClass().getPackage().getName().startsWith("org.kie.dmn") ) { return DMNNodeStub.of(result); } return result; }
@Override public Map<String, Object> getAll() { return getCurrentEntries(); }
@Override public Object set(String name, Object value) { return getCurrentEntries().put(name, value); }
@Override public Object get(String name) { return getCurrentEntries().get(name); }
@Override public DMNContext clone() { return of(this.ctx); }
@Override public void pushScope(String name, String namespace) { Map<String, Object> scopeRef = (Map<String, Object>) getCurrentEntries().computeIfAbsent(name, s -> new LinkedHashMap<String, Object>()); stack.push(new ScopeReference(name, namespace, scopeRef)); }
static MapBackedDMNContext of(Map<String, Object> ctx) { MapBackedDMNContext result = new MapBackedDMNContext(); result.ctx = ctx; return result; }
@Override public DMNContext getContext() { // TODO rewiew, this means the DMNContext returned is detached from the internal context here. return MapBackedDMNContext.of(dmnContext); }