SHARE
TWEET

ArrayObject Iterator

Darker666 Jun 11th, 2014 182 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package cz.cvut.fel.pr2.du3;
  8.  
  9. import cz.cvut.fel.pr2.du3.objects.ArrayObject;
  10. import cz.cvut.fel.pr2.du3.objects.DataObject;
  11. import java.util.Iterator;
  12.  
  13. /**
  14.  *
  15.  * @author Jakub
  16.  */
  17. public class ArrayObjectIterator implements Iterator {
  18.     private DataObject[] data;
  19.     private int index = 0;
  20.     public ArrayObjectIterator(DataObject[] data) {
  21.         this.data = data;
  22.        
  23.     }
  24.     public ArrayObjectIterator(ArrayObject data) {
  25.         this.data = (DataObject[])data.getObjects();
  26.     }
  27.     @Override
  28.     public boolean hasNext() {
  29.         return index+1<data.length;
  30.     }
  31.  
  32.     @Override
  33.     public DataObject next() {
  34.         return data[index++];
  35.     }
  36.  
  37.     @Override
  38.     public void remove() {
  39.         throw new UnsupportedOperationException("Not supported for arrays!");
  40.     }
  41.    
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top