Skip to content
Snippets Groups Projects
CellGridIterator.java 1.05 KiB
Newer Older
  • Learn to ignore specific revisions
  • BEL KHALIFA Mohamed amine's avatar
    BEL KHALIFA Mohamed amine committed
    package model;
    
    import java.util.Iterator;
    
    public class CellGridIterator implements Iterator<Cell> {
    
    EL GAOUAL Zaid's avatar
    EL GAOUAL Zaid committed
    
    
        private ArrayGrid grid;
        private int PrvColmn;
        private int PrvRow;
        private int ActColmn;
        private int ActRow;
    
    
        CellGridIterator(ArrayGrid grid){
    
            PrvRow=ActRow=0;
            PrvColmn=ActColmn=0;
            this.grid=grid;
    
    
    
    
    BEL KHALIFA Mohamed amine's avatar
    BEL KHALIFA Mohamed amine committed
        }
    
    
    EL GAOUAL Zaid's avatar
    EL GAOUAL Zaid committed
    
    
    
    
    
        public
        boolean hasNext ( ) {
            return hasNextRow ()|| hasNextCol ();
        }
    
        public
        Boolean hasNextCol (){
    
    
            return !(grid.getNumberOfColumns ()==ActColmn);
    
    
    BEL KHALIFA Mohamed amine's avatar
    BEL KHALIFA Mohamed amine committed
        }
    
    
    EL GAOUAL Zaid's avatar
    EL GAOUAL Zaid committed
        public Boolean hasNextRow(){
    
    
            return !(grid.getNumberOfRows ()-1==this.ActRow);
    
        }
    
    
        public   Cell next ( ) {
    
            if ( hasNextCol ( ) ) {
                PrvColmn=ActColmn;
                ActColmn++;
                return grid.getCell (PrvRow,PrvColmn );
    
    
            }
            if ( hasNextRow ( ) ) {
                ActRow++;
    
                ActColmn=1;
                PrvColmn=0;
    
    
                PrvRow=ActRow;
    
                return grid.getCell ( PrvRow , PrvColmn );
    
    
    
    BEL KHALIFA Mohamed amine's avatar
    BEL KHALIFA Mohamed amine committed
            }
    
            return null;
    
    EL GAOUAL Zaid's avatar
    EL GAOUAL Zaid committed
    
    
    BEL KHALIFA Mohamed amine's avatar
    BEL KHALIFA Mohamed amine committed
        }
    
    
    EL GAOUAL Zaid's avatar
    EL GAOUAL Zaid committed
    
    
    BEL KHALIFA Mohamed amine's avatar
    BEL KHALIFA Mohamed amine committed
    }