View Javadoc

1   package cz.cuni.amis.utils.astar;
2   
3   import java.util.Iterator;
4   
5   /**
6    * Clasical iterator for AStarHeap.
7    */
8   public class AStarHeapIterator<NODE> implements Iterator {
9   	
10  	private NODE[] nodes;
11  	private int items;
12  	private int current;
13  	private AStarHeap heap;
14  	
15  	public AStarHeapIterator(NODE[] myNodes, int myItems, AStarHeap<NODE> myHeap){
16  		nodes = myNodes;
17  		items = myItems;
18  		current = 0;
19  		heap = myHeap;
20  	}
21  
22  	public boolean hasNext() {
23  		return (current < items);		
24  	}
25  
26  	public Object next() {
27  		if (current < items){
28  			return nodes[current++];
29  		} else {
30  			return null;
31  		}		
32  	}
33  
34  	public void remove() {
35  		if (current == 0) 
36  			return;
37  		heap.remove(nodes[current-1]);
38  		current = current - 1;
39  		items = items - 1;
40  	}
41  
42  }