KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > ba > ca > CallList


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

19 package edu.umd.cs.findbugs.ba.ca;
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 public class CallList {
25     private boolean isTop, isBottom;
26     private ArrayList JavaDoc<Call> callList;
27     
28     public CallList() {
29         this.callList = new ArrayList JavaDoc<Call>();
30     }
31     
32     public boolean isValid() {
33         return !(isTop() || isBottom());
34     }
35     
36     public Iterator JavaDoc<Call> callIterator() {
37         return callList.iterator();
38     }
39     
40     public boolean isTop() {
41         return isTop;
42     }
43     
44     public boolean isBottom() {
45         return isBottom;
46     }
47     
48     public void setTop() {
49         this.isTop = true;
50         this.isBottom = false;
51         this.callList.clear();
52     }
53     
54     public void setBottom() {
55         this.isTop = false;
56         this.isBottom = true;
57         this.callList.clear();
58     }
59     
60     public void clear() {
61         this.isTop = this.isBottom = false;
62         this.callList.clear();
63     }
64     
65     public void add(Call call) {
66         callList.add(call);
67     }
68     
69     public int size() {
70         return callList.size();
71     }
72     
73     public Call get(int index) {
74         return callList.get(index);
75     }
76     
77     public void copyFrom(CallList other) {
78         this.isTop = other.isTop;
79         this.isBottom = other.isBottom;
80         this.callList.clear();
81         this.callList.addAll(other.callList);
82     }
83     
84     public static CallList merge(CallList a, CallList b) {
85         CallList result = new CallList();
86
87         if (a.isBottom || b.isBottom) {
88             result.isBottom = true;
89         } else if (a.isTop) {
90             result.copyFrom(b);
91         } else if (b.isTop) {
92             result.copyFrom(a);
93         } else {
94             // Result is the common prefix
95
int len = Math.min(a.size(), b.size());
96             for (int i = 0; i < len; ++i) {
97                 if (!a.get(i).equals(b.get(i)))
98                     break;
99                 result.add(a.get(i));
100             }
101         }
102         return result;
103     }
104     
105     //@Override
106
@Override JavaDoc
107          public boolean equals(Object JavaDoc obj) {
108         if (obj == null || obj.getClass() != this.getClass())
109             return false;
110         CallList other = (CallList) obj;
111         return this.callList.equals(other.callList);
112     }
113     
114     //@Override
115
@Override JavaDoc
116          public int hashCode() {
117         return callList.hashCode();
118     }
119     
120     @Override JavaDoc
121          public String JavaDoc toString() {
122         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
123         for (Call call : callList) {
124             if (buf.length() > 0)
125                 buf.append(',');
126             buf.append(call.getMethodName());
127         }
128         return buf.toString();
129     }
130 }
131
Popular Tags