publicVector2D(List<List<Integer>> vec2d){ iter = vec2d.iterator(); cur = iter.hasNext() ? iter.next().iterator() : null; }
@Override public Integer next(){ hasNext(); return cur.next(); }
@Override publicbooleanhasNext(){ // using while is neccesary for case like [[], [], [-1]] // note double paranthesis below while ((cur == null || !cur.hasNext()) && iter.hasNext()){ cur = iter.next().iterator(); } return cur != null && cur.hasNext(); } }
/** * Your Vector2D object will be instantiated and called as such: * Vector2D i = new Vector2D(vec2d); * while (i.hasNext()) v[f()] = i.next(); */