You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

package.html 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <html>
  2. <body>
  3. This package implements a general tree comparison as a
  4. special case of visiting generic trees pairwise.
  5. Trees are wrapped as <code>GenericTreeNode</code>, which has a static
  6. method <code>boolean traverse(..)</code> which accepts
  7. a visitor and traverses a pair of trees, calling the
  8. visitor on each.
  9. <p>This package supports four forms of generality
  10. through the following classes:
  11. <table border="+1">
  12. <tr><th>Classes</th>
  13. <th>Capability</th></tr>
  14. <tr><td valign="top">GenericTreeNode</td>
  15. <td>Able to handle trees of varying types
  16. by wrapping in a generic form.<td>
  17. </tr>
  18. <tr><td valign="top">GenericTreeNodesVisitorI, GenericTreeNode.traverse(..)</td>
  19. <td>Can handle any type of pairwise visitor function
  20. by accepting visitor in the traverse method.</td>
  21. </tr>
  22. <tr><td valign="top">{java.util.Comparator}, GenericTreeNode.getComparator()</td>
  23. <td>The object comparison can be sensitive to the type
  24. of the object on a per-object basis, established during
  25. the process of wrapping the tree.</td>
  26. </tr>
  27. <tr><td valign="top">GenericTreeListOrdererI, GenericTreeListOrdererFactoryI</td>
  28. <td>The ordering of children can be appropriate to
  29. the objective of the traversal. e.g., when computing
  30. "set intersection" rather than "list equals", the
  31. order of children might be changed to align matching
  32. children for the visits.
  33. <br>This ordering can be determined as appropriate for each
  34. list comparison by implementing a factory which selects
  35. from the appropriate orderers. Any factory product is used
  36. by the traverse(..) method to order children before
  37. visiting.</td>
  38. <td></td>
  39. </tr>
  40. </table>
  41. <p><u>Supported variants</u>:
  42. The following variants are implemented or planned using the components above:
  43. <table border="1">
  44. <tr><th>Component</th><th>Description</th></tr>
  45. <tr><td colspan=2>Current</th></tr>
  46. <tr><td>GenericTreeNode.PRINTALL</td>
  47. <td>A visitor which prints out the entire tree.</td></tr>
  48. <tr><td>GenericTreeNode.PRINTERR</td>
  49. <td>A visitor which prints the nonmatching pairs.</td></tr>
  50. <tr><td>GenericTreeNode.EXACT</td>
  51. <td>A visitor which returns false if any pairs do not match.</td></tr>
  52. <tr><td>TreeCompare</td>
  53. <td>A sample program to read in serialized trees and compare them.
  54. (but see Structure in the compare subpackage for a better example) </td></tr>
  55. <tr><td>CompareUtil</td>
  56. <td>Misc comparison utilities (e.g., for short-circuiting comparisons).</td></tr>
  57. <tr><td colspan=2>Planned</th></tr>
  58. <tr><td>GenericTreeNode.KIDDIFF</td>
  59. <td>A visitor which calculates tree differences, using ordering children
  60. (catches swaps, missed or added elements, within children)</td></tr>
  61. <tr><td>GenericTreeNode.TREEDIFF</td>
  62. <td>A visitor which calculates tree differences, accumulating the tree
  63. (catches swaps, missed or added elements, throughout tree.)</td></tr>
  64. </table>
  65. <p><u>Use</u>:
  66. Run TreeCompare to use the comparer from the command line on a supported tree,
  67. (currently only the Swing TreeNode implemented as DefaultMutableTreeNode).
  68. <p><u>Programming</u>:<br>
  69. To support a new tree, see the Structure example in the compare subpackage
  70. or use example of the Swing TreeNode:
  71. <li>Write an adapter that uses GenericTreeNode to wrap your tree nodes</li>
  72. <li>Write a factory that produces a wrapped tree</li>
  73. <li>Write a Comparator that compares the underlying node object
  74. to include with each node object wrapped. Be sure to implement
  75. the Comparator.equals(Object) method correctly, i.e., returning
  76. true when it is equivalent to another comparator. It is best
  77. to use a singleton for each type of node you support. </li>
  78. <li>Optionally write a visitor to perform whatever operations you wish.
  79. Note that visitors must tolerate a single null input in order to
  80. completely traverse unmatching trees.</li>
  81. <li>To perform operations requiring preprocessing of child List's,
  82. write children orderer(s) and provide a factory to select them.</li>
  83. <p>To design new algorithms/applications, bear in mind the main tools:
  84. <li>The comparator that follows the node object</li>
  85. <li>The visitor that traverses the tree </li>
  86. <li>The child orderer that may preprocess the child lists </li>
  87. <br>In particular, when going beyond pair-wise comparisons to
  88. list-wise or tree-wise comparisons, you'll have to decide
  89. where to put the appropriate logic. You may have a relatively
  90. lightweight visitor and a heavyweight orderer, or no
  91. orderer at all. In that case, you may need to invoke a
  92. special method on your visitor after the traversal completes
  93. to do any final processing.
  94. <h2>Future Work</h2>:
  95. <p><u>Smarter group comparisons</u>:
  96. <br>Does calculating maps help with diagnosing problems?
  97. <pre>
  98. Given two lists,
  99. A [ a, b, c, d, e, f, g, h ]
  100. B [ a, e, c, d, b, g, h ]
  101. The result should say:
  102. - B swapped order of e and b
  103. - B omitted f
  104. Note the match-map (index of matching element, if any):
  105. A->B [ 0, 4, 2, 3, 1, -, 5, 6 ]
  106. B->A [ 0, 4, 2, 3, 1, 6, 7 ]
  107. the shift-map (difference between expected and actual order):
  108. A->B [ 0, 3, 0, 0, -3, -, -1, -1 ]
  109. B->A [ 0, 3, 0, 0, -3, 1, 1 ]
  110. Thus:
  111. - detect swaps as complementary out-of-index order pairs
  112. (todo: three-way or n-ary?)
  113. - fix or ignore swaps
  114. - detect shifts as complementary series
  115. where shift-width n is +/- for both
  116. - -n =>
  117. - if negative element is actual, n elements omitted
  118. - if negative element is expected, n elements added
  119. <pre>
  120. </body>
  121. </html>