Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/PathScope.java @ 229:1ec6b327a6ac
Scope for status reworked: explicit files or a general matcher
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 31 May 2011 05:23:07 +0200 |
parents | |
children | 072b5f3ed0c8 |
comparison
equal
deleted
inserted
replaced
228:fffe4f882248 | 229:1ec6b327a6ac |
---|---|
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@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.internal; | |
18 | |
19 import java.util.ArrayList; | |
20 | |
21 import org.tmatesoft.hg.util.Path; | |
22 | |
23 /** | |
24 * @author Artem Tikhomirov | |
25 * @author TMate Software Ltd. | |
26 */ | |
27 public class PathScope implements Path.Matcher { | |
28 private final Path[] files; | |
29 private final Path[] dirs; | |
30 private final boolean recursiveDirs; | |
31 | |
32 public PathScope(boolean recursiveDirs, Path... paths) { | |
33 if (paths == null) { | |
34 throw new IllegalArgumentException(); | |
35 } | |
36 this.recursiveDirs = recursiveDirs; | |
37 ArrayList<Path> f = new ArrayList<Path>(5); | |
38 ArrayList<Path> d = new ArrayList<Path>(5); | |
39 for (Path p : paths) { | |
40 if (p.isDirectory()) { | |
41 d.add(p); | |
42 } else { | |
43 f.add(p); | |
44 } | |
45 } | |
46 files = f.toArray(new Path[f.size()]); | |
47 dirs = d.toArray(new Path[d.size()]); | |
48 } | |
49 | |
50 public boolean accept(Path path) { | |
51 if (path.isDirectory()) { | |
52 // either equals to or parent of a directory we know about. | |
53 // If recursiveDirs, accept also if nested to one of our directories. | |
54 // If one of configured files is nested under the path, accept. | |
55 for (Path d : dirs) { | |
56 switch(d.compareWith(path)) { | |
57 case Same : return true; | |
58 case Nested : return true; | |
59 case Parent : return recursiveDirs; | |
60 } | |
61 } | |
62 for (Path f : files) { | |
63 if (f.compareWith(path) == Path.CompareResult.Nested) { | |
64 return true; | |
65 } | |
66 } | |
67 } else { | |
68 for (Path d : dirs) { | |
69 if (d.compareWith(path) == Path.CompareResult.Parent) { | |
70 return true; | |
71 } | |
72 } | |
73 for (Path f : files) { | |
74 if (f.equals(path)) { | |
75 return true; | |
76 } | |
77 } | |
78 // either lives in a directory in out scope | |
79 // or there's a file that matches the path | |
80 } | |
81 // TODO Auto-generated method stub | |
82 return false; | |
83 } | |
84 } |