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