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

xapi.collect.impl.ArrayIterable Maven / Gradle / Ivy

package xapi.collect.impl;

import java.util.Iterator;

import xapi.except.NotImplemented;

public class ArrayIterable  implements Iterable {

  private final E[] array;

  private final class Itr implements Iterator {
    int pos = 0, end = array.length;
    @Override
    public boolean hasNext() {
      return pos < end;
    }
    @Override
    public E next() {
      return array[pos++];
    }
    @Override
    public void remove() {
      ArrayIterable.this.remove(array[pos-1]);
    }
  }

  public ArrayIterable(E[] array) {
    this.array = array;
  }

  @Override
  public Iterator iterator() {
    return new Itr();
  }

  protected void remove(E key) {
    throw new NotImplemented("ArrayIterable does not support remove");
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy