01: /*
02: * @(#)ProjectionEnumeration.java 1.2 04/12/06
03: *
04: * Copyright (c) 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package org.pnuts.lib;
10:
11: import java.util.*;
12:
13: class ProjectionEnumeration implements Iterator {
14: private Enumeration en;
15: private Object next;
16: private boolean end;
17: private boolean needToFindNext = true;
18:
19: protected ProjectionEnumeration() {
20: }
21:
22: public ProjectionEnumeration(Enumeration en) {
23: this .en = en;
24: }
25:
26: protected Object project(Object obj) {
27: return obj;
28: }
29:
30: protected boolean findNext() {
31: if (en.hasMoreElements()) {
32: next = project(en.nextElement());
33: return true;
34: }
35: this .end = true;
36: return false;
37: }
38:
39: public boolean hasNext() {
40: if (needToFindNext) {
41: findNext();
42: this .needToFindNext = false;
43: }
44: return !end;
45: }
46:
47: public Object next() {
48: if (!hasNext()) {
49: throw new NoSuchElementException();
50: }
51: this .needToFindNext = true;
52: return next;
53: }
54:
55: public void remove() {
56: throw new UnsupportedOperationException();
57: }
58: }
|