com.files.ListIteratorIterable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of files-sdk Show documentation
Show all versions of files-sdk Show documentation
The Files.com Java client library provides convenient access to the Files.com API from JVM based applications.
package com.files;
import java.util.Iterator;
import java.util.NoSuchElementException;
public class ListIteratorIterable implements Iterable {
private final ListIterator listIterator;
public ListIteratorIterable(ListIterator listIterator) {
this.listIterator = listIterator;
listIterator.loadNextPage();
}
@Override
public Iterator iterator() {
return new Iterator() {
private int index = -1;
@Override
public boolean hasNext() {
return listIterator.hasNextPage() || this.index < listIterator.data.size() - 1;
}
@Override
public T next() {
this.index++;
if (this.index >= listIterator.data.size()) {
if (listIterator.hasNextPage()) {
listIterator.loadNextPage();
this.index = 0;
} else {
throw new NoSuchElementException("There are no more items in the list.");
}
}
return listIterator.data.get(index);
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy