1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.rawdata.stat;
19
20 import java.util.Collection;
21 import java.util.HashMap;
22
23 import org.apache.log4j.Logger;
24
25
26
27
28
29
30
31 public final class ErrorRegistry {
32
33 private static final ErrorRegistry INSTANCE = new ErrorRegistry();
34
35 private static Logger log = Logger.getLogger(ErrorRegistry.class);
36
37 private HashMap<Integer, ErrorType> errors = new HashMap<Integer, ErrorType>();
38
39 private ErrorRegistry() {
40
41 }
42
43 public static ErrorRegistry getInstance() {
44 return INSTANCE;
45 }
46
47
48
49
50
51
52
53
54
55 public void register(ErrorType err) throws ErrorAlreadyExistsException {
56 if (errors.containsKey(err.getCode())) {
57 throw new ErrorAlreadyExistsException(err);
58 }
59 errors.put(err.getCode(), err);
60
61 log.debug("New error type registered: error code: " + err.getCode() +
62 "; error message" + err.getMessage() + ";");
63
64 }
65
66
67
68
69
70
71
72
73 public boolean containsErrorCode(Integer code) {
74 return errors.containsKey(code);
75 }
76
77
78
79
80
81
82
83
84 public ErrorType get(Integer code) {
85 return errors.get(code);
86 }
87
88
89
90
91
92
93 public Collection<ErrorType> getAll() {
94 return errors.values();
95 }
96
97 }