![JAR search and dependency download from the Maven repository](/logo.png)
de.tsl2.nano.collection.CyclingIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tsl2.nano.datastructure Show documentation
Show all versions of tsl2.nano.datastructure Show documentation
optimized implementations for trees, collections, arrays, historized input
The newest version!
/*
* File: $HeadURL$
* Id : $Id$
*
* created by: Thomas Schneider
* created on: Jun 25, 2013
*
* Copyright: (c) Thomas Schneider 2013, all rights reserved
*/
package de.tsl2.nano.collection;
import java.util.Collection;
import java.util.Iterator;
/**
* It is an endless looping iterator - useful for switches and more.
*
* @author Thomas Schneider
* @version $Revision$
*/
public class CyclingIterator implements Iterator {
Collection parent;
Iterator parentIt;
/**
* constructor
* @param parent
*/
public CyclingIterator(Collection parent) {
super();
this.parent = parent;
this.parentIt = parent.iterator();
}
@Override
public boolean hasNext() {
return parent.size() > 0;
}
@Override
public E next() {
return parentIt.hasNext() ? parentIt.next() : (parentIt = parent.iterator()).next();
}
@Override
public void remove() {
parentIt.remove();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy