java - FIFO tie breaker in Comparator? -


for homework, need compare nodes based on heuristic can put them in treeset. however, when heuristic values 2 nodes equal need way break tie.

i'm not allowed modify node class provided , far can tell there aren't other values / properties of node me break tie i'm not using. (we're dealing puzzles, not matters.) there way break ties based on when added them treeset? don't know how go it....

i saw example in documentation priority blocking queue want use comparator interface, , can't work.

thanks in advance; tips / hints appreciated.

are allowed create wrapper nodes?

public class nodewrapper implements comparable<nodewrapper> {   private static atomiclong serialnumgenerator = new atomiclong(0l);    private final node node;   private final long serialnum;    public nodewrapper(node node) {     this.node = node;     this.serialnum = serialnumgenerator.getandincrement();   }    @override   public int compareto(nodewrapper other) {     int compare = this.node.compareto(other.node);     if (compare == 0) {       compare = (this.serialnum < other.serialnum)           ? -1           : ((this.serialnum > other.serialnum) ? 1 : 0);     }     return compare;   }   // implement other methods including equals() , hashcode() } 

Comments

Popular posts from this blog

How can I edit my VIM config so that Vim treats ".ejs" files the same as it currently treats my html files? -

Python __call__ special method practical example -