View Javadoc

1   package org.codehaus.mojo.dashboard.report.plugin.beans;
2   
3   /*
4    *  Copyright 2008 Henrik Lynggaard
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   *  under the License.
18   */
19  
20  import java.util.Date;
21  import java.util.HashMap;
22  import java.util.Iterator;
23  import java.util.Map;
24  
25  /**
26   * 
27   * @author Henrik Lynggaard
28   */
29  public class TagListReportBean extends AbstractReportBean
30  {
31  	/**
32  	 * 
33  	 */
34      private Map tags = new HashMap();
35      /**
36       * 
37       */
38      private int nbTotal = 0;
39      
40      /**
41       * 
42       */
43      private int nbClasses;
44      
45      /**
46       * Construct a new CloverReportBean against the given project.
47       */
48      public TagListReportBean()
49      {
50  
51      }
52  
53      /**
54       * 
55       * @param projectName
56       */
57      public TagListReportBean( Date dateGeneration )
58      {
59          super( dateGeneration );
60      }
61  
62      public Map getTags()
63      {
64          return tags;
65      }
66  
67      public void setTag( String name, Integer count )
68      {
69          tags.put( name, count );
70          this.nbTotal = this.nbTotal + count.intValue();
71      }
72      
73      /**
74       * @param error
75       */
76      public void addAllEntries( Map entries )
77      {
78          if ( this.tags.isEmpty() )
79          {
80              this.tags.putAll( entries );
81          }
82          else
83          {
84              Iterator iter = entries.keySet().iterator();
85              while ( iter.hasNext() )
86              {
87                  String key = (String) iter.next();
88                  Integer newValuetoAdd = ( (Integer) ( entries.get( key ) ) );
89                  if ( ( this.tags.containsKey( key ) ) )
90                  {
91                  	Integer oldCount = (Integer) tags.get( key );
92                      this.tags.put( key, new Integer( oldCount.intValue() + newValuetoAdd.intValue() ) );
93                  }
94                  else
95                  {
96                  	tags.put( key, newValuetoAdd );
97                  }
98              }
99          }
100     }
101     
102     /**
103      * 
104      * @param dashboardReport
105      */
106     public void merge( IDashBoardReportBean dashboardReport )
107     {
108 
109         if ( dashboardReport != null && dashboardReport instanceof TagListReportBean )
110         {
111         	this.nbTotal = this.nbTotal + ( (TagListReportBean) dashboardReport ).getNbTotal();
112         	this.nbClasses = this.nbClasses + ( (TagListReportBean) dashboardReport ).getNbClasses();
113         	this.addAllEntries(((TagListReportBean)dashboardReport).getTags());
114         }
115 
116         
117     }
118     
119     /**
120      * 
121      */
122     protected Object clone()
123     {
124     	TagListReportBean clone = new TagListReportBean( this.getDateGeneration() );
125     	clone.setNbTotal(this.nbTotal);
126     	clone.setNbClasses(this.nbClasses);
127         clone.addAllEntries( this.tags );
128         return clone;
129     }
130 
131 	public int getNbTotal() {
132 		return nbTotal;
133 	}
134 
135 	public void setNbTotal(int nbTotal) {
136 		this.nbTotal = nbTotal;
137 	}
138 
139 	public int getNbClasses() {
140 		return nbClasses;
141 	}
142 
143 	public void setNbClasses(int nbClasses) {
144 		this.nbClasses = nbClasses;
145 	}
146 }