View Javadoc

1   package org.codehaus.mojo.dashboard.report.plugin.beans;
2   
3   /*
4    * Copyright 2007 David Vicente
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.Date;
20  import java.util.Hashtable;
21  import java.util.Iterator;
22  import java.util.Map;
23  
24  /**
25   *
26   * @author <a href="dvicente72@gmail.com">David Vicente</a>
27   *
28   */
29  public class FindBugsReportBean extends AbstractReportBean
30  {
31      /**
32       *
33       */
34      private int nbClasses;
35  
36      /**
37       *
38       */
39      private int nbBugs;
40  
41      /**
42       *
43       */
44      private int nbErrors;
45  
46      /**
47       *
48       */
49      private int nbMissingClasses;
50  
51      /**
52       * Map:FindBugs categories.
53       */
54      private Map categories;
55  
56      /**
57       * Map:FindBugs priorities.
58       */
59      private Map priorities;
60  
61      /**
62       * Default constructor
63       *
64       */
65      public FindBugsReportBean()
66      {
67          this.categories = new Hashtable();
68          this.priorities = new Hashtable();
69      }
70  
71      /**
72       *
73       * @param dateGeneration
74       */
75      public FindBugsReportBean( Date dateGeneration )
76      {
77          super( dateGeneration );
78          this.categories = new Hashtable();
79          this.priorities = new Hashtable();
80      }
81  
82      /**
83       *
84       * @return int
85       */
86      public int getNbClasses()
87      {
88          return nbClasses;
89      }
90  
91      /**
92       *
93       * @param nbClasses
94       */
95      public void setNbClasses( int nbClasses )
96      {
97          this.nbClasses = nbClasses;
98      }
99  
100     /**
101      *
102      * @return
103      */
104     public int getNbErrors()
105     {
106         return nbErrors;
107     }
108 
109     /**
110      *
111      * @param nbErrors
112      */
113     public void setNbErrors( int nbErrors )
114     {
115         this.nbErrors = nbErrors;
116     }
117 
118     /**
119      *
120      * @return
121      */
122     public int getNbBugs()
123     {
124         return nbBugs;
125     }
126 
127     /**
128      *
129      * @param nbBugs
130      */
131     public void setNbBugs( int nbBugs )
132     {
133         this.nbBugs = nbBugs;
134     }
135 
136     /**
137      *
138      * @return
139      */
140     public int getNbMissingClasses()
141     {
142         return nbMissingClasses;
143     }
144 
145     /**
146      *
147      * @param nbMissingClasses
148      */
149     public void setNbMissingClasses( int nbMissingClasses )
150     {
151         this.nbMissingClasses = nbMissingClasses;
152     }
153 
154     /**
155      * get the findbugs categories map.
156      *
157      * @return findbugs categories map
158      */
159     public Map getCategories()
160     {
161         return this.categories;
162     }
163 
164     /**
165      *
166      * @param categories
167      */
168     public void setCategories( Map categories )
169     {
170         this.categories = categories;
171     }
172 
173     /**
174      * get the findbugs priorities map.
175      *
176      * @return findbugs priorities map
177      */
178     public Map getPriorities()
179     {
180         return this.priorities;
181     }
182 
183     /**
184      *
185      * @param priorities
186      */
187     public void setPriorities( Map priorities )
188     {
189         this.priorities = priorities;
190     }
191 
192     /**
193      *
194      * @param error
195      */
196     public void addCategory( String category )
197     {
198         if ( this.categories.isEmpty() )
199         {
200             this.categories.put( category, new Integer( 1 ) );
201         }
202         else
203         {
204             if ( ( this.categories.containsKey( category ) ) )
205             {
206 
207                 Integer oldValue = ( (Integer) ( this.categories.get( category ) ) );
208                 this.categories.put( category, new Integer( oldValue.intValue() + 1 ) );
209             }
210             else
211             {
212                 this.categories.put( category, new Integer( 1 ) );
213             }
214         }
215     }
216 
217     /**
218      * @param error
219      */
220     public void addAllCategories( Map categories )
221     {
222         if ( this.categories.isEmpty() )
223         {
224             this.categories.putAll( categories );
225         }
226         else
227         {
228             Iterator iter = categories.keySet().iterator();
229             while ( iter.hasNext() )
230             {
231                 String category = (String) iter.next();
232                 Integer newValuetoAdd = ( (Integer) ( categories.get( category ) ) );
233                 if ( ( this.categories.containsKey( category ) ) )
234                 {
235 
236                     Integer oldValue = ( (Integer) ( this.categories.get( category ) ) );
237                     this.categories.put( category, new Integer( oldValue.intValue() + newValuetoAdd.intValue() ) );
238                 }
239                 else
240                 {
241                     this.categories.put( category, newValuetoAdd );
242                 }
243             }
244         }
245     }
246 
247     /**
248      *
249      * @param error
250      */
251     public void addPriority( String priority )
252     {
253         if ( this.priorities.isEmpty() )
254         {
255             this.priorities.put( priority, new Integer( 1 ) );
256         }
257         else
258         {
259             if ( ( this.priorities.containsKey( priority ) ) )
260             {
261 
262                 Integer oldValue = ( (Integer) ( this.priorities.get( priority ) ) );
263                 this.priorities.put( priority, new Integer( oldValue.intValue() + 1 ) );
264             }
265             else
266             {
267                 this.priorities.put( priority, new Integer( 1 ) );
268             }
269         }
270     }
271 
272     /**
273      * @param error
274      */
275     public void addAllPriorities( Map priorities )
276     {
277         if ( this.priorities.isEmpty() )
278         {
279             this.priorities.putAll( priorities );
280         }
281         else
282         {
283             Iterator iter = priorities.keySet().iterator();
284             while ( iter.hasNext() )
285             {
286                 String priority = (String) iter.next();
287                 Integer newValuetoAdd = ( (Integer) ( priorities.get( priority ) ) );
288                 if ( ( this.priorities.containsKey( priority ) ) )
289                 {
290                     Integer oldValue = ( (Integer) ( this.priorities.get( priority ) ) );
291                     this.priorities.put( priority, new Integer( oldValue.intValue() + newValuetoAdd.intValue() ) );
292                 }
293                 else
294                 {
295                     this.priorities.put( priority, newValuetoAdd );
296                 }
297             }
298         }
299     }
300 
301     /**
302      *
303      * @param dashboardReport
304      */
305     public void merge( IDashBoardReportBean dashboardReport )
306     {
307         if ( dashboardReport != null && dashboardReport instanceof FindBugsReportBean )
308         {
309             this.nbClasses = this.nbClasses + ( (FindBugsReportBean) dashboardReport ).getNbClasses();
310 
311             this.nbBugs = this.nbBugs + ( (FindBugsReportBean) dashboardReport ).getNbBugs();
312 
313             this.nbErrors = this.nbErrors + ( (FindBugsReportBean) dashboardReport ).getNbErrors();
314 
315             this.nbMissingClasses =
316                 this.nbMissingClasses + ( (FindBugsReportBean) dashboardReport ).getNbMissingClasses();
317 
318             this.addAllCategories( ( (FindBugsReportBean) dashboardReport ).getCategories() );
319             this.addAllPriorities( ( (FindBugsReportBean) dashboardReport ).getPriorities() );
320         }
321     }
322 
323     /**
324      *
325      */
326     protected Object clone()
327     {
328         FindBugsReportBean clone = new FindBugsReportBean( this.getDateGeneration() );
329         clone.setNbClasses( this.nbClasses );
330         clone.setNbBugs( this.nbBugs );
331         clone.setNbMissingClasses( this.nbMissingClasses );
332         clone.setNbErrors( this.nbErrors );
333         clone.addAllCategories( this.getCategories() );
334         clone.addAllPriorities( this.getPriorities() );
335         return clone;
336     }
337 
338 }