Coverage Report - org.apache.maven.plugin.checkstyle.CheckstyleResults
 
Classes in this File Line Coverage Branch Coverage Complexity
CheckstyleResults
100%
33/33
100%
10/10
1,667
 
 1  
 package org.apache.maven.plugin.checkstyle;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import com.puppycrawl.tools.checkstyle.api.AuditEvent;
 23  
 import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
 24  
 
 25  
 import java.util.HashMap;
 26  
 import java.util.Iterator;
 27  
 import java.util.LinkedList;
 28  
 import java.util.List;
 29  
 import java.util.Map;
 30  
 
 31  
 /**
 32  
  * Object holding the references to the CheckstyleResults.
 33  
  *
 34  
  * @author <a href="mailto:joakim@erdfelt.net">Joakim Erdfelt</a>
 35  
  * @todo provide fallback to disk based storage if too many results.
 36  
  */
 37  
 public class CheckstyleResults
 38  
 {
 39  
     private Map files;
 40  
 
 41  
     public CheckstyleResults()
 42  28
     {
 43  28
         files = new HashMap();
 44  28
     }
 45  
 
 46  
     public List getFileViolations( String file )
 47  
     {
 48  
         List violations;
 49  
 
 50  144
         if ( this.files.containsKey( file ) )
 51  
         {
 52  80
             violations = (List) this.files.get( file );
 53  
         }
 54  
         else
 55  
         {
 56  64
             violations = new LinkedList();
 57  64
             this.files.put( file, violations );
 58  
         }
 59  
 
 60  144
         return violations;
 61  
     }
 62  
 
 63  
     public void setFileViolations( String file, List violations )
 64  
     {
 65  78
         this.files.put( file, violations );
 66  78
     }
 67  
 
 68  
     public Map getFiles()
 69  
     {
 70  778
         return files;
 71  
     }
 72  
 
 73  
     public void setFiles( Map files )
 74  
     {
 75  2
         this.files = files;
 76  2
     }
 77  
 
 78  
     public int getFileCount()
 79  
     {
 80  38
         return this.files.size();
 81  
     }
 82  
 
 83  
     public long getSeverityCount( SeverityLevel level )
 84  
     {
 85  94
         long count = 0;
 86  
 
 87  94
         Iterator it = this.files.values().iterator();
 88  
 
 89  278
         while ( it.hasNext() )
 90  
         {
 91  184
             List errors = (List) it.next();
 92  
 
 93  184
             count = count + getSeverityCount( errors, level );
 94  
         }
 95  
 
 96  94
         return count;
 97  
     }
 98  
 
 99  
     public long getSeverityCount( String file, SeverityLevel level )
 100  
     {
 101  150
         long count = 0;
 102  
 
 103  150
         if ( !this.files.containsKey( file ) )
 104  
         {
 105  8
             return count;
 106  
         }
 107  
 
 108  142
         List violations = (List) this.files.get( file );
 109  
 
 110  142
         count = getSeverityCount( violations, level );
 111  
 
 112  142
         return count;
 113  
     }
 114  
 
 115  
     public long getSeverityCount( List violations, SeverityLevel level )
 116  
     {
 117  392
         long count = 0;
 118  
 
 119  392
         Iterator it = violations.iterator();
 120  
 
 121  1428
         while ( it.hasNext() )
 122  
         {
 123  1036
             AuditEvent event = (AuditEvent) it.next();
 124  
 
 125  1036
             if ( event.getSeverityLevel().equals( level ) )
 126  
             {
 127  328
                 count++;
 128  
             }
 129  
         }
 130  
 
 131  392
         return count;
 132  
     }
 133  
 }