public class WildcardPattern extends Object
Java Regular Expressions
.
To increase performance it holds an internal cache of all processed patterns.
Following rules are applied:
Some examples of patterns:
org/T?st.java
- matches org/Test.java
and also org/Tost.java
org/*.java
- matches all .java
files in the org
directory,
e.g. org/Foo.java
or org/Bar.java
org/**
- matches all files underneath the org
directory,
e.g. org/Foo.java
or org/foo/bar.jsp
org/**/Test.java
- matches all Test.java
files underneath the org
directory,
e.g. org/Test.java
or org/foo/Test.java
or org/foo/bar/Test.java
org/**/*.java
- matches all .java
files underneath the org
directory,
e.g. org/Foo.java
or org/foo/Bar.java
or org/foo/bar/Baz.java
Another implementation, which is also based on Java Regular Expressions, can be found in FileUtil from IntelliJ OpenAPI.
Modifier | Constructor and Description |
---|---|
protected |
WildcardPattern(String pattern,
String directorySeparator) |
Modifier and Type | Method and Description |
---|---|
static WildcardPattern |
create(String pattern)
Creates pattern with "/" as a directory separator.
|
static WildcardPattern[] |
create(String[] patterns)
Creates array of patterns with "/" as a directory separator.
|
static WildcardPattern |
create(String pattern,
String directorySeparator)
Creates pattern with specified separator for directories.
|
boolean |
match(String value)
Returns true if specified value matches this pattern.
|
static boolean |
match(WildcardPattern[] patterns,
String value)
Returns true if specified value matches one of specified patterns.
|
String |
toString()
Returns string representation of this pattern.
|
protected WildcardPattern(String pattern, String directorySeparator)
public static boolean match(WildcardPattern[] patterns, String value)
public static WildcardPattern create(String pattern)
create(String, String)
public static WildcardPattern[] create(String[] patterns)
create(String, String)
public static WildcardPattern create(String pattern, String directorySeparator)
This is used to match Java-classes, i.e. org.foo.Bar
against org/**
.
However usage of character other than "/" as a directory separator is misleading and should be avoided,
so method create(String)
is preferred over this one.
Also note that no matter whether forward or backward slashes were used in the antPattern
the returned pattern will use directorySeparator
.
Thus to match Windows-style path "dir\file.ext" against pattern "dir/file.ext" normalization should be performed.
Copyright © 2009–2015 SonarSource. All rights reserved.