All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.pkl.thirdparty.commonmark.internal.renderer.NodeRendererMap Maven / Gradle / Ivy

Go to download

Fat Jar containing pkl-cli, pkl-codegen-java, pkl-codegen-kotlin, pkl-config-java, pkl-core, pkl-doc, and their shaded third-party dependencies.

There is a newer version: 0.27.1
Show newest version
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