KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > util > CollectionsUtil


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2005 Fossil E-Commerce, http://www.fossilec.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: CollectionsUtil.java 74 2006-01-17 17:12:07Z rmarins $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.util;
23
24 import java.util.Enumeration JavaDoc;
25 import java.util.NoSuchElementException JavaDoc;
26
27 /**
28  * @author Rafael Marins
29  * @version $Rev: 74 $ $Date: 2006-01-17 17:12:07Z $
30  */

31 public class CollectionsUtil {
32
33     private static final class CompoundEnumeration implements Enumeration JavaDoc {
34
35         private final Enumeration JavaDoc e1, e2;
36
37         public CompoundEnumeration(Enumeration JavaDoc e1, Enumeration JavaDoc e2) {
38             this.e1 = e1;
39             this.e2 = e2;
40         }
41
42         public boolean hasMoreElements() {
43             return e1.hasMoreElements() || e2.hasMoreElements();
44         }
45
46         public Object JavaDoc nextElement() throws NoSuchElementException JavaDoc {
47             if (e1.hasMoreElements()) {
48                 return e1.nextElement();
49             } else {
50                 return e2.nextElement();
51             }
52         }
53
54     }
55
56     public static Enumeration JavaDoc append(Enumeration JavaDoc e1, Enumeration JavaDoc e2) {
57         return new CompoundEnumeration(e1, e2);
58     }
59
60 }
61
Popular Tags