1 25 38 package org.jgrapht.graph; 39 40 import java.util.*; 41 42 import org.jgrapht.*; 43 44 45 54 public class DefaultGraphMapping<V, E> 55 implements GraphMapping<V, E> 56 { 57 58 60 private Map<V, V> graphMappingForward; 61 private Map<V, V> graphMappingReverse; 62 63 private Graph<V, E> graph1; 64 private Graph<V, E> graph2; 65 66 68 78 public DefaultGraphMapping( 79 Map<V, V> g1ToG2, 80 Map<V, V> g2ToG1, 81 Graph<V, E> g1, 82 Graph<V, E> g2) 83 { 84 this.graph1 = g1; 85 this.graph2 = g2; 86 this.graphMappingForward = g1ToG2; 87 this.graphMappingReverse = g2ToG1; 88 } 89 90 92 public E getEdgeCorrespondence(E currEdge, boolean forward) 93 { 94 Graph<V, E> sourceGraph, targetGraph; 95 96 if (forward) { 97 sourceGraph = this.graph1; 98 targetGraph = this.graph2; 99 } else { 100 sourceGraph = this.graph2; 101 targetGraph = this.graph1; 102 } 103 104 V mappedSourceVertex = 105 getVertexCorrespondence( 106 sourceGraph.getEdgeSource(currEdge), 107 forward); 108 V mappedTargetVertex = 109 getVertexCorrespondence( 110 sourceGraph.getEdgeTarget(currEdge), 111 forward); 112 if ((mappedSourceVertex == null) || (mappedTargetVertex == null)) { 113 return null; 114 } else { 115 return targetGraph.getEdge( 116 mappedSourceVertex, 117 mappedTargetVertex); 118 } 119 } 120 121 public V getVertexCorrespondence( 122 V keyVertex, 123 boolean forward) 124 { 125 Map<V, V> graphMapping; 126 if (forward) { 127 graphMapping = graphMappingForward; 128 } else { 129 graphMapping = graphMappingReverse; 130 } 131 132 return graphMapping.get(keyVertex); 133 } 134 } 135 | Popular Tags |