-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProductIterator.java
58 lines (49 loc) · 1.27 KB
/
ProductIterator.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* SER-515 Product Iterator to implement iterator pattern
*
* @author Nirmit Agrawal, [email protected]
* @version 1.3
* @since 10-17-2022
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
public class ProductIterator extends ListIterator {
ArrayList<String> prod = new ArrayList<>();
int a = 0;
int size;
ProductIterator()
{
try {
Scanner s = new Scanner(new File("C:\\Users\\DELL\\Desktop\\Nirmit\\ASU\\SER 515\\Assignments\\Design Pattern - Individual\\ProductInfo.txt"));
while (s.hasNext()) {
prod.add(s.next());
this.size++;
}
s.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
@SuppressWarnings("rawtypes")
public boolean HasNext(Iterator iterator) {
this.a = this.a+1;
return this.a < this.size;
}
@SuppressWarnings("rawtypes")
public void MoveToHead(Iterator iterator) {
System.out.println("Head Moved..");
}
@SuppressWarnings("rawtypes")
public String Next(Iterator iterator) {
return this.prod.get(a);
}
@SuppressWarnings("rawtypes")
public void Remove(Iterator iterator) {
if (this.HasNext(iterator)) {
iterator.next();
}
}
}