/* * 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 ; int N = path.size() ; if (N <= 1) return true ; Iterator iter = path.iterator() ; Vertex prev = (Vertex) iter.next() ; Vertex u ; while (iter.hasNext()) { u = (Vertex) iter.next() ; if (! prev.children.contains(u)) return false ; prev = u ; } return true ; } static public String pathSimpleShow(List path) { if (path == null || path.isEmpty()) return "[]" ; StringBuffer res = new StringBuffer("[ " + path.get(0)) ; int N = path.size() ; for (int i=1; i 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")) ; } }