[JGIT PATCH v3 06/23] Added the class FileNamePattern.
Signed-off-by: Florian Koeberle <florianskarten@web.de>
---
.../jgit/treewalk/rules/FileNamePattern.java | 58 ++++++++++++++++++++
1 files changed, 58 insertions(+), 0 deletions(-)
create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FileNamePattern.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FileNamePattern.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FileNamePattern.java
new file mode 100644
index 0000000..f14fdef
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FileNamePattern.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2008 Florian Köberle
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License, version 2, as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ */
+package org.spearce.jgit.treewalk.rules;
+
+import org.spearce.jgit.errors.InvalidPatternException;
+import org.spearce.jgit.lib.FileNameMatcher;
+
+/**
+ * A {@link FileNamePattern} defines a pattern for all files in a tree. A
+ * typical example would be "*.txt", which would match at any file or subtree
+ * which ends with ".txt" like "a/b/c.txt" and "a.txt/a.c".
+ *
+ */
+class FileNamePattern implements FilePattern {
+ private final FileNameMatcher fileNameMatcher;
+
+ private final boolean matchDirectoriesOnly;
+
+ FileNamePattern(String fnMatchPatternString, boolean matchDirectoriesOnly)
+ throws InvalidPatternException {
+ this.fileNameMatcher = new FileNameMatcher(fnMatchPatternString, null);
+ this.matchDirectoriesOnly = matchDirectoriesOnly;
+ }
+
+ public FilePattern getPatternForSubDirectory(String directoryName) {
+ if (match(directoryName, true)) {
+ return MATCH_ALWAYS;
+ }
+ return this;
+ }
+
+ public boolean match(String fileName, boolean fileIsDirectory) {
+ if (matchDirectoriesOnly && !fileIsDirectory) {
+ return false;
+ }
+ fileNameMatcher.resetStringToMatch();
+ fileNameMatcher.extendStringToMatch(fileName);
+ return fileNameMatcher.isMatch();
+ }
+
+ public boolean isSameForSubDirectories() {
+ return false;
+ }
+}
--
1.5.4.3