/* * Created on 09/06/2003 */ package graph; import java.util.Vector; /** * @author André Santanchè */ public class Graph { Vector v; public Graph() { this(null); } public Graph(Vertex vertexList[]) { if (vertexList == null) v = new Vector(); else { v = new Vector(vertexList.length); for (int i = 0; i < vertexList.length; i++) v.addElement(vertexList[i]); } } public void addVertex(Vertex vert) { v.addElement(vert); } public void setVertex(Vertex vert, int index) { if (index <= v.size()) v.setElementAt(vert, index); } public Vertex getVertex(int index) { if (index >= v.size()) return null; else return (Vertex)v.elementAt(index); } public Vertex[] getVertexList() { return (Vertex[]) v.toArray(new Vertex[0]); } public int getMaximumWeight() { int mw = 0; Vertex vl[] = (Vertex[]) v.toArray(new Vertex[0]); for (int i = 0; i < vl.length; i++) { Edge el[] = vl[i].getEdges(); if (el != null && el.length > 0) for (int j = 0; j < el.length; j++) if (el[j].getWeight() > mw) mw = el[j].getWeight(); } return mw; } }