Package com.github.robtimus.filesystems
Class PathMatcherSupport
- java.lang.Object
-
- com.github.robtimus.filesystems.PathMatcherSupport
-
public final class PathMatcherSupport extends Object
A utility class that can assist in implementingPathMatcher
s.- Author:
- Rob Spoor
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Pattern
toGlobPattern(String glob)
Converts the given glob into aPattern
.static Pattern
toGlobPattern(String glob, int flags)
Converts the given glob into aPattern
.static Pattern
toPattern(String syntaxAndPattern)
Creates aPattern
for the given syntax and pattern combination.
-
-
-
Method Detail
-
toPattern
public static Pattern toPattern(String syntaxAndPattern)
Creates aPattern
for the given syntax and pattern combination. This follows the rules ofFileSystem.getPathMatcher(String)
.This method supports two syntaxes:
glob
andregex
. If the syntax isglob
, this method delegates totoGlobPattern(String)
. Otherwise it will callPattern.compile(String)
.- Parameters:
syntaxAndPattern
- The syntax and pattern.- Returns:
- A
Pattern
based on the given syntax and pattern. - Throws:
IllegalArgumentException
- If the parameter does not take the formsyntax:pattern
.PatternSyntaxException
- If the pattern is invalid.UnsupportedOperationException
- If the pattern syntax is notglob
orregex
.
-
toGlobPattern
public static Pattern toGlobPattern(String glob)
Converts the given glob into aPattern
.Note that this method uses a single forward slash (
/
) as path separator.- Parameters:
glob
- The glob to convert.- Returns:
- A
Pattern
built from the given glob. - Throws:
PatternSyntaxException
- If the given glob is invalid.- See Also:
FileSystem.getPathMatcher(String)
-
toGlobPattern
public static Pattern toGlobPattern(String glob, int flags)
Converts the given glob into aPattern
.Note that this method uses a single forward slash (
/
) as path separator.- Parameters:
glob
- The glob to convert.flags
-Match flags
for thePattern
.- Returns:
- A
Pattern
built from the given glob. - Throws:
PatternSyntaxException
- If the given glob is invalid.IllegalArgumentException
- If the match flags are invalid.- See Also:
FileSystem.getPathMatcher(String)
-
-