KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > api > SeverityLevelCounter


1 ////////////////////////////////////////////////////////////////////////////////
2
// checkstyle: Checks Java source code for adherence to a set of rules.
3
// Copyright (C) 2001-2005 Oliver Burn
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU Lesser General Public
7
// License as published by the Free Software Foundation; either
8
// version 2.1 of the License, or (at your option) any later version.
9
//
10
// This library is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
// Lesser General Public License for more details.
14
//
15
// You should have received a copy of the GNU Lesser General Public
16
// License along with this library; if not, write to the Free Software
17
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
////////////////////////////////////////////////////////////////////////////////
19
package com.puppycrawl.tools.checkstyle.api;
20
21 /**
22  * An audit listener that counts how many {@link AuditEvent AuditEvents}
23  * of a given severity have been generated.
24  *
25  * @author lkuehne
26  */

27 public final class SeverityLevelCounter implements AuditListener
28 {
29     /** The severity level to watch out for. */
30     private SeverityLevel mLevel;
31
32     /** Keeps track of the number of counted events. */
33     private int mCount;
34
35     /**
36      * Creates a new counter.
37      * @param aLevel the severity level events need to have, must be non-null.
38      */

39     public SeverityLevelCounter(SeverityLevel aLevel)
40     {
41         if (aLevel == null) {
42             throw new IllegalArgumentException JavaDoc();
43         }
44         mLevel = aLevel;
45     }
46
47     /** {@inheritDoc} */
48     public void addError(AuditEvent aEvt)
49     {
50         if (mLevel.equals(aEvt.getSeverityLevel())) {
51             mCount++;
52         }
53     }
54
55     /** {@inheritDoc} */
56     public void addException(AuditEvent aEvt, Throwable JavaDoc aThrowable)
57     {
58         if (SeverityLevel.ERROR.equals(mLevel)) {
59             mCount++;
60         }
61     }
62
63     /** {@inheritDoc} */
64     public void auditStarted(AuditEvent aEvt)
65     {
66         mCount = 0;
67     }
68
69     /** {@inheritDoc} */
70     public void fileStarted(AuditEvent aEvt)
71     {
72     }
73
74     /** {@inheritDoc} */
75     public void auditFinished(AuditEvent aEvt)
76     {
77     }
78
79     /** {@inheritDoc} */
80     public void fileFinished(AuditEvent aEvt)
81     {
82     }
83
84     /**
85      * Returns the number of counted events since audit started.
86      * @return the number of counted events since audit started.
87      */

88     public int getCount()
89     {
90         return mCount;
91     }
92 }
93
Popular Tags