private static boolean compareSortedMap ( SortedMap map1 , SortedMap map2 , Deque stack , Set visited ) { // Same instance check already performed... if ( map1 . size ( ) != map2 . size ( ) ) { return false ; } Iterator i1 = map1 . entrySet ( ) . iterator ( ) ; Iterator i2 = map2 . entrySet ( ) . iterator ( ) ; while ( i1 . hasNext ( ) ) { Map . Entry entry1 = ( Map . Entry ) i1 . next ( ) ; Map . Entry entry2 = ( Map . Entry ) i2 . next ( ) ; // Must split the Key and Value so that Map.Entry's equals() method is not used. DualKey dk = new DualKey ( entry1 . getKey ( ) , entry2 . getKey ( ) ) ; if ( ! visited . contains ( dk ) ) { // Push Keys for further comparison stack . addFirst ( dk ) ; } dk = new DualKey ( entry1 . getValue ( ) , entry2 . getValue ( ) ) ; if ( ! visited . contains ( dk ) ) { // Push values for further comparison stack . addFirst ( dk ) ; } } return true ; }
Deeply compare two SortedMap instances . This method walks the Maps in order taking advantage of the fact that the Maps are SortedMaps .