[JGIT PATCH 13/22] Added the class ComplexFilePattern.

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

 



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

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/ComplexFilePattern.java b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/ComplexFilePattern.java
new file mode 100644
index 0000000..e658d45
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/fileiteration/ComplexFilePattern.java
@@ -0,0 +1,89 @@
+/*
+ *  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.lib.fileiteration;
+
+import java.util.List;
+import java.util.ArrayList;
+
+class ComplexFilePattern implements FilePattern {
+	/**
+	 * Can contain String and
+	 */
+	private final List<StarPattern> usedPatternList;
+
+	private final boolean matchDirectoriesOnly;
+
+	private final int offset;
+
+	private ComplexFilePattern(List<StarPattern> List,
+			boolean matchDirectoriesOnly, int offset) {
+		this.usedPatternList = List;
+		this.matchDirectoriesOnly = matchDirectoriesOnly;
+		this.offset = offset;
+	}
+
+	ComplexFilePattern(List<String> patternStrings, boolean matchDirectoriesOnly) {
+		this.usedPatternList = new ArrayList<StarPattern>(patternStrings.size());
+		for (String patternString : patternStrings) {
+			this.usedPatternList.add(new StarPattern(patternString));
+		}
+		this.offset = 0;
+		this.matchDirectoriesOnly = matchDirectoriesOnly;
+	}
+
+	int getActualPathSize() {
+		return usedPatternList.size() - offset;
+	}
+
+	private StarPattern getPatternOfCurrentLevel() {
+		return usedPatternList.get(offset);
+	}
+
+	public boolean canMatchAtThisDirectoryLevel() {
+		return getActualPathSize() == 1;
+	}
+
+	public FilePattern getPatternForSubDirectory(String directoryName) {
+
+		if (getActualPathSize() > 1) {
+			if (getPatternOfCurrentLevel().matches(directoryName)) {
+				return new ComplexFilePattern(usedPatternList,
+						matchDirectoriesOnly, offset + 1);
+			} else {
+				return FilePattern.MATCH_NEVER;
+			}
+		}
+		assert (getActualPathSize() == 1);
+		if (match(directoryName, true)) {
+			return FilePattern.MATCH_ALWAYS;
+		} else {
+			return FilePattern.MATCH_NEVER;
+		}
+	}
+
+	public boolean match(String fileName, boolean fileIsDirectory) {
+		if (!fileIsDirectory && matchDirectoriesOnly) {
+			return false;
+		}
+		return getPatternOfCurrentLevel().matches(fileName);
+	}
+
+	public boolean isSameForSubDirectories() {
+		return false;
+	}
+
+}
-- 
1.5.2.5

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