public class Path extends Object implements Comparable<Path>
Modifier and Type | Field and Description |
---|---|
static String |
GLOB_PREFIX
The prefix to be used for glob patterns
|
Constructor and Description |
---|
Path(String path)
Create a new path object either from a concrete path or from a glob pattern.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Path o) |
boolean |
equals(Object obj) |
String |
getPath()
Return the path if this
Path object holds a path,
returns the pattern otherwise. |
int |
hashCode() |
boolean |
isPattern()
Returns {code true} if this
Path object is holding a pattern |
boolean |
matches(String otherPath)
If this
Path object holds a path (and not a pattern), this method
checks whether the provided path is equal to this path or a sub path of it. |
String |
toString() |
public static final String GLOB_PREFIX
public Path(@Nonnull String path)
Create a new path object either from a concrete path or from a glob pattern.
A glob pattern must start with the glob:
prefix (e.g. glob:**/*.html
). The following rules are used
to interpret glob patterns:
*
character matches zero or more characters of a name component without crossing directory boundaries.**
characters match zero or more characters crossing directory boundaries.path
- The resource path or a glob pattern.NullPointerException
- If otherPath
is null
IllegalArgumentException
- If the provided path is not absolute, or if the glob pattern does not start with a slash.public boolean matches(String otherPath)
Path
object holds a path (and not a pattern), this method
checks whether the provided path is equal to this path or a sub path of it.
If a glob pattern is provided as the argument, it performs the same check
and respects the provided pattern. This means it returns true
if this
path is a parent to any potential path matching the provided pattern. For
example if this path is /apps/foo
and the provided pattern is
glob:/apps/foo/bar/*.jsp
this method will return true. Same if
the provided pattern is glob:/apps/**/hello.html
.
If this Path
object holds a pattern, it checks whether the
provided path matches the pattern. If this path object holds a pattern
and a pattern is provided as the argument, it returns only true
if the pattern is the same.
If the provided argument is not an absolute path (e.g. if it is a relative
path or a pattern), this method returns false
.otherPath
- Absolute path to check.true
If other path is within the sub tree of this path
or matches the pattern.NullPointerException
- If otherPath
is null
IllegalArgumentException
- If the provided path is not absolute, or if the glob pattern does not start with a slash.isPattern()
public String getPath()
Path
object holds a path,
returns the pattern otherwise.isPattern()
public boolean isPattern()
Path
object is holding a patternfalse
for a path.public int compareTo(@Nonnull Path o)
compareTo
in interface Comparable<Path>
Copyright © 2017 The Apache Software Foundation. All rights reserved.