edu.ucsb.nceas.metacat

## Class NodeComparator

- java.lang.Object
- - edu.ucsb.nceas.metacat.NodeComparator

- All Implemented Interfaces:
    java.util.Comparator

      public class NodeComparator
      extends java.lang.Object
      implements java.util.Comparator

  A utility class that sorts two node records.

  The order of the records determines how the XML document is printed from DocumentImpl.toXml(), so it is important that the sort order specified here results in a depth first traversal of the nodes in tree. Currently, the nodes are inserted into the database in this depth-forst order, so the nodeid identifiers are a good indicator of the proper sort order.

  However, if we modify data loading semantics to allow document nodes to be rearranged, or otherwise change the nodeindex value, this current sort algorithm will fail to work.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `NodeComparator()` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compare(NodeRecord o1, NodeRecord o2)` compare two NodeRecord objects to determine proper sort order.
    `int` | `compare(java.lang.Object o1, java.lang.Object o2)` compare two objects to determine proper sort order -- delegates to the compare(NodeRecord, NodeRecord) method.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface java.util.Comparator

      `comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong`

- - ### Constructor Detail

    - #### NodeComparator

          public NodeComparator()

      Constructor

  - ### Method Detail

    - #### compare

          public int compare(java.lang.Object o1,
                             java.lang.Object o2)

      compare two objects to determine proper sort order -- delegates to the compare(NodeRecord, NodeRecord) method.
      Specified by:
        `compare` in interface `java.util.Comparator`

    - #### compare

          public int compare(NodeRecord o1,
                             NodeRecord o2)

      compare two NodeRecord objects to determine proper sort order. The node records are equal if their nodeid fields are equal. One is less than another if its parentnodeid is less, or if its parentnodeid is equal and its nodeindex is less. One is greater than another if its parentnodeid is greater, or if its parentnodeid is equal and its nodeindex is greater.

Copyright © 2020 Regents of the University of California. All Rights Reserved.