View Javadoc

1   /*
2    * JBCS - A JBuilder Plugin for Checkstyle
3    *
4    * This program is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU General Public License
6    * as published by the Free Software Foundation; either version 2
7    * of the License, or (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program; if not, write to the Free Software
16   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17   *
18   * Copyright © 2003
19   * Henri Tremblay
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  }