/* * Copyright 2008 Wishnu Prasetya. * * This file is part of T2. * T2 is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License (GPL) as published by the * Free Software Foundation; either version 3 of the License, or any * later version. * * T2 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. * * A copy of the GNU General Public License can be found in T2 distribution. * If it is missing, see http://www.gnu.org/licenses. */ package t2ext.bcel.utils; import java.util.ArrayList; import java.util.List; /** * @author Maaike Gerritsen */ public class SimplePath { public static final int NotFinished = 0; public static final int Cycle = 1; public static final int Finished = 2; private int _state; private int _endId; private List _pathList; public SimplePath(int endId){ _state = NotFinished; _pathList = new ArrayList(); _endId = endId; } public void addToList(int id, Node node){ if(id==_endId || (node.getChildLeft()==null && node.getChildRight()==null)){ _pathList.add(id); setState(Finished); } else if(_pathList.size()>0 && id==_pathList.get(0).intValue()){ _pathList.add(id); setState(Cycle); } else if(_pathList.contains(id)){ setState(Finished); } else _pathList.add(id); } public void setList(List list){ _pathList = new ArrayList(list); } public List getList(){ return _pathList; } public int getState(){ return _state; } private void setState(int state){ _state = state; } }