1 50 package org.apache.avalon.excalibur.collections; 51 52 import java.util.Enumeration ; 53 import java.util.List ; 54 import java.util.NoSuchElementException ; 55 56 65 public final class ArrayEnumeration 66 implements Enumeration 67 { 68 protected Object [] m_elements; 69 protected int m_index; 70 71 public ArrayEnumeration( final List elements ) 72 { 73 m_elements = elements.toArray(); 74 } 75 76 public ArrayEnumeration( final Object [] elements ) 77 { 78 m_elements = elements; 79 } 80 81 public boolean hasMoreElements() 82 { 83 return ( m_index < m_elements.length ); 84 } 85 86 public Object nextElement() 87 { 88 if( !hasMoreElements() ) 89 { 90 throw new NoSuchElementException ( "No more elements exist" ); 91 } 92 93 return m_elements[ m_index++ ]; 94 } 95 } 96 97 | Popular Tags |