-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainClass.java
49 lines (44 loc) · 1.78 KB
/
MainClass.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
import java.util.*;
/**
* Created by bianca on 12/5/2017.
*/
public class MainClass {
public static void main(String[] args) {
//creez o instanta a clasei SubjectF
IFactory factory = SingletonFactory.getInstance();;
SubjectF f = factory.create();
Scanner scan = new Scanner(System.in);
String buffer = scan.nextLine();
if (buffer.equals("begin")){
//citesc de la System.in cate o linie
buffer = scan.nextLine();
while (!buffer.equals("end")){
//separ in string-uri dupa " " pentru a determina comenziile
String[] tokens = buffer.split(" ");
switch (tokens[0]) { //comanda
case "feed":
f.addFeed(new Feed(tokens[1], tokens[2]));
break;
case "create_obs":
int length = tokens.length;
for (int i = 3; i< length; i++) {
tokens[2] += " " + tokens[i];
tokens[i] = null;
} //reconstruiesc filtru care este separat dupa " "
f.registerObserver(new ObserverStock(Integer.parseInt
(tokens[1]), tokens[2]));
break;
case "delete_obs":
f.removeObserver(Integer.parseInt(tokens[1]));
break;
case "print":
f.printObserver(Integer.parseInt(tokens[1]));
break;
default:
break;
}
buffer = scan.nextLine();
}
}
}
}