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 Summary
Modifier and Type Method Description static Optional<PathElements>findForFilePaths(Iterable<Path> pathsToFiles)Finds the common (left-most) elements amongPaths.static Optional<PathElements>findForFilePaths(Iterable<Path> pathsToFiles, CasedStringComparer comparer)Finds the common (left-most) elements amongPaths, with a customizable means via aCasedStringComparerfor comparing strings.static Optional<PathElements>findForFilePaths(Iterable<Path> pathsToFiles, IOCase ioCase)Finds the common (left-most) elements amongPaths, with a customizable means via anIOCasefor comparing strings.
-
Method Details
-
findForFilePaths
Finds the common (left-most) elements amongPaths.- Parameters:
pathsToFiles- paths to files- Returns:
- the common path-elements among all of
pathsToFiles, if any common elements exist. - Throws:
IllegalArgumentException- ifpathsToFilesis empty.
-
findForFilePaths
Finds the common (left-most) elements amongPaths, with a customizable means via anIOCasefor comparing strings.- Parameters:
pathsToFiles- paths to filesioCase- 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- ifpathsToFilesis empty.
-
findForFilePaths
public static Optional<PathElements> findForFilePaths(Iterable<Path> pathsToFiles, CasedStringComparer comparer)Finds the common (left-most) elements amongPaths, with a customizable means via aCasedStringComparerfor 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
PathElementsis 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 filescomparer- 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- ifpathsToFilesis empty.
-