| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| SeverityLevelCounter |
|
| 1.5;1.5 |
| 1 | //////////////////////////////////////////////////////////////////////////////// | |
| 2 | // checkstyle: Checks Java source code for adherence to a set of rules. | |
| 3 | // Copyright (C) 2001-2014 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 | 602 | { |
| 41 | 602 | if (aLevel == null) { |
| 42 | 0 | throw new IllegalArgumentException(); |
| 43 | } | |
| 44 | 602 | mLevel = aLevel; |
| 45 | 602 | } |
| 46 | ||
| 47 | /** {@inheritDoc} */ | |
| 48 | public void addError(AuditEvent aEvt) | |
| 49 | { | |
| 50 | 3388 | if (mLevel.equals(aEvt.getSeverityLevel())) { |
| 51 | 3375 | mCount++; |
| 52 | } | |
| 53 | 3388 | } |
| 54 | ||
| 55 | /** {@inheritDoc} */ | |
| 56 | public void addException(AuditEvent aEvt, Throwable aThrowable) | |
| 57 | { | |
| 58 | 0 | if (SeverityLevel.ERROR.equals(mLevel)) { |
| 59 | 0 | mCount++; |
| 60 | } | |
| 61 | 0 | } |
| 62 | ||
| 63 | /** {@inheritDoc} */ | |
| 64 | public void auditStarted(AuditEvent aEvt) | |
| 65 | { | |
| 66 | 585 | mCount = 0; |
| 67 | 585 | } |
| 68 | ||
| 69 | /** {@inheritDoc} */ | |
| 70 | public void fileStarted(AuditEvent aEvt) | |
| 71 | { | |
| 72 | 596 | } |
| 73 | ||
| 74 | /** {@inheritDoc} */ | |
| 75 | public void auditFinished(AuditEvent aEvt) | |
| 76 | { | |
| 77 | 585 | } |
| 78 | ||
| 79 | /** {@inheritDoc} */ | |
| 80 | public void fileFinished(AuditEvent aEvt) | |
| 81 | { | |
| 82 | 596 | } |
| 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 | 583 | return mCount; |
| 91 | } | |
| 92 | } |