Example usage for org.apache.commons.collections MultiMap keySet

List of usage examples for org.apache.commons.collections MultiMap keySet

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

Returns a Set view of the keys contained in this map.

Usage

From source file:edu.uci.ics.jung.graph.impl.BipartiteGraph.java

/**
 * Creates a one-part graph from a bipartite graph by folding
 * Vertices from one class into a second class. This function
 * creates a new UndirectedGraph (with vertex set V') in which: <br>
 * <ul>/*from   ww  w  .  j a  v a 2 s .c om*/
 * <li> each vertex in V' has an equivalent V in bpg.getAllVertices( class ) </li>
 * <li> an edge E' joins V'1 and V'2 iff there is a path of length 2 from
 * V1 to V2 (by way of some third vertex in the other class, VXs) </li>
 * <li> each edge E' is annotated with the set of vertices VXs </li>
 * </ul>
 * 
 * In social network analysis and related fields, this operation transforms
 * an actor-by-event chart into an actor-by-actor chart.
 * 
 * @param bpg      The bipartite graph to be folded
 * @param vertexSet      Chooses the set of vertices to be brought into
 *                the new Graph.
 * @return   an UndirectedSparseGraph.
 */
public static Graph fold(BipartiteGraph bpg, Choice vertexSet) {
    Graph newGraph = new UndirectedSparseGraph();
    Set vertices = bpg.getAllVertices(vertexSet);
    for (Iterator iter = vertices.iterator(); iter.hasNext();) {
        BipartiteVertex v = (BipartiteVertex) iter.next();
        v.copy(newGraph);
    }

    Set coveredNodes = new HashSet();

    for (Iterator iter = vertices.iterator(); iter.hasNext();) {
        BipartiteVertex v = (BipartiteVertex) iter.next();
        coveredNodes.add(v);

        // the set of all Bs that touch this A
        Set hyperEdges = v.getNeighbors();

        // this will ultimately contain a mapping from
        // the next adjacent "A" to the list of "B"s that support that
        // connection (that is, all Bs that run between this A and its neighbor
        MultiMap mm = new MultiHashMap();
        for (Iterator iterator = hyperEdges.iterator(); iterator.hasNext();) {
            Vertex hyperEdge = (Vertex) iterator.next();
            addAll(mm, hyperEdge.getNeighbors(), hyperEdge);
        }
        for (Iterator iterator = mm.keySet().iterator(); iterator.hasNext();) {
            Vertex aVertex = (Vertex) iterator.next();

            if (coveredNodes.contains(aVertex))
                continue;

            Edge newEdge = GraphUtils.addEdge(newGraph, (Vertex) v.getEqualVertex(newGraph),
                    (Vertex) aVertex.getEqualVertex(newGraph));
            newEdge.addUserDatum(BIPARTITE_USER_TAG, mm.get(aVertex), UserData.SHARED);
        }
    }
    return newGraph;
}

From source file:gov.nih.nci.caadapter.ui.mapping.sdtm.SDTMMapFileTransformer.java

public void BeginTransformation() throws Exception {
    /**/*  w ww .jav  a  2 s .  co m*/
     * 1. For each key in the _csvDataFromFile, check if the key exists in _mappedData <br>
     * 1a. If exists, get the pos and the colmnname <br>
     * 2. create SDTM record instance <br>
     * 2a. setRecord <br>
     * 3. print rec <br>
     */
    SDTMRecord _sdtm = new SDTMRecord();
    MultiMap mhm = new SDTM_CSVReader().readCSVFile(_csvFileName);
    // Iterate over the keys in the map
    Iterator it = mhm.keySet().iterator();
    while (it.hasNext()) {
        // SDTMRecord _sdtm = new SDTMRecord(_csvDataFromFile);
        // Get key
        Object key = it.next();
        if (_mappedData.containsKey(key)) {
            Collection coll = (Collection) mhm.get(key);
            for (Iterator it1 = coll.iterator(); it1.hasNext();) {
                Object mappedKey = it1.next();
                StringBuffer _value = (StringBuffer) _mappedData.get(key);
                // System.out.println("==============================================");
                // System.out.println("Mappedvalues " + _value);
                // System.out.println("CSVValues are " + mappedKey);
                StringTokenizer _level0 = new StringTokenizer(_value.toString(), ",");
                while (_level0.hasMoreTokens()) {
                    StringTokenizer str = new StringTokenizer(_level0.nextToken(), "?");
                    int pos = new Integer(str.nextToken().substring(0, 2).trim()).intValue();
                    String dataKey = str.nextToken();
                    EmptyStringTokenizer emp = new EmptyStringTokenizer(mappedKey.toString(), ",");
                    createRecord1(_sdtm, emp.getTokenAt(pos - 1).toString(), dataKey.replace('.', '_'));
                }
            }
        }
    }
    _sdtm.print(defineXMLList.toString(), _saveSDTMPath);
}

From source file:edu.uci.ics.jung.algorithms.blockmodel.GraphCollapser.java

/**
 * Internal method for collapsing a set of vertexes.
 * //  w  ww . j a  v  a  2s .c  o m
 * @param er
 * @param superVertices
 * @param vertices_to_edges
 */
protected void collapseVerticesIntoSuperVertices(EquivalenceRelation er, Map superVertices,
        MultiMap vertices_to_edges) {

    Set vertices = new HashSet(vertices_to_edges.keySet());
    // some of these vertices may be parts of one or another root set
    for (Iterator destinations = vertices.iterator(); destinations.hasNext();) {
        Vertex dest = (Vertex) destinations.next();
        Set destSet = er.getEquivalenceRelationContaining(dest);
        if (destSet != null) {
            CollapsedVertex superV = (CollapsedVertex) superVertices.get(destSet);
            replaceWith(vertices_to_edges, dest, superV);
        }
    }
}

From source file:edu.uci.ics.jung.algorithms.blockmodel.GraphCollapser.java

/**
 * INTERNAL METHOD/*from   w w  w .j  a v a2  s. co  m*/
 */
protected void createEdgesCorrespondingToMap(Graph copy, CollapsedVertex cv, MultiMap vertices_to_edges,
        Set coveredCV) {
    for (Iterator iter = vertices_to_edges.keySet().iterator(); iter.hasNext();) {

        Vertex edgeDestination = (Vertex) iter.next();

        // this line does nothing for CVs, but is useful for other vertices
        // opposite is either a CollapsedVertex, or it's a copy of the origial
        // if we've already seen it, we should skip it; we've already done those edges
        if (coveredCV.contains(edgeDestination))
            continue;

        Set relevantEdges = new HashSet((Collection) vertices_to_edges.get(edgeDestination));

        edgeDestination = (Vertex) edgeDestination.getEqualVertex(copy);

        if (shouldAddEdge(edgeDestination, cv.getRootSet(), relevantEdges)) {

            if (PredicateUtils.enforcesEdgeConstraint(copy, Graph.DIRECTED_EDGE))
                createDirectedEdges(copy, cv, edgeDestination, relevantEdges);
            else if (PredicateUtils.enforcesEdgeConstraint(copy, Graph.UNDIRECTED_EDGE))
                createUndirectedEdge(copy, cv, edgeDestination, relevantEdges);
            else
                throw new IllegalArgumentException(
                        "Mixed (directed/undirected) " + "graphs not currently supported");
        }
    }

}

From source file:edu.uci.ics.jung.algorithms.blockmodel.GraphCollapser.java

/**
 * This function collapses a series of vertices in one
 * EquivalenceSet into one//from w w w  . j a v a  2  s  . c o m
 * CollapsedVertex. 
 * @param g      A graph to collapse vertices from
 * @param rootSet   A set of vertice to collapse into one CollapsedVertex
 * @return      A graph with rootset.size()-1 fewer vertices.
 */
public Graph getCollapsedGraph(Graph g, Set rootSet) {

    // first, we copy the original graph
    Graph copy = (Graph) g.copy();

    // and remove our set to merge
    for (Iterator iter = rootSet.iterator(); iter.hasNext();) {
        Vertex v = (Vertex) iter.next();
        copy.removeVertex((Vertex) v.getEqualVertex(copy));
    }

    // and create one new vertex
    CollapsedVertex superVertex = createCollapsedVertex(copy, rootSet);
    annotateVertex(superVertex, rootSet);

    MultiMap vertices_to_edges = findEdgesAndVerticesConnectedToRootSet(superVertex.getRootSet());

    for (Iterator iter = vertices_to_edges.keySet().iterator(); iter.hasNext();) {
        Vertex opposite = (Vertex) iter.next();
        opposite = (Vertex) opposite.getEqualVertex(copy);
        Set relevantEdges = new HashSet((Collection) vertices_to_edges.get(opposite));

        if (shouldAddEdge(opposite, superVertex.getRootSet(), relevantEdges)) {

            if (PredicateUtils.enforcesEdgeConstraint(g, Graph.DIRECTED_EDGE)) {
                createDirectedEdges(copy, superVertex, opposite, relevantEdges);
            } else if (PredicateUtils.enforcesEdgeConstraint(g, Graph.UNDIRECTED_EDGE)) {
                createUndirectedEdge(copy, superVertex, opposite, relevantEdges);
            } else
                throw new IllegalArgumentException(
                        "Mixed (directed/undirected" + " graphs not currently supported");
        }
    }

    return copy;
}

From source file:com.pactera.edg.am.metamanager.extractor.adapter.mapping.impl.RecordExtractMappingServiceImpl.java

/**
 * ?????????<br>/*  w  w  w  .jav a 2 s.  co  m*/
 * ??depReferences?????
 * @param cfg ?
 * @return ?
 * @throws SQLException ?
 */
protected List<MMDDependency> extractDependency(TRecordConfigFull cfg) throws SQLException {
    // ??
    List<TRecordRelationship> depList = cfg.findAllDependency();
    for (int i = 0; i < depList.size(); i++) {
        if (depList.get(i).useSql()) {
            this.queryDependencyRelation(depList.get(i));
        }
    }

    // ? (???????)
    List<MMDDependency> result = new ArrayList<MMDDependency>();
    for (Iterator<TRecordRelationship> depIt = this.depReferences.keySet().iterator(); depIt.hasNext();) {
        TRecordRelationship depc = depIt.next();
        MultiMap map = this.depReferences.get(depc);
        for (Iterator<?> fromIt = map.keySet().iterator(); fromIt.hasNext();) {
            String fromId = (String) fromIt.next();
            Collection<?> toIds = (Collection<?>) map.get(fromId); //MultiMap
            if (toIds == null || toIds.isEmpty()) {
                continue;
            }
            MdKey fromKey = MetadataMap.getMetadataKey(depc.getFromClassifier(), fromId);
            List<MMMetadata> fromMetadatas = this.mdReferences.getByInherit(fromKey, cfg.getInherits());
            if (fromMetadatas == null || fromMetadatas.isEmpty()) {
                continue;
            }
            for (Iterator<?> toIt = toIds.iterator(); toIt.hasNext();) {
                String toId = (String) toIt.next();
                MdKey toKey = MetadataMap.getMetadataKey(depc.getToClassifier(), toId);
                List<MMMetadata> toMetadatas = this.mdReferences.getByInherit(toKey, cfg.getInherits());
                if (toMetadatas == null || toMetadatas.isEmpty()) {
                    continue;
                }

                for (Iterator<MMMetadata> it1 = fromMetadatas.iterator(); it1.hasNext();) {
                    MMMetadata fromMetadata = it1.next();
                    for (Iterator<MMMetadata> it2 = toMetadatas.iterator(); it2.hasNext();) {
                        MMMetadata toMetadata = it2.next();
                        MMDDependency dependency = new MMDDependency();
                        dependency.setOwnerMetadata(fromMetadata);
                        dependency.setValueMetadata(toMetadata);
                        dependency.setOwnerRole(depc.getFromRole());
                        dependency.setValueRole(depc.getToRole());
                        result.add(dependency);
                    }
                }
            }
        }
    }

    return result;
}

From source file:edu.harvard.med.screensaver.service.cherrypicks.CherryPickRequestPlateMapFilesBuilder.java

@SuppressWarnings("unchecked")
private InputStream doBuildZip(CherryPickRequest cherryPickRequest, Set<CherryPickAssayPlate> forPlates)
        throws IOException {
    ByteArrayOutputStream zipOutRaw = new ByteArrayOutputStream();
    ZipOutputStream zipOut = new ZipOutputStream(zipOutRaw);
    MultiMap/*<String,SortedSet<CherryPick>>*/ files2CherryPicks = buildCherryPickFiles(cherryPickRequest,
            forPlates);//  w w w. j ava2s .com
    buildReadme(cherryPickRequest, zipOut);
    buildDistinctPlateCopyFile(cherryPickRequest, forPlates, zipOut);
    PrintWriter out = new CSVPrintWriter(new OutputStreamWriter(zipOut), NEWLINE);
    for (Iterator iter = files2CherryPicks.keySet().iterator(); iter.hasNext();) {
        String fileName = (String) iter.next();
        ZipEntry zipEntry = new ZipEntry(fileName);
        zipOut.putNextEntry(zipEntry);
        writeHeadersRow(out);
        for (LabCherryPick cherryPick : (SortedSet<LabCherryPick>) files2CherryPicks.get(fileName)) {
            writeCherryPickRow(out, cherryPick);
        }
        out.flush();
    }
    out.close();
    return new ByteArrayInputStream(zipOutRaw.toByteArray());
}

From source file:fr.in2p3.cc.storage.treqs.control.dispatcher.Dispatcher.java

/**
 * Processes the new requests and then put them in queues.
 * <p>//from w w w .j ava  2s .c o  m
 * TODO v2.0 This should be multithreaded in order to ask several file
 * properties to the server simultaneously.
 * 
 * @param newRequests
 *            Map of new requests.
 * @throws TReqSException
 *             If there is a problem while processing the requests.
 */
@SuppressWarnings("unchecked")
private void process(final MultiMap newRequests) throws TReqSException {
    LOGGER.trace("> process");

    assert newRequests != null;

    short counter = this.maxFilesBeforeMessage;
    final Iterator<String> iterator = newRequests.keySet().iterator();
    while (iterator.hasNext()) {
        final String filename = iterator.next();
        final Iterator<FileRequest> iterator2 = ((Collection<FileRequest>) newRequests.get(filename))
                .iterator();
        while (iterator2.hasNext()) {
            final FileRequest fileRequest = iterator2.next();

            counter--;
            if (counter == 0) {
                LOGGER.info("{} files done", this.maxFilesBeforeMessage);
                counter = this.maxFilesBeforeMessage;
            }

            this.innerProcess(fileRequest);

        }
        if (newRequests.size() > 0) {
            LOGGER.info("Processing {} request(s)", newRequests.size());
        }
    }

    LOGGER.trace("< process");
}

From source file:ar.com.fdvs.dj.core.layout.AbstractLayoutManager.java

protected void layoutCharts() {
    //Pre-sort charts by group column
    MultiMap mmap = new MultiHashMap();
    for (Iterator iter = getReport().getCharts().iterator(); iter.hasNext();) {
        DJChart djChart = (DJChart) iter.next();
        mmap.put(djChart.getColumnsGroup(), djChart);
    }//from  www. ja  v a2 s.  co m

    for (Iterator iterator = mmap.keySet().iterator(); iterator.hasNext();) {
        Object key = iterator.next();
        Collection charts = (Collection) mmap.get(key);
        ArrayList l = new ArrayList(charts);
        //Reverse iteration of the charts to meet insertion order
        for (int i = l.size(); i > 0; i--) {
            DJChart djChart = (DJChart) l.get(i - 1);
            JRDesignChart chart = createChart(djChart);

            //Charts has their own band, so they are added in the band at Y=0
            JRDesignBand band = createGroupForChartAndGetBand(djChart);
            band.addElement(chart);
        }
    }

    //Pre-sort charts by group column
    mmap = new MultiHashMap();
    for (Iterator iter = getReport().getNewCharts().iterator(); iter.hasNext();) {
        ar.com.fdvs.dj.domain.chart.DJChart djChart = (ar.com.fdvs.dj.domain.chart.DJChart) iter.next();
        mmap.put(djChart.getDataset().getColumnsGroup(), djChart);
    }

    for (Iterator iterator = mmap.keySet().iterator(); iterator.hasNext();) {
        Object key = iterator.next();
        Collection charts = (Collection) mmap.get(key);
        ArrayList l = new ArrayList(charts);
        //Reverse iteration of the charts to meet insertion order
        for (int i = l.size(); i > 0; i--) {
            ar.com.fdvs.dj.domain.chart.DJChart djChart = (ar.com.fdvs.dj.domain.chart.DJChart) l.get(i - 1);
            String name = "chart_" + (i - 1);
            JRDesignChart chart = createChart(djChart, name);

            if (djChart.getLink() != null)
                HyperLinkUtil.applyHyperLinkToElement((DynamicJasperDesign) getDesign(), djChart.getLink(),
                        chart, name + "_hyperlink");

            //Charts has their own band, so they are added in the band at Y=0
            JRDesignBand band = createGroupForChartAndGetBand(djChart);
            band.addElement(chart);
        }
    }
}

From source file:fr.in2p3.cc.storage.treqs.control.controller.QueuesController.java

/**
 * Do house cleaning on done queues. Iterate on the queues map and clean the
 * done queues./*www  .  j a v  a 2s  . c o  m*/
 * 
 * @return Quantity of done queues were cleaned.
 */
@SuppressWarnings("unchecked")
public int cleanDoneQueues() {
    LOGGER.trace("> cleanDoneQueues");

    int cleaned = 0;
    final MultiMap toRemove = new MultiValueMap();
    synchronized (this.queuesMap) {
        Iterator<String> iterName = this.queuesMap.keySet().iterator();
        // Checks the references to ended queues.
        while (iterName.hasNext()) {
            final String key = iterName.next();
            final Iterator<Queue> queues = ((Collection<Queue>) this.queuesMap.get(key)).iterator();
            while (queues.hasNext()) {
                final Queue queue = queues.next();

                if (queue.getStatus() == QueueStatus.ENDED) {
                    LOGGER.debug("Queue {} is ended. Cleanup starting.", key);
                    toRemove.put(key, queue);
                    cleaned++;
                } else {
                    LOGGER.debug("Queue {} is not ended.", key);
                }
            }
        }

        // Removes ended queues.
        iterName = toRemove.keySet().iterator();
        while (iterName.hasNext()) {
            final String key = iterName.next();

            final Iterator<Queue> queues = ((Collection<Queue>) toRemove.get(key)).iterator();
            while (queues.hasNext()) {
                final Queue queue = queues.next();

                LOGGER.debug("Deleting {} {}", key, queue.toString());
                this.queuesMap.remove(key, queue);

            }

        }
    }

    LOGGER.trace("< cleanDoneQueues");

    return cleaned;
}