真心求教!gef编程读取有向流程图有分支时hashmap是否适用?如是,该如何读取下一个节点,如否,改用什么方法?流程图没有分支的时候是可以正常读取的流程图有分支的时候只能来到if,后面的没有读下去
贴上部分代码,如需更多信息请留言
ReceiveModel receive = null;
ReplyModel myReply = null;
HashMap<String,InvokeModel> invokeModelHashMap = new HashMap<String,InvokeModel>();
HashMap<String,AssignModel> assignModelHashMap = new HashMap<String,AssignModel>();
HashMap<String,ReplyModel> replyModelHashMap = new HashMap<String,ReplyModel>();
HashMap<String,IfModel> ifModelHashMap = new HashMap<String,IfModel>();
HashMap<String,ElseModel> elseModelHashMap = new HashMap<String,ElseModel>();
HashMap<String,EndElseModel> endElseModelHashMap = new HashMap<String,EndElseModel>();
HashMap<String,EndIfModel> endIfModelHashMap = new HashMap<String,EndIfModel>();
HashMap<String,WhileModel> whileModelHashMap = new HashMap<String,WhileModel>();
HashMap<String,EndWhileModel> endWhileModelHashMap = new HashMap<String,EndWhileModel>();
HashMap<String,NodeModel> nodesModelHashMap = new HashMap<String,NodeModel>();

Iterator<NodeModel> i = diagram.getNodes().iterator();
while(i.hasNext()){
NodeModel nodeModel = i.next();
if(nodeModel instanceof ReceiveModel){
            receive = (ReceiveModel)nodeModel;
}else if(nodeModel instanceof ReplyModel){
            myReply = (ReplyModel)nodeModel;
replyModelHashMap.put(nodeModel.getName(),(ReplyModel)nodeModel);
}else if(nodeModel instanceof InvokeModel){
            invokeModelHashMap.put(nodeModel.getName(),(InvokeModel)nodeModel);
}else if(nodeModel instanceof AssignModel){
            assignModelHashMap.put(nodeModel.getName(),(AssignModel)nodeModel);
}else if(nodeModel instanceof IfModel){
            ifModelHashMap.put(nodeModel.getName(),(IfModel)nodeModel);
}else if(nodeModel instanceof ElseModel){
            elseModelHashMap.put(nodeModel.getName(),(ElseModel)nodeModel);
}else if(nodeModel instanceof EndElseModel){
            endElseModelHashMap.put(nodeModel.getName(),(EndElseModel)nodeModel);
}else if(nodeModel instanceof WhileModel){
            whileModelHashMap.put(nodeModel.getName(),(WhileModel)nodeModel);
}else if(nodeModel instanceof EndWhileModel){
            endWhileModelHashMap.put(nodeModel.getName(),(EndWhileModel)nodeModel);
}else if(nodeModel instanceof EndIfModel){
            endIfModelHashMap.put(nodeModel.getName(),(EndIfModel)nodeModel);
}
nodesModelHashMap.put(nodeModel.getName(),nodeModel);
    } HashMap遍历Java

解决方案 »

  1.   

    同学 可以用LinkedHashMap 他可以找到下一个节点。
      

  2.   

    现在的具体问题是我想输出图中所有调用的输出数据类型,原方法是从流程图最后的返回开始利用getincomingconnection(输入连线)查找上一个图符的方法比对是不是调用这个图符,如果是
    就得到它的输出数据类型,如否就继续上一个。这个方法在没有分支的第一幅图那里没有报错,但
    在第二幅图有分支的情况下就报错了。我现在没有想到更好的办法来解决这个问题。请问有没有更
    好的建议?
      

  3.   

    适用,又不一定使用,取决于你怎么用。至少我没看懂你程序里面是怎么用的,看起来太复杂了假设节点只需要其节点名称的话,那么:
    Map<String 节点名称, List<String 节点名称>>寻找节点时,用广度优先遍历会更简单点。
      

  4.   

    多谢大家的建议和意见!我的问题已经解决了,其实hashmap的存储方式没有对错,只要所有的图符都能存进去,然后整个流程都是有固定的头(接收)和尾(返回),只要从头或尾,然后根据连线这条线索去迭代就可以。遇到分支的时候我的处理方式是加以判断,例如图二那里,我设置了if的判断条件去选择我下一个路径是调用还是否则,然后根据不同的情况再利用getOutgoingConnection这个方法得到下一个图符的名字,这样流程就可以正常的读取下去了。毕竟这个办法只是两个分支的情况,只是为了临时解决问题,目前还在研究中