001: /*
002: * Bytecode Analysis Framework
003: * Copyright (C) 2005, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019: package edu.umd.cs.findbugs.ba.ca;
020:
021: import java.util.ArrayList;
022: import java.util.Iterator;
023:
024: public class CallList {
025: private boolean isTop, isBottom;
026: private ArrayList<Call> callList;
027:
028: public CallList() {
029: this .callList = new ArrayList<Call>();
030: }
031:
032: public boolean isValid() {
033: return !(isTop() || isBottom());
034: }
035:
036: public Iterator<Call> callIterator() {
037: return callList.iterator();
038: }
039:
040: public boolean isTop() {
041: return isTop;
042: }
043:
044: public boolean isBottom() {
045: return isBottom;
046: }
047:
048: public void setTop() {
049: this .isTop = true;
050: this .isBottom = false;
051: this .callList.clear();
052: }
053:
054: public void setBottom() {
055: this .isTop = false;
056: this .isBottom = true;
057: this .callList.clear();
058: }
059:
060: public void clear() {
061: this .isTop = this .isBottom = false;
062: this .callList.clear();
063: }
064:
065: public void add(Call call) {
066: callList.add(call);
067: }
068:
069: public int size() {
070: return callList.size();
071: }
072:
073: public Call get(int index) {
074: return callList.get(index);
075: }
076:
077: public void copyFrom(CallList other) {
078: this .isTop = other.isTop;
079: this .isBottom = other.isBottom;
080: this .callList.clear();
081: this .callList.addAll(other.callList);
082: }
083:
084: public static CallList merge(CallList a, CallList b) {
085: CallList result = new CallList();
086:
087: if (a.isBottom || b.isBottom) {
088: result.isBottom = true;
089: } else if (a.isTop) {
090: result.copyFrom(b);
091: } else if (b.isTop) {
092: result.copyFrom(a);
093: } else {
094: // Result is the common prefix
095: int len = Math.min(a.size(), b.size());
096: for (int i = 0; i < len; ++i) {
097: if (!a.get(i).equals(b.get(i)))
098: break;
099: result.add(a.get(i));
100: }
101: }
102: return result;
103: }
104:
105: @Override
106: public boolean equals(Object obj) {
107: if (obj == null || obj.getClass() != this .getClass())
108: return false;
109: CallList other = (CallList) obj;
110: return this .callList.equals(other.callList);
111: }
112:
113: @Override
114: public int hashCode() {
115: return callList.hashCode();
116: }
117:
118: @Override
119: public String toString() {
120: StringBuffer buf = new StringBuffer();
121: for (Call call : callList) {
122: if (buf.length() > 0)
123: buf.append(',');
124: buf.append(call.getMethodName());
125: }
126: return buf.toString();
127: }
128: }
|