Changeset 6698


Ignore:
Timestamp:
10/26/15 14:02:22 (9 years ago)
Author:
teckart@informatik.uni-leipzig.de
Message:

Added new helper methods and more consistent handling of normalized vertex IDs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo-importer/src/main/java/eu/clarin/cmdi/vlo/importer/ResourceStructureGraph.java

    r6213 r6698  
    5353     */
    5454    public static void addResource(String mdSelfLink) {
    55         if (!vertexIdMap.containsKey(mdSelfLink)) {
    56             CmdiVertex newVertex = new CmdiVertex(StringUtils.normalizeIdString(mdSelfLink));
    57             vertexIdMap.put(mdSelfLink, newVertex);
    58         }
    59 
    60         if (!foundVerticesSet.contains(vertexIdMap.get(mdSelfLink))) {
    61             graph.addVertex(vertexIdMap.get(mdSelfLink));
    62             foundVerticesSet.add(vertexIdMap.get(mdSelfLink));
     55        String normalizedMdSelfLink = StringUtils.normalizeIdString(mdSelfLink);
     56        if (!vertexIdMap.containsKey(normalizedMdSelfLink)) {
     57            CmdiVertex newVertex = new CmdiVertex(normalizedMdSelfLink);
     58            vertexIdMap.put(normalizedMdSelfLink, newVertex);
     59        }
     60
     61        if (!foundVerticesSet.contains(vertexIdMap.get(normalizedMdSelfLink))) {
     62            graph.addVertex(vertexIdMap.get(normalizedMdSelfLink));
     63            foundVerticesSet.add(vertexIdMap.get(normalizedMdSelfLink));
    6364        } else {
    6465            LOG.debug("Duplicate resource vertex mdSelfLink: " + mdSelfLink);
     
    7374     */
    7475    public static void addEdge(String sourceVertexId, String targetVertexId) {
     76        String normalizedSourceVertexId = StringUtils.normalizeIdString(sourceVertexId);
     77        String normalizedTargetVertexId = StringUtils.normalizeIdString(targetVertexId);
     78       
    7579        // add vertices
    76         if (!vertexIdMap.containsKey(sourceVertexId)) {
    77             CmdiVertex sourceVertex = new CmdiVertex(StringUtils.normalizeIdString(sourceVertexId));
    78             vertexIdMap.put(sourceVertexId, sourceVertex);
     80        if (!vertexIdMap.containsKey(normalizedSourceVertexId)) {
     81            CmdiVertex sourceVertex = new CmdiVertex(normalizedSourceVertexId);
     82            vertexIdMap.put(normalizedSourceVertexId, sourceVertex);
    7983            graph.addVertex(sourceVertex);
    8084        }
    8185
    82         if (!vertexIdMap.containsKey(targetVertexId)) {
    83             CmdiVertex targetVertex = new CmdiVertex(StringUtils.normalizeIdString(targetVertexId));
    84             vertexIdMap.put(targetVertexId, targetVertex);
     86        if (!vertexIdMap.containsKey(normalizedTargetVertexId)) {
     87            CmdiVertex targetVertex = new CmdiVertex(normalizedTargetVertexId);
     88            vertexIdMap.put(normalizedTargetVertexId, targetVertex);
    8589            graph.addVertex(targetVertex);
    8690        }
     
    8892        // add edge
    8993        try {
    90             graph.addEdge(vertexIdMap.get(sourceVertexId), vertexIdMap.get(targetVertexId));
    91             updateDepthValues(vertexIdMap.get(sourceVertexId), new HashSet<CmdiVertex>());
     94            graph.addEdge(vertexIdMap.get(normalizedSourceVertexId), vertexIdMap.get(normalizedTargetVertexId));
     95            updateDepthValues(vertexIdMap.get(normalizedSourceVertexId), new HashSet<CmdiVertex>());
    9296        } catch (IllegalArgumentException cfe) {
    9397            // was a cycle -> ignore
     
    162166        return foundVerticesSet;
    163167    }
     168   
     169    public static CmdiVertex getVertex(String vertexId) {
     170        return vertexIdMap.get(vertexId);       
     171    }
     172   
     173    public static Map<String, CmdiVertex> getVertexIdMap() {
     174        return vertexIdMap;
     175    }
    164176
    165177    /**
    166178     * Get all vertices that are source of an edge where targetVertex is target.
    167      * In other words get all vertices that are part of targetVertex.
     179     * In other words get all resource vertices that are part of resource targetVertex.
    168180     *
    169181     * @param targetVertex
     
    187199    /**
    188200     * Get all vertices that are target of an edge where sourceVertex is source.
    189      * In other words get all vertices of which sourceVertex is part of.
     201     * In other words get all resource vertices of which resource sourceVertex is part of.
    190202     *
    191203     * @param sourceVertex
     
    273285    private final String id;
    274286    private int hierarchyWeight = 0;
     287    private boolean wasImported = false;
    275288
    276289    public CmdiVertex(String id) {
     
    288301    public int getHierarchyWeight() {
    289302        return hierarchyWeight;
     303    }
     304   
     305    public void setWasImported(boolean wasImported) {
     306        this.wasImported = wasImported;
     307    }
     308   
     309    public boolean getWasImported() {
     310        return wasImported;
    290311    }
    291312
Note: See TracChangeset for help on using the changeset viewer.