001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU Lesser General Public License (LGPL): http://www.gnu.org/licenses/ 004 005 package graphlab.library; 006 007 import graphlab.library.exceptions.InvalidVertexException; 008 009 import java.util.ArrayList; 010 import java.util.Iterator; 011 012 /** 013 * I think this is enough for a path; 014 * 015 * @author Omid 016 * @param <VertexType> 017 */ 018 public class Path<VertexType extends BaseVertex> implements Iterable<VertexType> { 019 private ArrayList<BaseVertex> vertices = new ArrayList<BaseVertex>(); 020 021 public void insert(VertexType vertex) { 022 if (vertices.contains(vertex)) 023 throw new InvalidVertexException("Duplicate vertex in path"); 024 vertices.add(vertex); 025 } 026 027 public void insert(VertexType vertex, int position) { 028 if (vertices.contains(vertex)) 029 throw new InvalidVertexException("Duplicate vertex in path"); 030 vertices.add(position, vertex); 031 } 032 033 public Iterator<VertexType> iterator() { 034 Iterator<VertexType> iterator = (Iterator<VertexType>) vertices.iterator(); 035 return iterator; 036 } 037 038 public VertexType get(int i) { 039 return (VertexType) vertices.get(i); 040 } 041 042 public int size() { 043 return vertices.size(); 044 } 045 046 }