Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/PathRegexpMatcher.java @ 114:46291ec605a0
Filters to read and initialize according to configuration files
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 03 Feb 2011 22:13:55 +0100 |
parents | |
children | 7567f4a42fe5 |
comparison
equal
deleted
inserted
replaced
113:67ae317408c9 | 114:46291ec605a0 |
---|---|
1 /* | |
2 * Copyright (c) 2011 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@svnkit.com | |
16 */ | |
17 package org.tmatesoft.hg.internal; | |
18 | |
19 import java.util.regex.Pattern; | |
20 import java.util.regex.PatternSyntaxException; | |
21 | |
22 import org.tmatesoft.hg.core.Path; | |
23 import org.tmatesoft.hg.core.Path.Matcher; | |
24 | |
25 /** | |
26 * | |
27 * @author Artem Tikhomirov | |
28 * @author TMate Software Ltd. | |
29 */ | |
30 public class PathRegexpMatcher implements Matcher { | |
31 private Pattern[] patterns; | |
32 | |
33 // disjunction, matches if any pattern found | |
34 // uses pattern.find(), not pattern.matches() | |
35 public PathRegexpMatcher(Pattern... p) { | |
36 if (p == null) { | |
37 throw new IllegalArgumentException(); | |
38 } | |
39 patterns = p; | |
40 } | |
41 | |
42 public PathRegexpMatcher(String... p) throws PatternSyntaxException { | |
43 this(compile(p)); | |
44 } | |
45 | |
46 private static Pattern[] compile(String[] p) throws PatternSyntaxException { | |
47 // deliberately do no check for null, let it fail | |
48 Pattern[] rv = new Pattern[p.length]; | |
49 int i = 0; | |
50 for (String s : p) { | |
51 rv[i++] = Pattern.compile(s); | |
52 } | |
53 return rv; | |
54 } | |
55 | |
56 public boolean accept(Path path) { | |
57 for (Pattern p : patterns) { | |
58 if (p.matcher(path).find()) { | |
59 return true; | |
60 } | |
61 } | |
62 return false; | |
63 } | |
64 } |