/Users/lyon/j4p/src/ip/martelli/EdgeElements.java

1    package ip.martelli; 
2     
3     
4    import ip.gui.EdgeElement; 
5     
6    import java.util.Vector; 
7     
8     
9    public class EdgeElements { 
10       private Vector edgeVector = new Vector(); 
11    
12       public void add(EdgeElement e) { 
13           edgeVector.addElement(e); 
14       } 
15    
16       public EdgeElement getElementAt(int i) { 
17           return (EdgeElement) edgeVector.elementAt(i); 
18       } 
19    
20       public int getSize() { 
21           return edgeVector.size(); 
22       } 
23    
24       public EdgeElement getMinOpenNode() { 
25           if (getSize() == 0) return null; 
26           int minCost = 1000000; 
27           EdgeElement lowCostEdgeElement = new EdgeElement(); 
28           lowCostEdgeElement.setOpen(true); 
29           lowCostEdgeElement.setCost(minCost); 
30           for (int i = 0; i < getSize(); i++) { 
31               EdgeElement el = getElementAt(i); 
32               if (!el.isOpen()) continue; 
33               if (el.getCost() > lowCostEdgeElement.getCost()) continue; 
34               lowCostEdgeElement = el; 
35           } 
36           if (lowCostEdgeElement.getCost() == minCost) return null; 
37           return lowCostEdgeElement; 
38       } 
39    
40       public static int countPath(EdgeElement pos) { 
41           int i = 0; 
42           while (pos != null) { 
43               i++; 
44               pos = pos.getParent(); 
45           } 
46           return i; 
47       } 
48    
49    
50   } 
51    
52    
53    
54