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

org.openl.rules.ui.TraceHelper Maven / Gradle / Ivy

There is a newer version: 5.27.9
Show newest version
/**
 * OpenL Tablets,  2006
 * https://sourceforge.net/projects/openl-tablets/
 */
package org.openl.rules.ui;

import org.apache.commons.collections4.BidiMap;
import org.apache.commons.collections4.bidimap.DualHashBidiMap;

import org.openl.rules.webstudio.web.trace.node.ITracerObject;
import org.openl.rules.webstudio.web.trace.node.RefToTracerNodeObject;

/**
 * @author snshor
 */
public class TraceHelper {

    private final BidiMap traceTreeCache = new DualHashBidiMap<>();

    public ITracerObject getTableTracer(int elementId) {
        return traceTreeCache.get(elementId);
    }

    public void cacheTraceTree(ITracerObject tree) {
        traceTreeCache.clear();
        cacheTree(tree);
    }

    private void cacheTree(ITracerObject treeNode) {
        traceTreeCache.put(traceTreeCache.size(), treeNode);
        if (treeNode instanceof RefToTracerNodeObject) {
            // no need to add children nodes of reference node to the treeCache
            // because they will be added from original node
            return;
        }
        Iterable children = treeNode.getChildren();
        for (ITracerObject child : children) {
            cacheTree(child);
        }
    }

    public Integer getNodeKey(ITracerObject node) {
        return traceTreeCache.getKey(node);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy