Skip to content

Commit 108d92a

Browse files
unknownunknown
authored andcommitted
some patterns are added and google question is added
1 parent 8b8c415 commit 108d92a

File tree

88 files changed

+1285
-573
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1285
-573
lines changed

.idea/workspace.xml

Lines changed: 396 additions & 565 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package Iterator.IteratorChannelExample;
2+
3+
/**
4+
* Created by jihun.im on 2017-04-28.
5+
*/
6+
public class Channel {
7+
private double frequency;
8+
private ChannelTypeEnum TYPE;
9+
10+
public Channel(double freq, ChannelTypeEnum type){
11+
this.frequency=freq;
12+
this.TYPE=type;
13+
}
14+
15+
public double getFrequency() {
16+
return frequency;
17+
}
18+
19+
public ChannelTypeEnum getTYPE() {
20+
return TYPE;
21+
}
22+
23+
@Override
24+
public String toString(){
25+
return "Frequency="+this.frequency+", Type="+this.TYPE;
26+
}
27+
28+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package Iterator.IteratorChannelExample;
2+
3+
/**
4+
* Created by jihun.im on 2017-04-28.
5+
*/
6+
public interface ChannelCollection {
7+
public void addChannel(Channel c);
8+
public void removeChannel(Channel c);
9+
public ChannelIterator iterator(ChannelTypeEnum type);
10+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package Iterator.IteratorChannelExample;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
/**
7+
* Created by jihun.im on 2017-04-28.
8+
*/
9+
public class ChannelCollectionImpl implements ChannelCollection {
10+
11+
12+
private List<Channel> channelList;
13+
14+
public ChannelCollectionImpl() {
15+
channelList = new ArrayList<Channel>();
16+
}
17+
18+
@Override
19+
public void addChannel(Channel c) {
20+
channelList.add(c);
21+
}
22+
23+
@Override
24+
public void removeChannel(Channel c) {
25+
channelList.remove(c);
26+
}
27+
28+
@Override
29+
public ChannelIterator iterator(ChannelTypeEnum type) {
30+
return new ChannelIteratorImpl(type, this.channelList);
31+
}
32+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package Iterator.IteratorChannelExample;
2+
3+
/**
4+
* Created by jihun.im on 2017-04-28.
5+
*/
6+
public interface ChannelIterator {
7+
boolean hasNext();
8+
Channel next();
9+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package Iterator.IteratorChannelExample;
2+
3+
import java.util.List;
4+
5+
/**
6+
* Created by jihun.im on 2017-04-28.
7+
*/
8+
public class ChannelIteratorImpl implements ChannelIterator {
9+
private ChannelTypeEnum type;
10+
private List<Channel> channels;
11+
private int position;
12+
13+
public ChannelIteratorImpl(ChannelTypeEnum ty,
14+
List<Channel> channelsList) {
15+
this.type = ty;
16+
this.channels = channelsList;
17+
}
18+
19+
@Override
20+
public boolean hasNext() {
21+
while (position < channels.size()) {
22+
Channel c = channels.get(position);
23+
if (c.getTYPE().equals(type) || type.equals(ChannelTypeEnum.ALL)) {
24+
return true;
25+
} else
26+
position++;
27+
}
28+
return false;
29+
}
30+
31+
@Override
32+
public Channel next() {
33+
Channel c = channels.get(position);
34+
position++;
35+
return c;
36+
}
37+
38+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package Iterator.IteratorChannelExample;
2+
3+
/**
4+
* Created by jihun.im on 2017-04-28.
5+
*/
6+
public enum ChannelTypeEnum {
7+
ENGLISH, HINDI, FRENCH, ALL;
8+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package Iterator.IteratorChannelExample;
2+
3+
/**
4+
* Created by jihun.im on 2017-04-28.
5+
*/
6+
public class IteratorMain {
7+
8+
public static void main(String[] args) {
9+
ChannelCollection channels = populateChannels();
10+
ChannelIterator baseIterator = channels.iterator(ChannelTypeEnum.ALL);
11+
while (baseIterator.hasNext()) {
12+
Channel c = baseIterator.next();
13+
System.out.println(c.toString());
14+
}
15+
System.out.println("******");
16+
// Channel Type Iterator
17+
ChannelIterator englishIterator = channels.iterator(ChannelTypeEnum.ENGLISH);
18+
while (englishIterator.hasNext()) {
19+
Channel c = englishIterator.next();
20+
System.out.println(c.toString());
21+
}
22+
}
23+
24+
private static ChannelCollection populateChannels() {
25+
ChannelCollection channels = new ChannelCollectionImpl();
26+
channels.addChannel(new Channel(98.5, ChannelTypeEnum.ENGLISH));
27+
channels.addChannel(new Channel(99.5, ChannelTypeEnum.HINDI));
28+
channels.addChannel(new Channel(100.5, ChannelTypeEnum.FRENCH));
29+
channels.addChannel(new Channel(101.5, ChannelTypeEnum.ENGLISH));
30+
channels.addChannel(new Channel(102.5, ChannelTypeEnum.HINDI));
31+
channels.addChannel(new Channel(103.5, ChannelTypeEnum.FRENCH));
32+
channels.addChannel(new Channel(104.5, ChannelTypeEnum.ENGLISH));
33+
channels.addChannel(new Channel(105.5, ChannelTypeEnum.HINDI));
34+
channels.addChannel(new Channel(106.5, ChannelTypeEnum.FRENCH));
35+
return channels;
36+
}
37+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package Iterator.IteratorChannelExampleUsingNativeIterator;
2+
3+
/**
4+
* Created by jihun.im on 2017-04-28.
5+
*/
6+
public class Channel {
7+
private double frequency;
8+
private ChannelTypeEnum TYPE;
9+
10+
public Channel(double freq, ChannelTypeEnum type){
11+
this.frequency=freq;
12+
this.TYPE=type;
13+
}
14+
15+
public double getFrequency() {
16+
return frequency;
17+
}
18+
19+
public ChannelTypeEnum getTYPE() {
20+
return TYPE;
21+
}
22+
23+
@Override
24+
public String toString(){
25+
return "Frequency="+this.frequency+", Type="+this.TYPE;
26+
}
27+
28+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package Iterator.IteratorChannelExampleUsingNativeIterator;
2+
3+
import java.util.Iterator;
4+
5+
/**
6+
* Created by jihun.im on 2017-04-28.
7+
*/
8+
public interface ChannelCollection {
9+
public void addChannel(Channel c);
10+
public void removeChannel(Channel c);
11+
public Iterator iterator(ChannelTypeEnum type);
12+
}

0 commit comments

Comments
 (0)