1 19 package edu.umd.cs.findbugs.ba.ca; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 24 public class CallList { 25 private boolean isTop, isBottom; 26 private ArrayList <Call> callList; 27 28 public CallList() { 29 this.callList = new ArrayList <Call>(); 30 } 31 32 public boolean isValid() { 33 return !(isTop() || isBottom()); 34 } 35 36 public Iterator <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 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 107 public boolean equals(Object 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 116 public int hashCode() { 117 return callList.hashCode(); 118 } 119 120 @Override 121 public String toString() { 122 StringBuffer buf = new StringBuffer (); 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 |