net.sf.javagimmicks.collections.composite.CompositeEnumeration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gimmicks Show documentation
Show all versions of gimmicks Show documentation
Utility classes, APIs and tools for Java
package net.sf.javagimmicks.collections.composite;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
class CompositeEnumeration implements Enumeration
{
protected final Iterator> _enumerations;
protected Enumeration _currentEnumeration;
protected Enumeration _nextEnumeration;
CompositeEnumeration(List> enumerations)
{
_enumerations = enumerations.iterator();
findNextEnumeration();
}
public boolean hasMoreElements()
{
if(_currentEnumeration != null && _currentEnumeration.hasMoreElements())
{
return true;
}
findNextEnumeration();
return _nextEnumeration != null && _nextEnumeration.hasMoreElements();
}
public E nextElement()
{
if(!hasMoreElements())
{
throw new NoSuchElementException();
}
return moveNext();
}
protected void findNextEnumeration()
{
if(_nextEnumeration != null)
{
return;
}
while(_enumerations.hasNext())
{
_nextEnumeration = _enumerations.next();
if(_nextEnumeration.hasMoreElements())
{
break;
}
}
}
protected E moveNext()
{
if(_nextEnumeration != null)
{
_currentEnumeration = _nextEnumeration;
_nextEnumeration = null;
}
return _currentEnumeration.nextElement();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy