Package org.eclipse.jgit.fnmatch
Class FileNameMatcher
- java.lang.Object
-
- org.eclipse.jgit.fnmatch.FileNameMatcher
-
public class FileNameMatcher extends java.lang.ObjectThis class can be used to match filenames against fnmatch like patterns. It is not thread save.Supported are the wildcard characters * and ? and groups with:
- characters e.g. [abc]
- ranges e.g. [a-z]
- the following character classes
- [:alnum:]
- [:alpha:]
- [:blank:]
- [:cntrl:]
- [:digit:]
- [:graph:]
- [:lower:]
- [:print:]
- [:punct:]
- [:space:]
- [:upper:]
- [:word:]
- [:xdigit:]
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.PatterncharacterClassStartPattern(package private) static java.util.List<Head>EMPTY_HEAD_LISTprivate java.util.List<Head>headsprivate java.util.List<Head>headsStartValueprivate java.util.List<Head>listForLocalUseage{extendStringToMatchByOneCharacter(char)needs a list for the new heads, allocating a new array would be bad for the performance, as the method gets called very often.
-
Constructor Summary
Constructors Modifier Constructor Description FileNameMatcher(java.lang.String patternString, java.lang.Character invalidWildgetCharacter)Constructor for FileNameMatcherprivateFileNameMatcher(java.util.List<Head> headsStartValue)privateFileNameMatcher(java.util.List<Head> headsStartValue, java.util.List<Head> heads)FileNameMatcher(FileNameMatcher other)A Copy Constructor which creates a newFileNameMatcherwith the same state and reset point likeother.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(java.lang.String stringToMatch)Append to the string which is matched against the patterns of this classbooleancanAppendMatch()Whether a match can be appendedprivate static java.util.List<Head>createHeadsStartValues(java.lang.String patternString, java.lang.Character invalidWildgetCharacter)FileNameMatchercreateMatcherForSuffix()Create aFileNameMatcherinstance which uses the same pattern like this matcher, but has the current state of this matcher as reset and start pointprivate static java.util.List<AbstractHead>createSimpleHeads(java.lang.String patternPart, java.lang.Character invalidWildgetCharacter)private static AbstractHeadcreateWildCardHead(java.lang.Character invalidWildgetCharacter, boolean star)private booleanextendStringToMatchByOneCharacter(char c)private static intfindGroupEnd(int indexOfStartBracket, java.lang.String pattern)private static intindexOfUnescaped(java.lang.String searchString, char ch, int fromIndex)booleanisMatch()Whether the matcher matchesprivate static java.util.List<AbstractHead>parseHeads(java.lang.String pattern, java.lang.Character invalidWildgetCharacter)voidreset()Resets this matcher to it's state right after construction.
-
-
-
Field Detail
-
EMPTY_HEAD_LIST
static final java.util.List<Head> EMPTY_HEAD_LIST
-
characterClassStartPattern
private static final java.util.regex.Pattern characterClassStartPattern
-
headsStartValue
private java.util.List<Head> headsStartValue
-
heads
private java.util.List<Head> heads
-
listForLocalUseage
private java.util.List<Head> listForLocalUseage
{extendStringToMatchByOneCharacter(char)needs a list for the new heads, allocating a new array would be bad for the performance, as the method gets called very often.
-
-
Constructor Detail
-
FileNameMatcher
private FileNameMatcher(java.util.List<Head> headsStartValue)
- Parameters:
headsStartValue- must be a list which will never be modified.
-
FileNameMatcher
private FileNameMatcher(java.util.List<Head> headsStartValue, java.util.List<Head> heads)
- Parameters:
headsStartValue- must be a list which will never be modified.heads- a list which will be cloned and then used as current head list.
-
FileNameMatcher
public FileNameMatcher(java.lang.String patternString, java.lang.Character invalidWildgetCharacter) throws InvalidPatternExceptionConstructor for FileNameMatcher- Parameters:
patternString- must contain a pattern which fnmatch would accept.invalidWildgetCharacter- if this parameter isn't null then this character will not match at wildcards(* and ? are wildcards).- Throws:
InvalidPatternException- if the patternString contains a invalid fnmatch pattern.
-
FileNameMatcher
public FileNameMatcher(FileNameMatcher other)
A Copy Constructor which creates a newFileNameMatcherwith the same state and reset point likeother.- Parameters:
other- anotherFileNameMatcherinstance.
-
-
Method Detail
-
createHeadsStartValues
private static java.util.List<Head> createHeadsStartValues(java.lang.String patternString, java.lang.Character invalidWildgetCharacter) throws InvalidPatternException
- Throws:
InvalidPatternException
-
findGroupEnd
private static int findGroupEnd(int indexOfStartBracket, java.lang.String pattern) throws InvalidPatternException- Throws:
InvalidPatternException
-
parseHeads
private static java.util.List<AbstractHead> parseHeads(java.lang.String pattern, java.lang.Character invalidWildgetCharacter) throws InvalidPatternException
- Throws:
InvalidPatternException
-
createSimpleHeads
private static java.util.List<AbstractHead> createSimpleHeads(java.lang.String patternPart, java.lang.Character invalidWildgetCharacter)
-
createWildCardHead
private static AbstractHead createWildCardHead(java.lang.Character invalidWildgetCharacter, boolean star)
-
extendStringToMatchByOneCharacter
private boolean extendStringToMatchByOneCharacter(char c)
- Parameters:
c- new character to append- Returns:
- true to continue, false if the matcher can stop appending
-
indexOfUnescaped
private static int indexOfUnescaped(java.lang.String searchString, char ch, int fromIndex)
-
append
public void append(java.lang.String stringToMatch)
Append to the string which is matched against the patterns of this class- Parameters:
stringToMatch- extends the string which is matched against the patterns of this class.
-
reset
public void reset()
Resets this matcher to it's state right after construction.
-
createMatcherForSuffix
public FileNameMatcher createMatcherForSuffix()
Create aFileNameMatcherinstance which uses the same pattern like this matcher, but has the current state of this matcher as reset and start point- Returns:
- a
FileNameMatcherinstance which uses the same pattern like this matcher, but has the current state of this matcher as reset and start point.
-
isMatch
public boolean isMatch()
Whether the matcher matches- Returns:
- whether the matcher matches
-
canAppendMatch
public boolean canAppendMatch()
Whether a match can be appended- Returns:
- a boolean.
-
-