1 package org.apache.maven.plugin.checkstyle.exec;
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.LinkedList;
28 import java.util.List;
29 import java.util.Map;
30
31
32
33
34
35
36
37
38 public class CheckstyleResults
39 {
40 private Map<String, List<AuditEvent>> files;
41
42 private Configuration configuration;
43
44 public CheckstyleResults()
45 {
46 files = new HashMap<>();
47 }
48
49 public List<AuditEvent> getFileViolations( String file )
50 {
51 List<AuditEvent> violations;
52
53 if ( this.files.containsKey( file ) )
54 {
55 violations = this.files.get( file );
56 }
57 else
58 {
59 violations = new LinkedList<>();
60 if ( file != null )
61 {
62 this.files.put( file, violations );
63 }
64 }
65
66 return violations;
67 }
68
69 public void setFileViolations( String file, List<AuditEvent> violations )
70 {
71 if ( file != null )
72 {
73 this.files.put( file, violations );
74 }
75 }
76
77 public Map<String, List<AuditEvent>> getFiles()
78 {
79 return files;
80 }
81
82 public void setFiles( Map<String, List<AuditEvent>> files )
83 {
84 this.files = files;
85 }
86
87 public int getFileCount()
88 {
89 return this.files.size();
90 }
91
92 public long getSeverityCount( SeverityLevel level )
93 {
94 long count = 0;
95
96 for ( List<AuditEvent> errors : this.files.values() )
97 {
98 count = count + getSeverityCount( errors, level );
99 }
100
101 return count;
102 }
103
104 public long getSeverityCount( String file, SeverityLevel level )
105 {
106 long count = 0;
107
108 if ( !this.files.containsKey( file ) )
109 {
110 return count;
111 }
112
113 List<AuditEvent> violations = this.files.get( file );
114
115 count = getSeverityCount( violations, level );
116
117 return count;
118 }
119
120 public long getSeverityCount( List<AuditEvent> violations, SeverityLevel level )
121 {
122 long count = 0;
123
124 for ( AuditEvent event : violations )
125 {
126 if ( event.getSeverityLevel().equals( level ) )
127 {
128 count++;
129 }
130 }
131
132 return count;
133 }
134
135 public Configuration getConfiguration()
136 {
137 return configuration;
138 }
139
140 public void setConfiguration( Configuration configuration )
141 {
142 this.configuration = configuration;
143 }
144 }