code: 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;
      }
docs: Deeply compare two SortedMap instances.  This method walks the Maps in order,
  taking advantage of the fact that the Maps are SortedMaps.
  @param map1 SortedMap one
  @param map2 SortedMap two
  @param stack add items to compare to the Stack (Stack versus recursion)
  @param visited Set containing items that have already been compared, to prevent cycles.
  @return false if the Maps are for certain not equals.  'true' indicates that 'on the surface' the maps
  are equal, however, it will place the contents of the Maps on the stack for further comparisons.