/* * Copyright (C) 2010-2013 JPEXS * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package com.jpexs.asdec.abc.avm2.flowgraph; import com.jpexs.asdec.abc.avm2.treemodel.ContinueTreeItem; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; /** * * @author JPEXS */ public class GraphPart { public int start = 0; public int end = 0; public int instanceCount = 0; public List nextParts = new ArrayList(); public int posX = -1; public int posY = -1; public String path=""; public List refs=new ArrayList(); public boolean ignored=false; public List forContinues=new ArrayList(); private boolean leadsTo(GraphPart part,List visited,List ignored){ if(visited.contains(this)){ return false; } if(ignored.contains(this)){ return false; } visited.add(this); for(GraphPart p:nextParts){ if(p==part){ return true; }else{ if(p.leadsTo(part,visited,ignored)){ return true; } } } return false; } public boolean leadsTo(GraphPart part,List ignored){ return leadsTo(part,new ArrayList(),ignored); } public GraphPart(int start, int end) { this.start = start; this.end = end; } private GraphPart getNextPartPath(GraphPart original,String path,List visited){ if(visited.contains(this)){ return null; } visited.add(this); for(GraphPart p:nextParts){ if(p==original){ continue; } if(p.path.equals(path)){ return p; }else if(p.path.length()>=path.length()){ GraphPart gp=p.getNextPartPath(original,path,visited); if(gp!=null){ return gp; } } } return null; } public GraphPart getNextPartPath(List ignored){ List visited=new ArrayList(); visited.addAll(ignored); return getNextPartPath(this,path,visited); } @Override public String toString() { if (end < start) { return "<-> "+(start+1)+"-"+(end+1); } return "" + (start + 1) + "-" + (end + 1) + (instanceCount > 1 ? "(" + instanceCount + " links)" : "")+" p"+path; } public boolean containsIP(int ip) { return (ip >= start) && (ip <= end); } private boolean containsPart(GraphPart part, GraphPart what, List used) { if (used.contains(part)) { return false; } used.add(part); for (GraphPart subpart : part.nextParts) { if (subpart == what) { return true; } if (containsPart(subpart, what, used)) { return true; } } return false; } public int getHeight(){ return end-start+1; } public boolean containsPart(GraphPart what) { return containsPart(this, what, new ArrayList()); } }