-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOnProbationDecorator.java
85 lines (70 loc) · 1.59 KB
/
OnProbationDecorator.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package ll;
import java.util.Arrays;
import java.util.Iterator;
public class OnProbationDecorator extends StudentDecorator {
public OnProbationDecorator(Decorator<Student> decorator) {
super(decorator);
}
@Override
public Iterator<Student> iterator() {
return new ListIterator();
}
@Override
public Object[] toArray() {
Iterator<Student> iterator = iterator();
Object[] array = new Object[getSize()];
int counter = 0;
while (iterator.hasNext()) {
array[counter] = iterator.next();
counter++;
}
return array;
}
@SuppressWarnings("unchecked")
@Override
public <E> E[] toArray(E[] a) {
Iterator<Student> iterator = iterator();
int arrayLength = a.length;
int counter = 0;
while (iterator.hasNext()) {
if (arrayLength == counter)
a = Arrays.copyOf(a, getSize());
a[counter] = (E) iterator.next();
counter++;
}
return a;
}
public String toString() {
Iterator<Student> iterator = iterator();
String str = "[";
while (iterator.hasNext()) {
if (iterator.hasNext())
str = str + iterator.next() + " ";
else
str = str + iterator.next();
}
str = str + "]";
return str;
}
private class ListIterator implements Iterator<Student> {
OnProbationFilter filter = new OnProbationFilter(getDecorator()
.iterator());
@Override
public boolean hasNext() {
return filter.hasNext();
}
@Override
public Student next() {
return filter.next();
}
}
public int getSize() {
Iterator<Student> iterator = iterator();
int counter = 0;
while (iterator.hasNext()) {
iterator.next();
counter++;
}
return counter;
}
}