01: // FileEnumeration.java
02: // $Id: FileEnumeration.java,v 1.6 2007/02/09 13:45:14 ylafon Exp $
03: // (c) COPYRIGHT MIT and INRIA, 1997.
04: // Please first read the full copyright statement in file COPYRIGHT.html
05:
06: package org.w3c.cvs;
07:
08: import java.util.Enumeration;
09: import java.util.Hashtable;
10: import java.util.NoSuchElementException;
11:
12: class FileEnumeration implements Enumeration {
13: CvsEntry next = null;
14: Enumeration cvsenum = null;
15:
16: private CvsEntry computeNextElement() {
17: if (cvsenum == null)
18: return (next = null);
19: while ((next == null) && cvsenum.hasMoreElements()) {
20: CvsEntry entry = (CvsEntry) cvsenum.nextElement();
21: if (!entry.isdir)
22: next = entry;
23: }
24: return next;
25: }
26:
27: public synchronized boolean hasMoreElements() {
28: return ((next != null) || ((next = computeNextElement()) != null));
29: }
30:
31: public synchronized Object nextElement() {
32: if (next == null) {
33: if ((next = computeNextElement()) == null)
34: throw new NoSuchElementException("invalid enum");
35: }
36: CvsEntry item = next;
37: next = null;
38: return item.name;
39: }
40:
41: FileEnumeration(Hashtable entries) {
42: this.cvsenum = (entries != null) ? entries.elements() : null;
43: }
44:
45: }
|