tari

Untitled

Oct 1st, 2010
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. double[][] data;
  2.  
  3. public Iterator<double> iterator() {
  4.     return new FishIterator(data);
  5. }
  6.  
  7. private class FishIterator<double> implements Iterator<double> {
  8.     private int x = 0, xm, y = 0, ym
  9.     public FishIterator(double[][] data) {
  10.         xm = data.length;
  11.         ym = data[0].length;
  12.     }
  13.    
  14.     public boolean hasNext() {
  15.         return !(y == ym-1 && x == xm-1);
  16.     }
  17.    
  18.     public double next() {
  19.         if (++x >= xm) {
  20.             x = 0;
  21.             y++;
  22.             return data[x][y];
  23.         }
  24.     }
  25.    
  26.     public void remove() {
  27.         throw new UnsupportedOperationException();
  28.     }
  29. }
Add Comment
Please, Sign In to add comment