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.Configuration;
24  import com.puppycrawl.tools.checkstyle.api.SeverityLevel;
25  
26  import java.util.HashMap;
27  import java.util.Iterator;
28  import java.util.LinkedList;
29  import java.util.List;
30  import java.util.Map;
31  
32  /**
33   * Object holding the references to the CheckstyleResults.
34   *
35   * @author <a href="mailto:joakim@erdfelt.net">Joakim Erdfelt</a>
36   * @version $Id: CheckstyleResults.html 816658 2012-05-08 13:56:19Z hboutemy $
37   * @todo provide fallback to disk based storage if too many results.
38   */
39  public class CheckstyleResults
40  {
41      private Map files;
42      
43      private Configuration configuration;
44  
45      public CheckstyleResults()
46      {
47          files = new HashMap();
48      }
49  
50      public List getFileViolations( String file )
51      {
52          List violations;
53  
54          if ( this.files.containsKey( file ) )
55          {
56              violations = (List) this.files.get( file );
57          }
58          else
59          {
60              violations = new LinkedList();
61              this.files.put( file, violations );
62          }
63  
64          return violations;
65      }
66  
67      public void setFileViolations( String file, List violations )
68      {
69          this.files.put( file, violations );
70      }
71  
72      public Map getFiles()
73      {
74          return files;
75      }
76  
77      public void setFiles( Map files )
78      {
79          this.files = files;
80      }
81  
82      public int getFileCount()
83      {
84          return this.files.size();
85      }
86  
87      public long getSeverityCount( SeverityLevel level )
88      {
89          long count = 0;
90  
91          Iterator it = this.files.values().iterator();
92  
93          while ( it.hasNext() )
94          {
95              List errors = (List) it.next();
96  
97              count = count + getSeverityCount( errors, level );
98          }
99  
100         return count;
101     }
102 
103     public long getSeverityCount( String file, SeverityLevel level )
104     {
105         long count = 0;
106 
107         if ( !this.files.containsKey( file ) )
108         {
109             return count;
110         }
111 
112         List violations = (List) this.files.get( file );
113 
114         count = getSeverityCount( violations, level );
115 
116         return count;
117     }
118 
119     public long getSeverityCount( List violations, SeverityLevel level )
120     {
121         long count = 0;
122 
123         Iterator it = violations.iterator();
124 
125         while ( it.hasNext() )
126         {
127             AuditEvent event = (AuditEvent) it.next();
128 
129             if ( event.getSeverityLevel().equals( level ) )
130             {
131                 count++;
132             }
133         }
134 
135         return count;
136     }
137 
138     public Configuration getConfiguration()
139     {
140         return configuration;
141     }
142 
143     public void setConfiguration( Configuration configuration )
144     {
145         this.configuration = configuration;
146     }
147 }