KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > spi > ior > IdentifiableContainerBase


1 /*
2  * @(#)IdentifiableContainerBase.java 1.7 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.spi.ior;
9
10 import java.util.List JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Iterator JavaDoc;
13
14 import com.sun.corba.se.impl.ior.FreezableList ;
15
16 import com.sun.corba.se.spi.ior.TaggedComponent ;
17 import com.sun.corba.se.spi.ior.Identifiable ;
18
19 /** Convenience class for defining objects that contain lists of Identifiables.
20  * Mainly implements iteratorById. Also note that the constructor creates the
21  * list, which here is always an ArrayList, as this is much more efficient overall
22  * for short lists.
23  * @author Ken Cavanaugh
24  */

25 public class IdentifiableContainerBase extends FreezableList
26 {
27     /** Create this class with an empty list of identifiables.
28      * The current implementation uses an ArrayList.
29      */

30     public IdentifiableContainerBase()
31     {
32     super( new ArrayList JavaDoc() ) ;
33     }
34     
35     /** Return an iterator which iterates over all contained Identifiables
36      * with type given by id.
37      */

38     public Iterator JavaDoc iteratorById( final int id)
39     {
40     return new Iterator JavaDoc() {
41         Iterator JavaDoc iter = IdentifiableContainerBase.this.iterator() ;
42         Object JavaDoc current = advance() ;
43
44         private Object JavaDoc advance()
45         {
46         while (iter.hasNext()) {
47             Identifiable ide = (Identifiable)(iter.next()) ;
48             if (ide.getId() == id)
49             return ide ;
50         }
51
52         return null ;
53         }
54
55         public boolean hasNext()
56         {
57         return current != null ;
58         }
59
60         public Object JavaDoc next()
61         {
62         Object JavaDoc result = current ;
63         current = advance() ;
64         return result ;
65         }
66
67         public void remove()
68         {
69         iter.remove() ;
70         }
71     } ;
72     }
73 }
74
Popular Tags