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 General Public License (GPL): http://www.gnu.org/licenses/ 004 package graphlab.plugins.visualization.corebasics.basics; 005 006 import graphlab.graph.graph.VertexModel; 007 008 import java.util.ArrayList; 009 010 /** 011 * @author Rouzbeh Ebrahimi 012 */ 013 public class Cycle { 014 ArrayList<VertexModel> cycleVertices; 015 boolean isCycleEnded; 016 017 public Cycle(ArrayList<VertexModel> cycleVertices) { 018 int cycleSize = cycleVertices.size(); 019 if (cycleVertices.get(0).equals(cycleVertices.get(cycleSize))) { 020 this.cycleVertices = cycleVertices; 021 isCycleEnded = true; 022 } 023 } 024 025 public Cycle() { 026 cycleVertices = new ArrayList<VertexModel>(); 027 isCycleEnded = false; 028 } 029 030 public void add(VertexModel v) { 031 this.cycleVertices.add(v); 032 } 033 034 public boolean endCycle(VertexModel v) { 035 if (this.cycleVertices.get(0).equals(v)) { 036 this.cycleVertices.add(v); 037 isCycleEnded = true; 038 return true; 039 } else { 040 return false; 041 } 042 } 043 044 public ArrayList<VertexModel> getCycle() { 045 if (isCycleEnded) return this.cycleVertices; 046 else return null; 047 } 048 } 049