View Javadoc

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