View Javadoc

1   package org.codehaus.mojo.dashboard.report.plugin.beans;
2   
3   /*
4    * Copyright 2006 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.ArrayList;
20  import java.util.Collections;
21  import java.util.Date;
22  import java.util.List;
23  
24  import org.codehaus.mojo.dashboard.report.plugin.beans.comparator.DescAfferentCouplingPackageComparator;
25  
26  /**
27   * 
28   * @author <a href="dvicente72@gmail.com">David Vicente</a>
29   * 
30   */
31  public class JDependReportBean extends AbstractReportBean
32  {
33      /**
34       * 
35       */
36      private double averageAfferentCoupling = 0;
37  
38      /**
39       * 
40       */
41      private int nbPackages = 0;
42  
43      /**
44       * 
45       */
46      private int sumAC = 0;
47      
48      /**
49       * 
50       */
51      private List packages = new ArrayList();
52      /**
53       * 
54       *
55       */
56      public JDependReportBean()
57      {
58      }
59      /**
60       * 
61       * @param dateGeneration
62       */
63      public JDependReportBean( Date dateGeneration )
64      {
65          super( dateGeneration );
66      }
67  
68      public int getNbPackages()
69      {
70          return nbPackages;
71      }
72  
73      public void setNbPackages( int nbPackages )
74      {
75          this.nbPackages = nbPackages;
76      }
77  
78      public int getSumAC()
79      {
80          return sumAC;
81      }
82  
83      public void setSumAC( int sumAC )
84      {
85          this.sumAC = sumAC;
86      }
87  
88      public double getAverageAfferentCoupling()
89      {
90          return averageAfferentCoupling;
91      }
92  
93      public void setAverageAfferentCoupling( double averageAfferentCoupling )
94      {
95          this.averageAfferentCoupling = averageAfferentCoupling;
96      }
97  
98      /**
99       * 
100      * @param dashboardReport
101      */
102     public void merge( IDashBoardReportBean dashboardReport )
103     {
104         if ( dashboardReport != null && dashboardReport instanceof JDependReportBean )
105         {
106             this.sumAC = this.sumAC + ( (JDependReportBean) dashboardReport ).getSumAC();
107             this.nbPackages = this.nbPackages + ( (JDependReportBean) dashboardReport ).getNbPackages();
108             if ( this.nbPackages == 0 )
109             {
110                 // no packages, therefore 0.
111                 this.averageAfferentCoupling = 0d;
112             }
113             else
114             {
115                 this.averageAfferentCoupling = (double) this.sumAC / this.nbPackages;
116             }
117             this.packages.addAll( ( (JDependReportBean) dashboardReport ).getPackages() );
118             // Collections.sort( this.packages, new DescAfferentCouplingPackageComparator() );
119         }
120     }
121 
122     public List getPackages()
123     {
124         Collections.sort( this.packages, new DescAfferentCouplingPackageComparator() );
125         return packages;
126     }
127 
128     public void setPackages( List packages )
129     {
130         this.packages = packages;
131     }
132     
133     /**
134      * 
135      * @param pack
136      */
137     public void addPackage( XRefPackageBean pack )
138     {
139         this.packages.add( pack );
140         this.sumAC = this.sumAC + pack.getAfferentCoupling().intValue();
141         this.nbPackages = this.nbPackages + 1;
142         if ( this.nbPackages == 0 )
143         {
144             // no packages, therefore 0.
145             this.averageAfferentCoupling = 0d;
146         }
147         else
148         {
149             this.averageAfferentCoupling = (double) this.sumAC / this.nbPackages;
150         }
151     }
152 
153 }