Coverage Report - org.apache.maven.plugin.checkstyle.CheckstyleResults
 
Classes in this File Line Coverage Branch Coverage Complexity
CheckstyleResults
100%
35/35
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  
  * @version $Id: org.apache.maven.plugin.checkstyle.CheckstyleResults.html 816654 2012-05-08 13:54:20Z hboutemy $
 36  
  * @todo provide fallback to disk based storage if too many results.
 37  
  */
 38  
 public class CheckstyleResults
 39  
 {
 40  
     private Map files;
 41  
 
 42  
     public CheckstyleResults()
 43  14
     {
 44  14
         files = new HashMap();
 45  14
     }
 46  
 
 47  
     public List getFileViolations( String file )
 48  
     {
 49  
         List violations;
 50  
 
 51  47
         if ( this.files.containsKey( file ) )
 52  
         {
 53  22
             violations = (List) this.files.get( file );
 54  
         }
 55  
         else
 56  
         {
 57  25
             violations = new LinkedList();
 58  25
             this.files.put( file, violations );
 59  
         }
 60  
 
 61  47
         return violations;
 62  
     }
 63  
 
 64  
     public void setFileViolations( String file, List violations )
 65  
     {
 66  25
         this.files.put( file, violations );
 67  25
     }
 68  
 
 69  
     public Map getFiles()
 70  
     {
 71  389
         return files;
 72  
     }
 73  
 
 74  
     public void setFiles( Map files )
 75  
     {
 76  1
         this.files = files;
 77  1
     }
 78  
 
 79  
     public int getFileCount()
 80  
     {
 81  19
         return this.files.size();
 82  
     }
 83  
 
 84  
     public long getSeverityCount( SeverityLevel level )
 85  
     {
 86  47
         long count = 0;
 87  
 
 88  47
         Iterator it = this.files.values().iterator();
 89  
 
 90  106
         while ( it.hasNext() )
 91  
         {
 92  59
             List errors = (List) it.next();
 93  
 
 94  59
             count = count + getSeverityCount( errors, level );
 95  59
         }
 96  
 
 97  47
         return count;
 98  
     }
 99  
 
 100  
     public long getSeverityCount( String file, SeverityLevel level )
 101  
     {
 102  57
         long count = 0;
 103  
 
 104  57
         if ( !this.files.containsKey( file ) )
 105  
         {
 106  4
             return count;
 107  
         }
 108  
 
 109  53
         List violations = (List) this.files.get( file );
 110  
 
 111  53
         count = getSeverityCount( violations, level );
 112  
 
 113  53
         return count;
 114  
     }
 115  
 
 116  
     public long getSeverityCount( List violations, SeverityLevel level )
 117  
     {
 118  130
         long count = 0;
 119  
 
 120  130
         Iterator it = violations.iterator();
 121  
 
 122  648
         while ( it.hasNext() )
 123  
         {
 124  518
             AuditEvent event = (AuditEvent) it.next();
 125  
 
 126  518
             if ( event.getSeverityLevel().equals( level ) )
 127  
             {
 128  164
                 count++;
 129  
             }
 130  518
         }
 131  
 
 132  130
         return count;
 133  
     }
 134  
 }