01: // Copyright (c) 2000 Per M.A. Bothner.
02: // This is free software; for terms and warranty disclaimer see ./COPYING.
03:
04: package gnu.mapping;
05:
06: public class BindingEnumeration implements java.util.Enumeration {
07: Binding[] bindings;
08: int index;
09: Environment parent;
10:
11: public BindingEnumeration(Binding[] bindings, int count,
12: Environment parent) {
13: this .bindings = bindings;
14: index = count;
15: this .parent = parent;
16: }
17:
18: public BindingEnumeration(Binding[] bindings, int count) {
19: this .bindings = bindings;
20: index = count;
21: this .parent = null;
22: }
23:
24: public BindingEnumeration(Environment env) {
25: this (env.table, 1 << env.log2Size, env.previous);
26: }
27:
28: public boolean hasMoreElements() {
29: for (;;) {
30: while (index > 0) {
31: Binding element = bindings[--index];
32: if (element != null && element != Binding.hashDELETED) {
33: index++;
34: return true;
35: }
36: }
37: if (parent == null)
38: return false;
39: bindings = parent.table;
40: index = 1 << parent.log2Size;
41: parent = parent.previous;
42: }
43: }
44:
45: public Object nextElement() {
46: if (hasMoreElements())
47: return bindings[--index];
48: throw new java.util.NoSuchElementException();
49: }
50:
51: public Binding nextBinding() {
52: return bindings[--index];
53: }
54: }
|