All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.files.ListIteratorIterable Maven / Gradle / Ivy

Go to download

The Files.com Java client library provides convenient access to the Files.com API from JVM based applications.

There is a newer version: 1.4.123
Show newest version
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