OSDN Git Service

6165b2d4fcc3354a763ef21af27d33f086df2f1b
[pf3gnuchains/gcc-fork.git] / libjava / gnu / gcj / util / EnumerationChain.java
1 /* Copyright (C) 1999  Red Hat, Inc.
2
3    This file is part of libgcj.
4
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7 details.  */
8
9 package gnu.gcj.util;
10
11 import java.util.Enumeration;
12 import java.util.NoSuchElementException;
13
14 public class EnumerationChain implements Enumeration
15 {
16   private Enumeration first_;
17   private Enumeration second_;
18
19   public EnumerationChain (Enumeration first, Enumeration second)
20     {
21       if (first == null
22           || second == null)
23         throw new NullPointerException();
24
25       first_ = first;
26       second_ = second;
27     }
28
29   public synchronized boolean hasMoreElements()
30     {
31       if (first_ == null)
32         return false;
33       else
34         return first_.hasMoreElements();
35     }
36
37   public synchronized Object nextElement() throws NoSuchElementException
38     {
39       while (first_ != null)
40         {
41           if (! first_.hasMoreElements())
42             {
43               first_ = second_;
44               second_ = null;
45             }
46           else 
47             return first_.nextElement();
48         }
49       
50       throw new NoSuchElementException();
51     }
52 }