private static boolean compareOrderedCollection ( Collection col1 , Collection col2 , Deque stack , Set visited ) { // Same instance check already performed... if ( col1 . size ( ) != col2 . size ( ) ) { return false ; } Iterator i1 = col1 . iterator ( ) ; Iterator i2 = col2 . iterator ( ) ; while ( i1 . hasNext ( ) ) { DualKey dk = new DualKey ( i1 . next ( ) , i2 . next ( ) ) ; if ( ! visited . contains ( dk ) ) { // push contents for further comparison stack . addFirst ( dk ) ; } } return true ; }
Deeply compare two Collections that must be same length and in same order .