01: /*
02: * $Id: MapArrayEnumeration.java,v 1.2 2002/09/16 08:05:02 jkl Exp $
03: *
04: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
05: *
06: * Use is subject to license terms, as defined in
07: * Anvil Sofware License, Version 1.1. See LICENSE
08: * file, or http://njet.org/license-1.1.txt
09: */
10: package anvil.core;
11:
12: import anvil.java.util.BindingEnumeration;
13: import java.util.Enumeration;
14:
15: /**
16: * class MapArrayEnumeration
17: *
18: * @author: Jani Lehtimäki
19: */
20: public class MapArrayEnumeration implements BindingEnumeration {
21:
22: private int _index = 0;
23: private int _length;
24: private boolean _up;
25: private AnyMap[] _array;
26:
27: public MapArrayEnumeration(AnyMap[] array, boolean up) {
28: _array = array;
29: _length = array.length;
30: _up = up;
31: if (!up) {
32: _index = _length - 1;
33: }
34: }
35:
36: public boolean hasMoreElements() {
37: if (_up) {
38: return _index < _length;
39: } else {
40: return _index >= 0;
41: }
42: }
43:
44: public Object nextKey() {
45: return _array[_index].getLeft();
46: }
47:
48: public Object nextElement() {
49: if (_up) {
50: if (_index < _length) {
51: return _array[_index++].getRight();
52: }
53: } else {
54: if (_index >= 0) {
55: return _array[_index--].getRight();
56: }
57: }
58: return null;
59: }
60:
61: }
|