KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > toolkits > astmetrics > ClassData


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2006 Nomair A. Naeem
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package soot.toolkits.astmetrics;
21
22 import java.awt.List JavaDoc;
23 import java.util.ArrayList JavaDoc;
24 import java.util.Iterator JavaDoc;
25
26
27 /*
28  * Should store general information about the class
29  * Size? number of nodes?
30  * Plus a list of MetricData objects
31  */

32 public class ClassData {
33     String JavaDoc className; //the name of the class whose data is being stored
34
ArrayList JavaDoc metricData; //each element should be a MetricData
35

36     public ClassData(String JavaDoc name){
37         className=name;
38         metricData = new ArrayList JavaDoc();
39     }
40
41     public String JavaDoc getClassName(){
42         return className;
43     }
44     
45     /*
46      * returns true if this className has the same name
47      * as the string sent as argument
48      */

49     public boolean classNameEquals(String JavaDoc className){
50         return (this.className.equals(className));
51     }
52     
53     
54     /*
55      * Only add new metric if this is not already present
56      * Else dont add
57      */

58     public void addMetric(MetricData data){
59         Iterator JavaDoc it = metricData.iterator();
60         while(it.hasNext()){
61             MetricData temp = (MetricData)it.next();
62             if(temp.metricName.equals(data.metricName)){
63                 //System.out.println("Not adding same metric again......"+temp.metricName);
64
return;
65             }
66         }
67         metricData.add(data);
68     }
69     
70     
71     public String JavaDoc toString(){
72         StringBuffer JavaDoc b = new StringBuffer JavaDoc();
73         b.append("<Class>\n");
74         b.append("<ClassName>" + className + "</ClassName>\n");
75         Iterator JavaDoc it = metricData.iterator();
76         while(it.hasNext()){
77             b.append(((MetricData)it.next()).toString());
78         }
79         b.append("</Class>");
80         return b.toString();
81     }
82 }
83
Popular Tags