[JGIT PATCH v2 17/24] Added the class TreeFilePattern.
From: Florian Koeberle <hidden>
Date: 2016-06-15 22:44:36
Subsystem:
the rest · Maintainer:
Linus Torvalds
Signed-off-by: Florian Koeberle <redacted> --- .../jgit/treewalk/rules/TreeFilePattern.java | 75 ++++++++++++++++++++ 1 files changed, 75 insertions(+), 0 deletions(-) create mode 100644 org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/TreeFilePattern.java
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/TreeFilePattern.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/TreeFilePattern.java
new file mode 100644
index 0000000..9234c95
--- /dev/null
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/rules/TreeFilePattern.java@@ -0,0 +1,75 @@ +/* + * 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 java.util.List; + +/** + * Represents a pattern like "documents/*.txt" which matches all *.txt files in + * the tree documents. + * + */ +class TreeFilePattern implements FilePattern { + + private final List<String> path; + + private final int offset; + + private final GlobalFilePattern globalFilePattern; + + public boolean canMatchAtThisDirectoryLevel() { + return false; + } + + TreeFilePattern(List<String> path, GlobalFilePattern globalFilePattern) { + this.path = path; + this.offset = 0; + this.globalFilePattern = globalFilePattern; + } + + private TreeFilePattern(List<String> path, int offset, + GlobalFilePattern globalFilePattern) { + this.path = path; + this.offset = offset; + this.globalFilePattern = globalFilePattern; + } + + public FilePattern getPatternForSubDirectory(String directoryName) { + try { + if (!path.get(offset).equals(directoryName)) { + return FilePattern.MATCH_NEVER; + } + } catch (IndexOutOfBoundsException e) { + throw new IllegalStateException( + "The offset of this class doesn't refer to a valid position in path"); + } + if (offset == path.size() - 1) { + return globalFilePattern; + } else { + return new TreeFilePattern(path, offset + 1, globalFilePattern); + } + } + + public boolean isSameForSubDirectories() { + return false; + } + + public boolean match(String fileName, boolean fileIsDirectory) { + return false; + } + +}
--
1.5.4.3