Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. public class IteratorCala implements Iterator {
  2.     private Integer currentPosition = 0;
  3.  
  4.     public boolean IsDone(){
  5.         if(currentPosition + 1 == 10){
  6.             return true;
  7.         } else {
  8.             return false;
  9.         }
  10.     }
  11.  
  12.     public Integer First(Integer[] tablica){
  13.         //System.out.println(tablica[0]);
  14.         if(IsDone() == false){
  15.             return tablica[0];
  16.         } else {
  17.             throw new ArrayIndexOutOfBoundsException("Brak elementów w tablicy");
  18.         }
  19.     }
  20.  
  21.     public Integer Next(Integer[] tablica){
  22.         if(IsDone() == true){
  23.             throw new ArrayIndexOutOfBoundsException("Koniec tablicy");
  24.         } else {
  25.             //System.out.println(currentPosition);
  26.             currentPosition++;
  27.             return tablica[currentPosition];
  28.         }
  29.     }
  30.  
  31.     public Integer CurrentItem(Integer[] tablica){
  32.         if(IsDone() == false){
  33.             return tablica[currentPosition];
  34.         } else {
  35.             throw new ArrayIndexOutOfBoundsException("Koniec tablicy");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement