1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.henri.jbcs;
22
23 import java.util.HashMap;
24 import java.util.Map;
25
26 import com.puppycrawl.tools.checkstyle.api.AuditEvent;
27 import com.puppycrawl.tools.checkstyle.api.AuditListener;
28 import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
29
30 /***
31 * The class is to handle user action.
32 *
33 * @author Henri Tremblay
34 * @version $Revision: 1.2 $ $Date: 2003/12/07 16:59:10 $
35 */
36 public class FailureCountListener implements AuditListener
37 {
38 /*** Initial map containing all counters at 0 */
39 private static final Map INITIAL_FAILURE_MAP = new HashMap(8);
40
41 static {
42 INITIAL_FAILURE_MAP.put(SeverityLevel.IGNORE, new Integer(0));
43 INITIAL_FAILURE_MAP.put(SeverityLevel.INFO, new Integer(0));
44 INITIAL_FAILURE_MAP.put(SeverityLevel.WARNING, new Integer(0));
45 INITIAL_FAILURE_MAP.put(SeverityLevel.ERROR, new Integer(0));
46 }
47
48 /*** Contains the number of failures by SeverityLevel */
49 private Map m_totalFailures = initFailureMap();
50
51 /*** Contains the number of failures for the current file */
52 private Map m_fileFailures = initFailureMap();
53
54 public FailureCountListener() {
55 }
56
57 private Map initFailureMap() {
58 Map failureMap = new HashMap(8);
59 failureMap.putAll(INITIAL_FAILURE_MAP);
60 return failureMap;
61 }
62
63 public int getFileFailureCount(SeverityLevel level) {
64 return ((Integer) m_fileFailures.get(level)).intValue();
65 }
66
67 public int getTotalFailureCount(SeverityLevel level) {
68 return ((Integer) m_totalFailures.get(level)).intValue();
69 }
70
71 public void auditStarted(AuditEvent evt) {
72 m_totalFailures = initFailureMap();
73 }
74
75 public void auditFinished(AuditEvent evt) {
76 }
77
78 public void fileStarted(AuditEvent evt) {
79 m_fileFailures = initFailureMap();
80 }
81
82 public void fileFinished(AuditEvent evt) {
83
84 }
85
86 public void addError(AuditEvent evt) {
87 m_fileFailures.put(evt.getSeverityLevel(), new Integer(((Integer) m_fileFailures.get(evt.getSeverityLevel())).intValue() + 1));
88 m_totalFailures.put(evt.getSeverityLevel(), new Integer(((Integer) m_totalFailures.get(evt.getSeverityLevel())).intValue() + 1));
89 }
90
91 public void addException(AuditEvent evt, Throwable ex) {
92 }
93 }