Class PathUtils.PathComparator

  • All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator<java.lang.String>
    Enclosing class:
    PathUtils

    public static class PathUtils.PathComparator
    extends java.lang.Object
    implements java.util.Comparator<java.lang.String>, java.io.Serializable
    Comparator for normalized paths.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static char PATH_SEPARATOR
      The separator character for normalized paths.
    • Constructor Summary

      Constructors 
      Constructor Description
      PathComparator()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(java.lang.String o1, java.lang.String o2)
      Compare two relative paths.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • PATH_SEPARATOR

        public static final char PATH_SEPARATOR
        The separator character for normalized paths. ('/').
        See Also:
        Constant Field Values
    • Constructor Detail

      • PathComparator

        public PathComparator()
    • Method Detail

      • compare

        public int compare​(java.lang.String o1,
                           java.lang.String o2)
        Compare two relative paths. Take into account the presence of path separator characters. That is, the path are compared lists of path segments. The result will be one of CMP_LT, #CMP_EQ, CMP_GT, or, an integer value which measures the difference between the two path (subtracting the second value from the first), with the sign of the difference indicating the comparison result. In effect: Math.signum(compare(path1, path2)) == Math.signum(path1 - path2) "In effect", because an actual difference between two path values is not defined. This implementation answers the difference between the first characters which do not match, or the differences between the path lengths if all characters of the shorter path match characters of the longer path, or CMP_LT or CMP_GT if slashes are not in the same positions in both paths. For example, "parent/child" is compared as \{ "parent", "child" \}. Then, "parent/child" is less than "parentAlt/child", because "parent" is less than "parentAlt".
        Specified by:
        compare in interface java.util.Comparator<java.lang.String>
        Parameters:
        path1 - The first relative path which is to be compared. An exception will result if the path is null.
        path2 - The second second path which is to be compared. An exception will result if the path is null.
        Returns:
        A integer value which corresponds to the comparison result. A value less than zero indicates that the first path is less than the second path. A value greater than zero indicates that first path is greater than the second. A value of zero indicates that the two paths are equal.