public GraphType transpose(GraphType orig,GraphToolkit<GraphType,EdgeType,VertexType> toolkit){
  GraphType trans=toolkit.createGraph();
  for (Iterator<VertexType> i=orig.vertexIterator(); i.hasNext(); ) {
    VertexType v=i.next();
    VertexType dupVertex=toolkit.duplicateVertex(v);
    dupVertex.setLabel(v.getLabel());
    trans.addVertex(v);
    m_origToTransposeMap.put(v,dupVertex);
    m_transposeToOrigMap.put(dupVertex,v);
  }
  trans.setNumVertexLabels(orig.getNumVertexLabels());
  for (Iterator<EdgeType> i=orig.edgeIterator(); i.hasNext(); ) {
    EdgeType e=i.next();
    VertexType transSource=m_origToTransposeMap.get(e.getTarget());
    VertexType transTarget=m_origToTransposeMap.get(e.getSource());
    EdgeType dupEdge=trans.createEdge(transSource,transTarget);
    dupEdge.setLabel(e.getLabel());
    toolkit.copyEdge(e,dupEdge);
  }
  trans.setNumEdgeLabels(orig.getNumEdgeLabels());
  return trans;
}

public GraphType transpose ( GraphType orig , GraphToolkit < GraphType , EdgeType , VertexType > toolkit ) { GraphType trans = toolkit . createGraph ( ) ; for ( Iterator < VertexType > i = orig . vertexIterator ( ) ; i . hasNext ( ) ; ) { VertexType v = i . next ( ) ; VertexType dupVertex = toolkit . duplicateVertex ( v ) ; dupVertex . setLabel ( v . getLabel ( ) ) ; trans . addVertex ( v ) ; m_origToTransposeMap . put ( v , dupVertex ) ; m_transposeToOrigMap . put ( dupVertex , v ) ; } trans . setNumVertexLabels ( orig . getNumVertexLabels ( ) ) ; for ( Iterator < EdgeType > i = orig . edgeIterator ( ) ; i . hasNext ( ) ; ) { EdgeType e = i . next ( ) ; VertexType transSource = m_origToTransposeMap . get ( e . getTarget ( ) ) ; VertexType transTarget = m_origToTransposeMap . get ( e . getSource ( ) ) ; EdgeType dupEdge = trans . createEdge ( transSource , transTarget ) ; dupEdge . setLabel ( e . getLabel ( ) ) ; toolkit . copyEdge ( e , dupEdge ) ; } trans . setNumEdgeLabels ( orig . getNumEdgeLabels ( ) ) ; return trans ; }
transpose a graph . note that the original graph is not modified ; the new graph and its vertices and edges are new objects .
