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  14
     {
 43  14
         files = new HashMap();
 44  14
     }
 45  
 
 46  
     public List getFileViolations( String file )
 47  
     {
 48  
         List violations;
 49  
 
 50  72
         if ( this.files.containsKey( file ) )
 51  
         {
 52  40
             violations = (List) this.files.get( file );
 53  
         }
 54  
         else
 55  
         {
 56  32
             violations = new LinkedList();
 57  32
             this.files.put( file, violations );
 58  
         }
 59  
 
 60  72
         return violations;
 61  
     }
 62  
 
 63  
     public void setFileViolations( String file, List violations )
 64  
     {
 65  39
         this.files.put( file, violations );
 66  39
     }
 67  
 
 68  
     public Map getFiles()
 69  
     {
 70  389
         return files;
 71  
     }
 72  
 
 73  
     public void setFiles( Map files )
 74  
     {
 75  1
         this.files = files;
 76  1
     }
 77  
 
 78  
     public int getFileCount()
 79  
     {
 80  19
         return this.files.size();
 81  
     }
 82  
 
 83  
     public long getSeverityCount( SeverityLevel level )
 84  
     {
 85  47
         long count = 0;
 86  
 
 87  47
         Iterator it = this.files.values().iterator();
 88  
 
 89  139
         while ( it.hasNext() )
 90  
         {
 91  92
             List errors = (List) it.next();
 92  
 
 93  92
             count = count + getSeverityCount( errors, level );
 94  
         }
 95  
 
 96  47
         return count;
 97  
     }
 98  
 
 99  
     public long getSeverityCount( String file, SeverityLevel level )
 100  
     {
 101  75
         long count = 0;
 102  
 
 103  75
         if ( !this.files.containsKey( file ) )
 104  
         {
 105  4
             return count;
 106  
         }
 107  
 
 108  71
         List violations = (List) this.files.get( file );
 109  
 
 110  71
         count = getSeverityCount( violations, level );
 111  
 
 112  71
         return count;
 113  
     }
 114  
 
 115  
     public long getSeverityCount( List violations, SeverityLevel level )
 116  
     {
 117  196
         long count = 0;
 118  
 
 119  196
         Iterator it = violations.iterator();
 120  
 
 121  714
         while ( it.hasNext() )
 122  
         {
 123  518
             AuditEvent event = (AuditEvent) it.next();
 124  
 
 125  518
             if ( event.getSeverityLevel().equals( level ) )
 126  
             {
 127  164
                 count++;
 128  
             }
 129  
         }
 130  
 
 131  196
         return count;
 132  
     }
 133  
 }