01:/*
02: * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
03: * reserved.
04: *
05: * Redistribution and use in source and binary forms, with or without
06: * modification, are permitted provided that the following conditions
07: * are met:
08: *
09: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: *
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in
14: * the documentation and/or other materials provided with the
15: * distribution.
16: *
17: * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
18: * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
21: * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28: *
29: */
30:
31:package rcm.enum;
32:import java.util.Enumeration;
33:import java.util.NoSuchElementException;
34:
35:/**
36: * Enumeration of an arbitrary array.
37: */
38:public class ArrayEnumeration implements Enumeration {
39: Object[] array;
40: int i = 0;
41:
42: /**
43: * Make an ArrayEnumeration.
44: * @param array Array to enumerate. May be null, if desired.
45: * (This is sometimes useful for producing an empty enumeration.)
46: */
47: public ArrayEnumeration (Object[] array) {
48: this .array = array;
49: }
50:
51: /**
52: * Test if enumeration has reached end.
53: * @return true if more elements are available to be enumerated, false
54: * if all elements have been yielded by nextElement()
55: */
56: public boolean hasMoreElements () {
57: return array != null ? i < array.length : false;
58: }
59:
60: /**
61: * Get next element of enumeration.
62: * @return next element of enumeration, advancing the enumeration pointer
63: * @exception java.util.NoSuchElementException if no more elements
64: */
65: public Object nextElement () {
66: if (array == null || i >= array.length)
67: throw new NoSuchElementException ();
68: return array[i++];
69: }
70:}
|