Class FindCommonPathElements

Object
com.owenfeehan.pathpatternfinder.commonpath.FindCommonPathElements

public class FindCommonPathElements
extends Object
Finds common (left-most) elements among Paths.

Elements are common if they are present (from left to right) among all paths.

The root of the path (e.g. c:\) is treated as an element, if it is present.

Author:
Owen Feehan
  • Method Details

    • findForFilePaths

      public static Optional<PathElements> findForFilePaths​(Iterable<Path> pathsToFiles)
      Finds the common (left-most) elements among Paths.
      Parameters:
      pathsToFiles - paths to files
      Returns:
      the common path-elements among all of pathsToFiles, if any common elements exist.
      Throws:
      IllegalArgumentException - if pathsToFiles is empty.
    • findForFilePaths

      public static Optional<PathElements> findForFilePaths​(Iterable<Path> pathsToFiles, IOCase ioCase)
      Finds the common (left-most) elements among Paths, with a customizable means via an IOCase for comparing strings.
      Parameters:
      pathsToFiles - paths to files
      ioCase - whether to be case-sensitive or not in comparisons.
      Returns:
      the common path-elements among all of pathsToFiles, if any common elements exist.
      Throws:
      IllegalArgumentException - if pathsToFiles is empty.
    • findForFilePaths

      public static Optional<PathElements> findForFilePaths​(Iterable<Path> pathsToFiles, CasedStringComparer comparer)
      Finds the common (left-most) elements among Paths, with a customizable means via a CasedStringComparer for comparing strings.

      If all are absolute paths, Optional.empty() is returned if there are no common elements.

      If all are relative paths, an empty collection of PathElements is returned if there are no common elements.

      If a mix of absolute paths and relative paths occur, Optional.empty() is returned if there are no common elements.

      Parameters:
      pathsToFiles - paths to files
      comparer - how to compare two strings (whether to be case-sensitive or not).
      Returns:
      the common path-elements among all of pathsToFiles, if any common elements exist.
      Throws:
      IllegalArgumentException - if pathsToFiles is empty.