1 /*
2 * EnumerationChain.java
3 * Created on September 4, 2003
4 *
5 * The Blues Framework - A lightweight application framework
6 * Copyright (C) 2003 Lonnie Pryor
7 * http://blues.lonniepryor.com
8 *
9 * This library is free software; you can redistribute it and/or modify it under the
10 * terms of the GNU Lesser General Public License as published by the Free Software
11 * Foundation; either version 2.1 of the License, or (at your option) any later
12 * version.
13 *
14 * This library is distributed in the hope that it will be useful, but WITHOUT ANY
15 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
16 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License along
19 * with this library; if not, write to:
20 *
21 * The Free Software Foundation, Inc.
22 * 59 Temple Place, Suite 330
23 * Boston, MA 02111-1307 USA
24 *
25 */
26 package com.lonniepryor.blues.util;
27
28 import java.util.Enumeration;
29
30 /***
31 * Simple implementation of the Composite pattern for java.util.Enumeration. NOTE:
32 * this class is NOT thread-safe and instances may only be used on a single thread
33 * at a time.
34 *
35 * @author Lonnie Pryor
36 * @version $Revision: 1.1 $
37 */
38 public final class EnumerationChain implements Enumeration {
39 /*** The currently operating enumeration. */
40 private Enumeration current;
41 /*** The next enumeration to use. */
42 private Enumeration next;
43
44 /***
45 * Creates a new EnumerationChain object.
46 *
47 * @param first The first enumeration.
48 * @param second The second enumeration.
49 */
50 public EnumerationChain (Enumeration first, Enumeration second) {
51 if (first == null)
52 throw new NullPointerException("first");
53 if (second == null)
54 throw new NullPointerException("second");
55 current = first;
56 next = second;
57 }
58
59 /* (non-Javadoc)
60 * @see java.util.Enumeration#hasMoreElements()
61 */
62 public boolean hasMoreElements () {
63 if (current == null)
64 return false;
65 if (current.hasMoreElements())
66 return true;
67 current = next;
68 next = null;
69 return hasMoreElements();
70 }
71
72 /* (non-Javadoc)
73 * @see java.util.Enumeration#nextElement()
74 */
75 public Object nextElement () {
76 if (!hasMoreElements())
77 throw new IllegalStateException();
78 return current.nextElement();
79 }
80 }
This page was automatically generated by Maven