1 package org.apache.maven.plugin.checkstyle;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
34
35
36
37
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 }