forked from MohammadSianaki/Design-Pattern-In-Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannelCollectionImpl.java
More file actions
54 lines (43 loc) · 1.39 KB
/
Copy pathChannelCollectionImpl.java
File metadata and controls
54 lines (43 loc) · 1.39 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
import java.util.ArrayList;
import java.util.List;
class ChannelCollectionImpl implements ChannelCollection {
private List<Channel> channelList = new ArrayList<>();
@Override
public void addChannel(Channel channel) {
channelList.add(channel);
}
@Override
public void removeChannel(Channel channel) {
channelList.remove(channel);
}
@Override
public ChannelIterator iterator(ChannelType channelType) {
return new ChannelIteratorImpl(channelType, channelList);
}
private class ChannelIteratorImpl implements ChannelIterator {
private ChannelType type;
private List<Channel> channelList;
private int position;
public ChannelIteratorImpl(ChannelType type, List<Channel> channelsList) {
this.type = type;
this.channelList = channelsList;
}
@Override
public boolean hasNext() {
while (position < channelList.size()) {
Channel c = channelList.get(position);
if (c.getTYPE().equals(type) || type.equals(ChannelType.ALL)) {
return true;
} else
position++;
}
return false;
}
@Override
public Channel next() {
Channel ch = channelList.get(position);
position++;
return ch;
}
}
}