View Javadoc

1   package cz.cuni.amis.utils.astar;
2   
3   import java.util.Comparator;
4   import java.util.Map;
5   
6   /**
7    * This comparator is a tricky object - it serves for the {@link AStarHeap} to compare nodes inside the heap.
8    * <p><p>
9    * The trick is, that it is initialized {@link AStarHeapComparator#AStarHeapComparator(Map)} with a map
10   * that contains node's costs that are used during the comparation inside {@link AStarHeapComparator#compare(Object, Object)}.
11   * No magic yet, ha? Well, the magic is that this map is not cloned... simply a pointer to this very instance passed
12   * inside the constructor is saved to you may alter the cost as you wish to! Which is truly needed by the {@link AStar} class
13   * that is obtaining nodes' costs from the {@link AStarMap} implementor.
14   * 
15   * @author Jimmy
16   *
17   * @param <NODE>
18   * 
19   * <p><p>
20   * Use amis-path-finding library instead, see svn://artemis.ms.mff.cuni.cz/pogamut/trunk/project/Utils/AmisPathFinding
21   */
22  @Deprecated
23  public class AStarHeapComparator<NODE> implements Comparator {
24  	
25  	private Map<NODE, Integer> values;
26  	
27  	public AStarHeapComparator(Map<NODE, Integer> estimatedCosts){
28  		values = estimatedCosts;
29  	}
30  
31  	public int compare(Object arg0, Object arg1) {
32  		return values.get(arg0).intValue() - values.get(arg1).intValue();
33  	}
34  
35  }