Top Description Fields Constructors Methods
org.eclipse.jgit.fnmatch

public Class FileNameMatcher

extends Object
Class Inheritance
Imports
java.util.ArrayList, .Collections, .List, .ListIterator, java.util.regex.Matcher, .Pattern, org.eclipse.jgit.errors.InvalidPatternException, .NoClosingBracketException

This 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:

Any character can be escaped by prepending it with a \

Field Summary

Modifier and TypeField and Description
private static final Pattern
pack-priv static final List<Head>
private List<Head>
private List<Head>
private 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

AccessConstructor and Description
private
FileNameMatcher(List<Head>
must be a list which will never be modified.
headsStartValue
)

private
FileNameMatcher(final List<Head>
must be a list which will never be modified.
headsStartValue
,
final List<Head>
a list which will be cloned and then used as current head list.
heads
)

public
FileNameMatcher(final String
must contain a pattern which fnmatch would accept.
patternString
,
final Character
if this parameter isn't null then this character will not match at wildcards(* and ? are wildcards).
invalidWildgetCharacter
)

Constructor for FileNameMatcher

public
FileNameMatcher(FileNameMatcher other)

A Copy Constructor which creates a new org.eclipse.jgit.fnmatch.FileNameMatcher with the same state and reset point like other.

Method Summary

Modifier and TypeMethod and Description
public void
append(String
extends the string which is matched against the patterns of this class.
stringToMatch
)

Append to the string which is matched against the patterns of this class

public boolean

Returns:

a boolean.
canAppendMatch
()

Whether a match can be appended

private static List<Head>
createHeadsStartValues(final String patternString, final Character invalidWildgetCharacter)

public FileNameMatcher

Returns:

a org.eclipse.jgit.fnmatch.FileNameMatcher instance which uses the same pattern like this matcher, but has the current state of this matcher as reset and start point.
createMatcherForSuffix
()

Create a org.eclipse.jgit.fnmatch.FileNameMatcher instance which uses the same pattern like this matcher, but has the current state of this matcher as reset and start point

private static List<AbstractHead>
createSimpleHeads(final String patternPart, final Character invalidWildgetCharacter)

private static AbstractHead
createWildCardHead(final Character invalidWildgetCharacter, final boolean star)

private boolean

Returns:

true to continue, false if the matcher can stop appending
extendStringToMatchByOneCharacter
(char
new character to append
c
)

private static int
findGroupEnd(final int indexOfStartBracket, final String pattern)

private static int
indexOfUnescaped(final String searchString, final char ch, final int fromIndex)

public boolean

Returns:

whether the matcher matches
isMatch
()

Whether the matcher matches

private static List<AbstractHead>
parseHeads(final String pattern, final Character invalidWildgetCharacter)

public void
reset()

Resets this matcher to it's state right after construction.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

characterClassStartPatternback to summary
private static final Pattern characterClassStartPattern
EMPTY_HEAD_LISTback to summary
pack-priv static final List<Head> EMPTY_HEAD_LIST
headsback to summary
private List<Head> heads
headsStartValueback to summary
private List<Head> headsStartValue
listForLocalUseageback to summary
private 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

FileNameMatcherback to summary
private FileNameMatcher(List<Head> headsStartValue)
Parameters
headsStartValue:List<Head>

must be a list which will never be modified.

FileNameMatcherback to summary
private FileNameMatcher(final List<Head> headsStartValue, final List<Head> heads)
Parameters
headsStartValue:List<Head>

must be a list which will never be modified.

heads:List<Head>

a list which will be cloned and then used as current head list.

FileNameMatcherback to summary
public FileNameMatcher(final String patternString, final Character invalidWildgetCharacter) throws InvalidPatternException

Constructor for FileNameMatcher

Parameters
patternString:String

must contain a pattern which fnmatch would accept.

invalidWildgetCharacter:Character

if this parameter isn't null then this character will not match at wildcards(* and ? are wildcards).

Exceptions
InvalidPatternException:
if the patternString contains a invalid fnmatch pattern.
FileNameMatcherback to summary
public FileNameMatcher(FileNameMatcher other)

A Copy Constructor which creates a new org.eclipse.jgit.fnmatch.FileNameMatcher with the same state and reset point like other.

Parameters
other:FileNameMatcher

another org.eclipse.jgit.fnmatch.FileNameMatcher instance.

Method Detail

appendback to summary
public void append(String stringToMatch)

Append to the string which is matched against the patterns of this class

Parameters
stringToMatch:String

extends the string which is matched against the patterns of this class.

canAppendMatchback to summary
public boolean canAppendMatch()

Whether a match can be appended

Returns:boolean

a boolean.

createHeadsStartValuesback to summary
private static List<Head> createHeadsStartValues(final String patternString, final Character invalidWildgetCharacter) throws InvalidPatternException
createMatcherForSuffixback to summary
public FileNameMatcher createMatcherForSuffix()

Create a org.eclipse.jgit.fnmatch.FileNameMatcher instance which uses the same pattern like this matcher, but has the current state of this matcher as reset and start point

Returns:FileNameMatcher

a org.eclipse.jgit.fnmatch.FileNameMatcher instance which uses the same pattern like this matcher, but has the current state of this matcher as reset and start point.

createSimpleHeadsback to summary
private static List<AbstractHead> createSimpleHeads(final String patternPart, final Character invalidWildgetCharacter)
createWildCardHeadback to summary
private static AbstractHead createWildCardHead(final Character invalidWildgetCharacter, final boolean star)
extendStringToMatchByOneCharacterback to summary
private boolean extendStringToMatchByOneCharacter(char c)
Parameters
c:char

new character to append

Returns:boolean

true to continue, false if the matcher can stop appending

findGroupEndback to summary
private static int findGroupEnd(final int indexOfStartBracket, final String pattern) throws InvalidPatternException
indexOfUnescapedback to summary
private static int indexOfUnescaped(final String searchString, final char ch, final int fromIndex)
isMatchback to summary
public boolean isMatch()

Whether the matcher matches

Returns:boolean

whether the matcher matches

parseHeadsback to summary
private static List<AbstractHead> parseHeads(final String pattern, final Character invalidWildgetCharacter) throws InvalidPatternException
resetback to summary
public void reset()

Resets this matcher to it's state right after construction.