Mercurial > hg4j
comparison src/org/tmatesoft/hg/util/FileWalker.java @ 287:ed6b74a58c66
Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Wed, 07 Sep 2011 09:33:27 +0200 |
| parents | 1ec6b327a6ac |
| children | 7f27122011c3 |
comparison
equal
deleted
inserted
replaced
| 286:954763c82cc3 | 287:ed6b74a58c66 |
|---|---|
| 30 private final File startDir; | 30 private final File startDir; |
| 31 private final Path.Source pathHelper; | 31 private final Path.Source pathHelper; |
| 32 private final LinkedList<File> dirQueue; | 32 private final LinkedList<File> dirQueue; |
| 33 private final LinkedList<File> fileQueue; | 33 private final LinkedList<File> fileQueue; |
| 34 private final Path.Matcher scope; | 34 private final Path.Matcher scope; |
| 35 private File nextFile; | 35 private RegularFileInfo nextFile; |
| 36 private Path nextPath; | 36 private Path nextPath; |
| 37 | 37 |
| 38 public FileWalker(File dir, Path.Source pathFactory) { | 38 public FileWalker(File dir, Path.Source pathFactory) { |
| 39 this(dir, pathFactory, null); | 39 this(dir, pathFactory, null); |
| 40 } | 40 } |
| 58 | 58 |
| 59 public void reset() { | 59 public void reset() { |
| 60 fileQueue.clear(); | 60 fileQueue.clear(); |
| 61 dirQueue.clear(); | 61 dirQueue.clear(); |
| 62 dirQueue.add(startDir); | 62 dirQueue.add(startDir); |
| 63 nextFile = null; | 63 nextFile = new RegularFileInfo(); |
| 64 nextPath = null; | 64 nextPath = null; |
| 65 } | 65 } |
| 66 | 66 |
| 67 public boolean hasNext() { | 67 public boolean hasNext() { |
| 68 return fill(); | 68 return fill(); |
| 70 | 70 |
| 71 public void next() { | 71 public void next() { |
| 72 if (!fill()) { | 72 if (!fill()) { |
| 73 throw new NoSuchElementException(); | 73 throw new NoSuchElementException(); |
| 74 } | 74 } |
| 75 nextFile = fileQueue.removeFirst(); | 75 File next = fileQueue.removeFirst(); |
| 76 nextPath = pathHelper.path(nextFile.getPath()); | 76 nextFile.init(next); |
| 77 nextPath = pathHelper.path(next.getPath()); | |
| 77 } | 78 } |
| 78 | 79 |
| 79 public Path name() { | 80 public Path name() { |
| 80 return nextPath; | 81 return nextPath; |
| 81 } | 82 } |
| 82 | 83 |
| 83 public File file() { | 84 public FileInfo file() { |
| 84 return nextFile; | 85 return nextFile; |
| 85 } | 86 } |
| 86 | 87 |
| 87 public boolean inScope(Path file) { | 88 public boolean inScope(Path file) { |
| 88 /* by default, no limits, all files are of interest */ | 89 /* by default, no limits, all files are of interest */ |
