/* * Copyright 2009 Wishnu Prasetya. * * You can redistribute and/or modify this class 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. */ package Sequenic.Graph; import java.util.* ; /** * Providing utility-methods to do something with paths. A path * is assumed to be represented by a list of vertices. * * @author Wishnu Prasetya */ public class PathUtil { static public boolean isPath(List path) { if (path==null) return false ; Iterator iter = path.iterator() ; Vertex prev, next; if(iter.hasNext()) { //path has at least 1 element next = iter.next(); while (iter.hasNext()) { //path has at least 2 elements, so check if they are connected prev = next; next = iter.next() ; if (!prev.isChild(next)) return false ; } } return true ; } static public String pathSimpleShow(List path) { if (path == null || path.isEmpty()) return "[]" ; StringBuffer res = new StringBuffer() ; String s = "[ "; for(Object o : path){ res.append(s).append(o.toString()); s = ", "; } return res.append(" ]").toString() ; } static public List readlist(String s) { StringTokenizer tokz = new StringTokenizer(s,"[], ") ; List t = new LinkedList() ; while (tokz.hasMoreTokens()) { t.add(Integer.parseInt(tokz.nextToken())) ; } return t ; } static public void main(String[] args){ System.out.println("" + readlist("[1, 2 4")) ; } }