Example usage for org.apache.commons.collections.map LRUMap keySet

List of usage examples for org.apache.commons.collections.map LRUMap keySet

Introduction

In this page you can find the example usage for org.apache.commons.collections.map LRUMap keySet.

Prototype

public Set keySet() 

Source Link

Document

Gets the keySet view of the map.

Usage

From source file:org.paxle.filter.webgraph.gui.PrefuseServlet.java

private Graph buildGraph() {
    // creating the result structure
    Graph graph = new Graph(true);
    graph.addColumn(VisualItem.LABEL, String.class);

    // getting the relations map
    LRUMap relations = this.getRelations();

    // cloning the sourceDomain map
    HashMap<String, Node> domainMap = new HashMap<String, Node>();
    @SuppressWarnings("unchecked")
    HashSet<String> sourceDomains = new HashSet<String>(relations.keySet());

    for (String sourceDomain : sourceDomains) {
        // getting target domains
        @SuppressWarnings("unchecked")
        Set<String> targetDomains = (Set<String>) relations.get(sourceDomain);
        if (targetDomains == null || targetDomains.size() == 0)
            continue;

        // getting or creating source
        Node sourceNode = domainMap.get(sourceDomain);
        if (sourceNode == null) {
            sourceNode = graph.addNode();
            sourceNode.setString(VisualItem.LABEL, sourceDomain);
            domainMap.put(sourceDomain, sourceNode);
        }//w  w w. j  a v a  2  s .c o  m

        for (String targetDomain : targetDomains) {
            // getting or creating target
            Node targetNode = domainMap.get(targetDomain);
            if (targetNode == null) {
                targetNode = graph.addNode();
                targetNode.setString(VisualItem.LABEL, targetDomain);
                domainMap.put(targetDomain, targetNode);
            }

            // adding link
            graph.addEdge(sourceNode, targetNode);
        }
    }

    return graph;
}

From source file:org.paxle.filter.webgraph.gui.SourceServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    /*/*from   w w w. j  a va2 s .c  o m*/
     * Okay, we have a lot of relations here. the filter stores up to 5000 domains with all relations,
     * if we graph this, the graph gets big and there is no overview.
     * What we do at the moment is this:
     * - limit the maximum Number of Nodes(Domains) to maxDomains(=100)
     * - limit the number of new domains introduced by a parent-domain to count(=5)
     * this keeps the graph small.
     */
    LRUMap relations = ((GraphFilter) this.filter).getRelations();
    StringBuffer result = new StringBuffer("digraph domains{\nedge [color=\"#80808080\"]\n");
    Iterator it = (new HashSet(relations.keySet())).iterator();
    int maxDomains = 1000;
    int maxChildDomains = 5;
    int numDomains = 0;
    int minReferences = 3;
    HashSet<String> domains = new HashSet<String>();
    while (it.hasNext()) {
        String domain1 = (String) it.next();
        //skip if the domain is new and we already know maxDomains
        if (!domains.contains(domain1)) {
            if (numDomains >= maxDomains)
                continue;
            domains.add(domain1);
            numDomains++;
        }
        //only nodes with at least minReferences ChildNodes (no lonely nodes)
        if (((Set) relations.get(domain1)).size() < minReferences)
            continue;
        Iterator<String> it2 = ((Set) relations.get(domain1)).iterator();
        int count = 0; //new domains from this parent-node
        while (it2.hasNext()) {
            String domain2 = (String) it2.next();
            if (!domains.contains(domain2)) {
                if (numDomains >= maxDomains)
                    continue;
                if (count > maxChildDomains)
                    continue;
                numDomains++;
                domains.add(domain2);
                count++;
            }
            result.append("\"").append(domain1).append("\"").append("->").append("\"").append(domain2)
                    .append("\";\n");
        }
    }
    result.append("}");
    resp.setContentType("text/plain");
    resp.setStatus(200);
    resp.getOutputStream().print(result.toString());
}