[JGIT PATCH v3 07/23] Added the class FilePathPattern.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Florian Koeberle <florianskarten@xxxxxx>
---
 .../jgit/treewalk/rules/FilePathPattern.java       |   76 ++++++++++++++++++++
 1 files changed, 76 insertions(+), 0 deletions(-)
 create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePathPattern.java

diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePathPattern.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePathPattern.java
new file mode 100644
index 0000000..4a5f021
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/FilePathPattern.java
@@ -0,0 +1,76 @@
+/*
+ *  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 FilePathPattern} represents a pattern for a file path.
+ * 
+ */
+class FilePathPattern implements FilePattern {
+	private final FileNameMatcher matcher;
+
+	private final boolean matchDirectoriesOnly;
+
+	private FilePathPattern(final FileNameMatcher matcher,
+			final boolean matchDirectoriesOnly) {
+		this.matcher = matcher;
+		this.matchDirectoriesOnly = matchDirectoriesOnly;
+	}
+
+	FilePathPattern(final String pattern, final boolean allowSlashInWildCard,
+			final boolean matchDirectoriesOnly) throws InvalidPatternException {
+
+		if (allowSlashInWildCard)
+			this.matcher = new FileNameMatcher(pattern, null);
+		else
+			this.matcher = new FileNameMatcher(pattern, new Character('/'));
+		this.matchDirectoriesOnly = matchDirectoriesOnly;
+	}
+
+	public FilePattern getPatternForSubDirectory(String directoryName) {
+		matcher.resetStringToMatch();
+		matcher.extendStringToMatch(directoryName);
+
+		if (matcher.isMatch())
+			return FilePattern.MATCH_ALWAYS;
+
+		matcher.extendStringToMatch("/");
+
+		if (matcher.willExtendResultInNoMatch())
+			return FilePattern.MATCH_NEVER;
+
+		final FileNameMatcher childMatcher = matcher.createMatcherForSuffix();
+		return new FilePathPattern(childMatcher, matchDirectoriesOnly);
+	}
+
+	public boolean match(String fileName, boolean fileIsDirectory) {
+		if (!fileIsDirectory && matchDirectoriesOnly) {
+			return false;
+		}
+		matcher.resetStringToMatch();
+		matcher.extendStringToMatch(fileName);
+		return matcher.isMatch();
+	}
+
+	public boolean isSameForSubDirectories() {
+		return false;
+	}
+
+}
-- 
1.5.4.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux