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. package com.sun.corba.se.spi.ior;
  8. import java.util.List;
  9. import java.util.ArrayList;
  10. import java.util.Iterator;
  11. import com.sun.corba.se.impl.ior.FreezableList ;
  12. import com.sun.corba.se.spi.ior.TaggedComponent ;
  13. import com.sun.corba.se.spi.ior.Identifiable ;
  14. /** Convenience class for defining objects that contain lists of Identifiables.
  15. * Mainly implements iteratorById. Also note that the constructor creates the
  16. * list, which here is always an ArrayList, as this is much more efficient overall
  17. * for short lists.
  18. * @author Ken Cavanaugh
  19. */
  20. public class IdentifiableContainerBase extends FreezableList
  21. {
  22. /** Create this class with an empty list of identifiables.
  23. * The current implementation uses an ArrayList.
  24. */
  25. public IdentifiableContainerBase()
  26. {
  27. super( new ArrayList() ) ;
  28. }
  29. /** Return an iterator which iterates over all contained Identifiables
  30. * with type given by id.
  31. */
  32. public Iterator iteratorById( final int id)
  33. {
  34. return new Iterator() {
  35. Iterator iter = IdentifiableContainerBase.this.iterator() ;
  36. Object current = advance() ;
  37. private Object advance()
  38. {
  39. while (iter.hasNext()) {
  40. Identifiable ide = (Identifiable)(iter.next()) ;
  41. if (ide.getId() == id)
  42. return ide ;
  43. }
  44. return null ;
  45. }
  46. public boolean hasNext()
  47. {
  48. return current != null ;
  49. }
  50. public Object next()
  51. {
  52. Object result = current ;
  53. current = advance() ;
  54. return result ;
  55. }
  56. public void remove()
  57. {
  58. iter.remove() ;
  59. }
  60. } ;
  61. }
  62. }