-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObserverFactory.java
43 lines (37 loc) · 993 Bytes
/
ObserverFactory.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
/**
* Factory singleton
*/
public class ObserverFactory {
private static ObserverFactory instance = null;
private ObserverFactory(){};
public static ObserverFactory getInstance() {
if(instance == null) {
return new ObserverFactory();
}
return null;
}
/**
* Creaza observatori
*/
public Observer makeObserver(String id, String expression) {
Observer newObserver = null;
if (isInteger(id) == true){
return new Observer(id, expression);
}
return null;
}
/**
* Verifica daca id-ul este numar intreg
*/
public static boolean isInteger(String s) {
try {
Integer.parseInt(s);
} catch(NumberFormatException e1) {
return false;
} catch(NullPointerException e2) {
return false;
}
// only got here if we didn't return false
return true;
}
}