public class FilepathFilterM extends java.lang.Object implements ToStringBuilder
[[src/**|result/**]/[~#*|~*#]|~_*]
src or result sub directory.
But from the root level the valid mask for files is ~_*, it means, excluding, should not start with "_".
For all deeper levels the files should not start or end with an #.
Hence all source files are gathered, but not commented files with #.
createWildcardFilter(String): operation to creates an instance of this class as filter, including sub instances for all sub paths.
check(String, boolean): operation to check a file or directory name with the current filter.
It returns the proper child filter to continue check in the child levels or the path. Use it in a loop or for... for the longer path.
filter::={ <filterElement> ? / }.
filterElement::= ** ## This means 'all tree', accepts all directory entries till the next matches.
| [ [~<?bNotBegin>] <*?sBegin> ] ## optional begin text, ~ if should not match
[ \[ { <filter?variantBegin> ? \| } \] ] ## [...|...] variants to begin optional, can contain ~ for exclude
[ * <*?sContain> * ] ## Between two '*' an inner String which should contain
[ * ## after asterisk check of end string
[ \[ { [~<?mNotEnd>] <*?variantEnd> ? \| } \] ] ## [...|...] variants to end optional
[ <*?sEnd> ] ## an end String optional.
] .
| Modifier and Type | Field and Description |
|---|---|
FilepathFilterM |
aFilterChild
This is the next part in the original path between /child/
|
boolean |
bAllTree
True if the filter path on ctor has contained "**".
|
boolean |
bLast |
(package private) boolean |
bNotBegin
up to 32 bit for negation of variants, bit 0 for first text etc.
|
private boolean |
bNoWildcard |
(package private) int |
mNotEnd
bit from 0 for each
variantsEnd whether it must match (0) or not (1). |
private java.lang.String |
sBegin |
private java.lang.String |
sContain |
private java.lang.String |
sEnd |
static java.lang.String |
sVersion
Version, history and license.
|
(package private) java.util.List<FilepathFilterM> |
variantsBegin
Variants either instead sBefore or instead sBehind.
|
(package private) java.util.List<java.lang.String> |
variantsEnd |
(package private) int |
zBegin |
(package private) int |
zContain |
(package private) int |
zEnd |
| Modifier | Constructor and Description |
|---|---|
protected |
FilepathFilterM(java.lang.String sMask,
boolean bLast,
FilepathFilterM filterChild)
Creates a FilepathFilterM for one level.
|
| Modifier and Type | Method and Description |
|---|---|
FilepathFilterM |
check(java.lang.String name,
boolean bDir)
Checks the given name against the current Level of this FilepathFilterM.
|
private FilepathFilterM |
checkRecursive(java.lang.String name,
boolean bDir,
int[] posEndBegin)
This is the essential check operation:
_A_ If
bAllTree is set, then this 'name' is tested with the aFilterChild. |
private FilepathFilterM |
checkVariants(java.lang.String name,
boolean bDir,
int[] posEndBegin,
int posStartEnd) |
private int |
checkVariantsEnd(java.lang.String name,
int zName) |
static FilepathFilterM |
createWildcardFilter(java.lang.String maskP)
Creates a FilepathFilterM with given mask.
|
private static FilepathFilterM |
createWildcardFilter(java.lang.String maskP,
FilepathFilterM filterChildP)
Creates
|
FilepathFilterM |
nextChild() |
private static void |
parseVariants(java.lang.String sPart,
int posBracket,
java.util.List<FilepathFilterM> list,
FilepathFilterM filterChild)
Variants are given in sPart in [...|...].
|
private static int |
parseVariantsEnd(java.lang.String sPart,
int posBracket,
java.util.List<java.lang.String> list)
Similar as
parseVariants(String, int, List, FilepathFilterM) but only for end. |
boolean |
selAllDirEntries()
Returns true if this filter selects all sub directories till end of tree.
|
boolean |
selAllEntries()
returns true if this filter will select all entries of this level.
|
boolean |
selAllFilesInDir()
returns true if this filter will select all files asked from a dir level.
|
java.lang.String |
toString() |
java.lang.StringBuilder |
toString(java.lang.StringBuilder app,
java.lang.String... cond)
This is a better version of a toString() concept for elaborately outputs.
|
boolean |
XXaccept(java.io.File dir,
java.lang.String name)
Checks whether the name matches due to this filter.
|
public static final java.lang.String sVersion
checkRecursive(String, boolean, int[]) if only sBegin is given, and bNoWildcard,
then the length of the input should be equal zBegin, or here tested, compare with 'posEnd' which is the length.
checkRecursive(String, boolean, int[]);
bugfix the last only file entry was used to accept a directory with this name.
Now test in checkRecursive(String, boolean, int[]) whether it is the last entry and not dir or vice versa,
but now only for the end of variants. Because variants may have not aFilterChild.
[~dirA*|~dirB]/*] this has not worked before.
selAllFilesInDir(), selAllDirEntries(). selAllEntries()
It is used for quest delete a directory entry, only if the first two conditions are met.
It checks the given mask.
check(String, boolean), test is done.
Adaption in application necessary (since 2 weeks...)
FilepathFilter with the multi selection.
The idea is old, it was present in the path as WildcardFilter in FileFunctions
but not used. Now it es tested, and used for the FileList.
public final FilepathFilterM aFilterChild
private final java.lang.String sBegin
private final java.lang.String sContain
private final java.lang.String sEnd
int zBegin
int zContain
int zEnd
public final boolean bAllTree
private final boolean bNoWildcard
public final boolean bLast
java.util.List<FilepathFilterM> variantsBegin
java.util.List<java.lang.String> variantsEnd
final boolean bNotBegin
int mNotEnd
variantsEnd whether it must match (0) or not (1).
See checkVariantsEnd(String, int).protected FilepathFilterM(java.lang.String sMask,
boolean bLast,
FilepathFilterM filterChild)
createWildcardFilter(String).
fix |
The filter accepts only this name |
begin* |
The filter accepts names starting with "begin" and "begin" itself.
Familiar example: "myfile.*", all files with this name and any extension. Or "myFile.c*" accepts also "myFile.cpp", but also for example "myFile.ci" if given. |
*end |
The filter accepts names ending with "end" and "end" itself. Familiar example: "*.cpp", all files with extension "cpp" |
begin*end |
The filter accepts names starting with "begin" and ending with end after before.
Familiar examples: "file*.cpp": All files starting with "file" with extension ".cpp" |
begin*mid*end |
The filter accepts names starting with "begin", ending with end after before
and containing "mid" between "begin" and "end".
Familiar examples: "file*.cpp": All files starting with "file" with extension ".cpp" |
begin*mid* |
The filter accepts names starting with "begin" and containing "mid" after "begin".
Familiar examples: "file*.c*": All files starting with "file" with extension ".c" but also ".cpp" This is a special case of begin*mid*end. |
*mid* |
The filter accepts names which contains "mid" but also only "mid".
Familiar examples: "*.c*": All fileswith extension ".c" but also ".cpp" This is a special case of begin*mid*end. |
* |
The filter accepts all names, returns always true. |
**
aFilterChild is used.
*)
** |
The filter accepts all names, returns always true. This stands for any deepness of a directory tree till the following child pattern does also match. It means the child pattern is tested. If it does match, it (and the following children) is used for further checking. If the child pattern does not match, matching is true and the child pattern is not used for this level. |
begin** |
The filter accepts names starting with "begin" and "begin" itself.
It the next level starts also with begin, it is preconditional. But nevertheless the next child level is checked. If it matches, it is used. |
begin**mid*end |
It is similar for all other wildcard variants.
Note: The "**" must be written on the first wildcard position. |
FilepathFilter.
Variants are written in [var1|var2] for positive variants
for the begin and end parts or as part of them between the wildcards.
[~var1|~var2] for negative variants.
Then not only one given string for begin and end are valid (matching)
but either one of the possible, or all Strings exclusively the given. Look on examples:
createWildcardFilter(String).
This path is then continued with the following parts after '/' if given.
But parts after asterisk are not used:
[dirA/**|dirB/spec]/*.c* |
Here all *.c* files either from dirA in any deepness or from dirB/spec/*.c* are matching |
[dirA/[spec1|spec2]|dirB/spec]/*.c* |
The parts of the path can be also nested. |
[...part...| is evaluated as an own expression in createWildcardFilter(String).
Hence any nesting is possible.
'*' can only be simple texts:
*.[~bak|~old] |
The filter does not accept names ending with this both
Note: Either a positive or a negative variant choice is possible. Both is nonsense. |
*.[c|cpp] |
The filter accepts names ending with ".c" or ".cpp".
This is the better possibility instead *.c* to accept C and C++ files.
Note: The list to check variantsEnd contains ".c" and ".cpp",
the complete text.
The writing style with the "." outside of the variants is only an abbreviation for writing. |
FileFunctions#createWildcardFilter(String) for a whole path
and see #accept(File, String).sMask - mask due to given examplesfilterChild - null or a child filter for the next level. Note: Parsing is done backward.private static void parseVariants(java.lang.String sPart,
int posBracket,
java.util.List<FilepathFilterM> list,
FilepathFilterM filterChild)
createWildcardFilter(String, FilepathFilterM) recursively for each found variant.
FilepathFilterM to the list, to store in the parents variantsBegin.sPart - The given textual part with variants till posBracket.posBracket - the end of the given variants in sPart (behind some other parts follow)list - The list to add the variants.filterChild - The given FilepathFilterM for children in the path (Note: parsing is processed backward)private static int parseVariantsEnd(java.lang.String sPart,
int posBracket,
java.util.List<java.lang.String> list)
parseVariants(String, int, List, FilepathFilterM) but only for end.
The end cannot contain directories, hence list is only a String.sPart - used after posBracketposBracket - the position of the opening bracket for the variants in sPartlist - public FilepathFilterM nextChild()
public boolean XXaccept(java.io.File dir,
java.lang.String name)
nextChild() and also not a path separated with '/' or '\'.
See FileFunctions#checkPathTODOpublic FilepathFilterM check(java.lang.String name, boolean bDir)
name - The name of a file or directory to check.bDir - true then it is a directory name what is to check.private FilepathFilterM checkRecursive(java.lang.String name, boolean bDir, int[] posEndBegin)
bAllTree is set, then this 'name' is tested with the aFilterChild.
aFilterChild matches, it is the child.
Then the return value of the recursively call is returned as filter for the next path entry.
aFilterChild does not match, and 'name' is a directory,
then name is matching, because bAllTree matches.
Then this is returned as next filter to check the next path entry.
aFilterChild does not match but 'name' is not a directory, then it returns null for not matching.
The bAllTree flag is only valid for directory entries as 'name'
bAllTree is not set, then the internal 'nextf' is set to the aFilterChild or to 'this'
if 'name' is a file (not directory, 'bDir' == false.
This value is prepared for return if all tests matches.
If tests are not matching, null is returned.
variantsBegin are not given, then the 'bDir' of name should matching to aFilterChild:
A directory need aFilterChild, a file must not have aFilterChild. If this is not proper, returns null.
But if variantsBegin are given, aFilterChild can be null, because the variants contains the filterchild.
Hence 'bDir' is then not evalueated.
zBegin and zEnd shortens the middle part of 'name'.
bNotBegin is given and the sBegin is longer then 'name' without zEnd,
then it is ok, the sBegin does not match, the test goes on.
But if bNotBegin is false, the test failes, return null.
sBegin is given, name without zEnd is tested.
returns false if is ok but bNotBegin is set, or if not ok and bNotBegin is false.
Else continue with further tests.
variantsBegin is given, then all variants are tested with the name part after zBegin
till zEnd.
This is done with recursively call of this operation via checkVariants(String, boolean, int[], int).
return value null of this call returns with null, it does not match.
The detailed bNotBegin etc. are done in the recursion.
variantsEnd are given, they are checked via checkVariantsEnd(String, int).
If this operation returns null, return null.
sEnd is given, it should match zEnd == 0, then not relevant.
sContain is test with the remaining middle part.
name - Name of the entry in path, either a directory or file name.bDir - true if 'name' is a directory entryposEndBegin - position to test 'name', >0 if this is called as inner variant test.FilepathFilterM to test the next entry in the path.
bAllTree matches. It is 'this' only to have a value !=null if not 'bDir'.
the last check does not call more checks because it is the last entry.
aFilterChild on matching the current entry.#
public boolean selAllFilesInDir()
public boolean selAllDirEntries()
public boolean selAllEntries()
bAllTree.private FilepathFilterM checkVariants(java.lang.String name, boolean bDir, int[] posEndBegin, int posStartEnd)
private int checkVariantsEnd(java.lang.String name,
int zName)
public static FilepathFilterM createWildcardFilter(java.lang.String maskP)
maskP - as examples above, for possibilities in each level see FilepathFilterM#FilepathFilterM(String, FilepathFilterM)private static FilepathFilterM createWildcardFilter(java.lang.String maskP, FilepathFilterM filterChildP)
maskP - bEnd - true if [internal] is parsed in sEnd rangepublic java.lang.StringBuilder toString(java.lang.StringBuilder app,
java.lang.String... cond)
ToStringBuildertoString in interface ToStringBuilderapp - an Appendable, especially a StringBuilder which have no additional tyry.catch necessitiescond - Any string optional, for conditions to control the output.
// * @throws IOException This is the necessity of Appendable.append(CharSequence).
// * It may be caught to throw new RuntimeException(exc) it not expected.
// * Especially a StringBuilder.append(CharSequence) does not throw an exception.public java.lang.String toString()
toString in class java.lang.Object