org.pkl.thirdparty.commonmark.internal.renderer.NodeRendererMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pkl-tools Show documentation
Show all versions of pkl-tools Show documentation
Fat Jar containing pkl-cli, pkl-codegen-java, pkl-codegen-kotlin, pkl-config-java, pkl-core, pkl-doc, and their shaded third-party dependencies.
package org.pkl.thirdparty.commonmark.internal.renderer;
import org.pkl.thirdparty.commonmark.node.Node;
import org.pkl.thirdparty.commonmark.renderer.NodeRenderer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class NodeRendererMap {
private final List nodeRenderers = new ArrayList<>();
private final Map, NodeRenderer> renderers = new HashMap<>(32);
public void add(NodeRenderer nodeRenderer) {
nodeRenderers.add(nodeRenderer);
for (var nodeType : nodeRenderer.getNodeTypes()) {
// The first node renderer for a node type "wins".
renderers.putIfAbsent(nodeType, nodeRenderer);
}
}
public void render(Node node) {
var nodeRenderer = renderers.get(node.getClass());
if (nodeRenderer != null) {
nodeRenderer.render(node);
}
}
public void beforeRoot(Node node) {
nodeRenderers.forEach(r -> r.beforeRoot(node));
}
public void afterRoot(Node node) {
nodeRenderers.forEach(r -> r.afterRoot(node));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy