-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyStackTest.java
More file actions
59 lines (42 loc) · 1.41 KB
/
Copy pathMyStackTest.java
File metadata and controls
59 lines (42 loc) · 1.41 KB
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
59
package examples;
public class MyStackTest {
public static void main(String[] args) {
// Define and initialize queues
LinkedList<Integer> qev1, qev2, qcv1, qcv2;
qev1 = new LinkedList<>();
qev2 = new LinkedList<>();
qcv1 = new LinkedList<>();
qcv2 = new LinkedList<>();
qev1.add(100);
qev1.add(200);
qev1.add(300);
qev1.add(300);
qev1.add(300);
qev1.add(300);
// Get an iterator for the queue
Iterator<Integer> iterator = qev1.iterator();
try {
iterator.remove(); // Error no call to next before remove
}
catch(UnsupportedOperationException e) {
System.out.println("Calling Iterator.remove() and throwing exception.");
}
}
}
// @ExternalRefinementsFor("java.util.Iterator")
// @StateSet({"start", "ready", "inNext"})
class Iterator<N> {
// @StateRefinement(to = "start(this)")
public Iterator(){}
// @StateRefinement(to = "ready(this)")
public boolean hasNext(){return true;}
// @StateRefinement(from = "ready(this)", to = "inNext(this)")
public Object next(){return null;}
// @StateRefinement(from = "inNext(this)", to = "start(this)")
public void remove(){}
}
// @ExternalRefinementsFor("java.util.LinkedList")
class LinkedList<T> {
public Iterator<T> iterator(){return null;}
public void add(T t){}
}