Class TreeHierarchyComparator<T>

  • Type Parameters:
    T - type of nodes in the tree-like hierarchy
    All Implemented Interfaces:
    java.util.Comparator<T>
    Direct Known Subclasses:
    ProjectComparator

    public abstract class TreeHierarchyComparator<T>
    extends java.lang.Object
    implements java.util.Comparator<T>
    Abstract comparator that takes into account tree-like hierarchy: - parents must precede children - ordering between nodes on the same depth is defined by compareOnSameDepth(Object, Object)
    Since:
    9.0
    Author:
    Dmitry.Treskunov
    • Method Detail

      • compare

        public int compare​(T o1,
                           T o2)
        Specified by:
        compare in interface java.util.Comparator<T>
      • onSamePath

        protected int onSamePath​(T left,
                                 T right)
      • isParent

        public boolean isParent​(@NotNull
                                T child,
                                @NotNull
                                T parent)
      • compareOnSameDepth

        protected abstract int compareOnSameDepth​(T o1,
                                                  T o2)
      • isRoot

        protected int isRoot​(T o1)