forked from DanH957/ATM-Machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccountIterator.java
44 lines (29 loc) · 1022 Bytes
/
AccountIterator.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.ArrayList;
//This class is responsible the Iterator design pattern
public class AccountIterator implements Iterator {
ArrayList<Account> accounts;
public AccountIterator(ArrayList<Account> accounts2) {
this.accounts = accounts2;
} //This obtains an already existing ArrayList for use within this class.
//This function returns true if the ArrayList has a space next to the current one
public boolean hasNext(int position) {
if (position >= accounts.size()) {
return false;
} else {
return true;
}
}
@Override //This function iterates to the next position in the ArrayList.
public Object next(int position) {
Account AccountItem = accounts.get(position);
return AccountItem;
}
@Override
//This function checks when the position is at 0, and prevents the user from going back even further.
public boolean hasPrev(int position) {
if(position == 0)
return false;
else
return true;
}
}