Mercurial > hg4j
comparison src/org/tmatesoft/hg/util/FileWalker.java @ 141:8248aae33f7d
Adopt FileIterator moving towards WCStatusCollector parameterizing. Improved path handling, move 'em around
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 17 Feb 2011 04:08:34 +0100 |
parents | f3c387ea0a34 |
children | 26ad7827a62d |
comparison
equal
deleted
inserted
replaced
140:1c1891ad1c73 | 141:8248aae33f7d |
---|---|
23 /** | 23 /** |
24 * | 24 * |
25 * @author Artem Tikhomirov | 25 * @author Artem Tikhomirov |
26 * @author TMate Software Ltd. | 26 * @author TMate Software Ltd. |
27 */ | 27 */ |
28 public class FileWalker { | 28 public class FileWalker implements FileIterator { |
29 | 29 |
30 private final File startDir; | 30 private final File startDir; |
31 private final Path.Source pathHelper; | |
31 private final LinkedList<File> dirQueue; | 32 private final LinkedList<File> dirQueue; |
32 private final LinkedList<File> fileQueue; | 33 private final LinkedList<File> fileQueue; |
33 private File nextFile; | 34 private File nextFile; |
34 private String nextPath; | 35 private Path nextPath; |
35 | 36 |
36 public FileWalker(File startDir) { | 37 public FileWalker(File dir, Path.Source pathFactory) { |
37 this.startDir = startDir; | 38 startDir = dir; |
39 pathHelper = pathFactory; | |
38 dirQueue = new LinkedList<File>(); | 40 dirQueue = new LinkedList<File>(); |
39 fileQueue = new LinkedList<File>(); | 41 fileQueue = new LinkedList<File>(); |
40 reset(); | 42 reset(); |
41 } | 43 } |
42 | 44 |
55 public void next() { | 57 public void next() { |
56 if (!fill()) { | 58 if (!fill()) { |
57 throw new NoSuchElementException(); | 59 throw new NoSuchElementException(); |
58 } | 60 } |
59 nextFile = fileQueue.removeFirst(); | 61 nextFile = fileQueue.removeFirst(); |
60 nextPath = path(nextFile); | 62 nextPath = pathHelper.path(nextFile.getPath()); |
61 } | 63 } |
62 | 64 |
63 public String name() { | 65 public Path name() { |
64 return nextPath; | 66 return nextPath; |
65 } | 67 } |
66 | 68 |
67 public File file() { | 69 public File file() { |
68 return nextFile; | 70 return nextFile; |
69 } | 71 } |
70 | 72 |
71 private String path(File f) { | |
72 // XXX LocalHgRepo#normalize | |
73 String p = f.getPath().substring(startDir.getPath().length() + 1); | |
74 return p.replace('\\', '/').replace("//", "/"); | |
75 } | |
76 | |
77 private File[] listFiles(File f) { | 73 private File[] listFiles(File f) { |
78 // in case we need to solve os-related file issues (mac with some encodings?) | 74 // in case we need to solve os-related file issues (mac with some encodings?) |
79 return f.listFiles(); | 75 return f.listFiles(); |
80 } | 76 } |
81 | 77 |