01: /* Soot - a J*va Optimization Framework
02: * Copyright (C) 2006 Nomair A. Naeem
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * 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.util.ArrayList;
23: import java.util.Iterator;
24:
25: /*
26: * Should store general information about the class
27: * Size? number of nodes?
28: * Plus a list of MetricData objects
29: */
30: public class ClassData {
31: String className; //the name of the class whose data is being stored
32: ArrayList<MetricData> metricData; //each element should be a MetricData
33:
34: public ClassData(String name) {
35: className = name;
36: metricData = new ArrayList<MetricData>();
37: }
38:
39: public String getClassName() {
40: return className;
41: }
42:
43: /*
44: * returns true if this className has the same name
45: * as the string sent as argument
46: */
47: public boolean classNameEquals(String className) {
48: return (this .className.equals(className));
49: }
50:
51: /*
52: * Only add new metric if this is not already present
53: * Else dont add
54: */
55: public void addMetric(MetricData data) {
56: Iterator<MetricData> it = metricData.iterator();
57: while (it.hasNext()) {
58: MetricData temp = it.next();
59: if (temp.metricName.equals(data.metricName)) {
60: //System.out.println("Not adding same metric again......"+temp.metricName);
61: return;
62: }
63: }
64: metricData.add(data);
65: }
66:
67: public String toString() {
68: StringBuffer b = new StringBuffer();
69: b.append("<Class>\n");
70: b.append("<ClassName>" + className + "</ClassName>\n");
71: Iterator<MetricData> it = metricData.iterator();
72: while (it.hasNext()) {
73: b.append(it.next().toString());
74: }
75: b.append("</Class>");
76: return b.toString();
77: }
78: }
|