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 Cycle<VertexType extends BaseVertex> implements Iterable { 019 private ArrayList<VertexType> vertices; 020 021 public void insert(VertexType vertex) { 022 if (vertices.contains(vertex)) 023 throw new InvalidVertexException("Duplicate vertex in cycle"); 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 cycle"); 030 vertices.add(position, vertex); 031 } 032 033 public Iterator iterator() { 034 return vertices.iterator(); 035 } 036 037 public VertexType get(int i) { 038 return vertices.get(i); 039 } 040 041 public int size() { 042 return vertices.size(); 043 } 044 045 }