package iterator; import arraylist.ArrayIndexList; import position.Position; import java.util.Iterator; import java.util.NoSuchElementException; /** * Created with MONSTER. * User: xgiovio * Date: 06/04/2014 * Time: 21:13 */ // generic iterable list creation using an arraylist. the class calling this metod should pass an array of Position public class IterablePositionIndexList implements Iterable> { Position[] new_structure = null; public IterablePositionIndexList (Position[] in){ new_structure = in; } @Override public Iterator> iterator() { return new getpositionsiterator(new_structure); } class getpositionsiterator implements Iterator>{ public getpositionsiterator(Position[] in_elements){ for (int i = 0;i< in_elements.length;i++){ data.add(i,in_elements[i]); } } @Override public boolean hasNext() { if (pos <= data.size() -2){ return true; }else { return false; } } @Override public Position next() throws NoSuchElementException { if (hasNext()){ pos++; return data.get(pos); }else { throw new NoSuchElementException(); } } @Override public void remove() { throw new UnsupportedOperationException (); } private ArrayIndexList> data = new ArrayIndexList>(); private int pos = -1; } }