1 19 20 25 26 27 package soot.toolkits.scalar; 28 29 import soot.*; 30 import soot.util.*; 31 import java.util.*; 32 33 46 public abstract class AbstractFlowSet implements FlowSet { 47 public abstract Object clone(); 48 49 52 public Object emptySet() { 53 FlowSet t = (FlowSet)clone(); 54 t.clear(); 55 return t; 56 } 57 58 public void copy(FlowSet dest) { 59 List elements = toList(); 60 Iterator it = elements.iterator(); 61 dest.clear(); 62 while (it.hasNext()) 63 dest.add(it.next()); 64 } 65 66 69 public void clear() { 70 Iterator it = toList().iterator(); 71 while (it.hasNext()) 72 remove(it.next()); 73 } 74 75 public void union(FlowSet other) { 76 union(other, this); 77 } 78 79 public void union(FlowSet other, FlowSet dest) { 80 if (dest != this && dest != other) 81 dest.clear(); 82 83 if (dest != this) { 84 Iterator thisIt = toList().iterator(); 85 while (thisIt.hasNext()) 86 dest.add(thisIt.next()); 87 } 88 89 if (dest != other) { 90 Iterator otherIt = other.toList().iterator(); 91 while (otherIt.hasNext()) 92 dest.add(otherIt.next()); 93 } 94 } 95 96 public void intersection(FlowSet other) { 97 intersection(other, this); 98 } 99 100 public void intersection(FlowSet other, FlowSet dest) { 101 if (dest == this && dest == other) return; 102 List elements = null; 103 FlowSet flowSet = null; 104 if (dest == this) { 105 106 elements = toList(); 107 flowSet = other; 108 } else { 109 110 elements = other.toList(); 111 flowSet = this; 112 } 113 dest.clear(); 114 Iterator it = elements.iterator(); 115 while (it.hasNext()) { 116 Object o = it.next(); 117 if (flowSet.contains(o)) 118 dest.add(o); 119 } 120 } 121 122 public void difference(FlowSet other) { 123 difference(other, this); 124 } 125 126 public void difference(FlowSet other, FlowSet dest) { 127 if (dest == this && dest == other) { 128 dest.clear(); 129 return; 130 } 131 132 Iterator it = this.toList().iterator(); 133 FlowSet flowSet = (other == dest)? (FlowSet)other.clone(): other; 134 dest.clear(); 136 while (it.hasNext()) { 137 Object o = it.next(); 138 if (!flowSet.contains(o)) 139 dest.add(o); 140 } 141 } 142 143 public abstract boolean isEmpty(); 144 145 public abstract int size(); 146 147 public abstract void add(Object obj); 148 149 public void add(Object obj, FlowSet dest) { 150 if (dest != this) 151 copy(dest); 152 dest.add(obj); 153 } 154 155 public abstract void remove(Object obj); 156 157 public void remove(Object obj, FlowSet dest) { 158 if (dest != this) 159 copy(dest); 160 dest.remove(obj); 161 } 162 163 public abstract boolean contains(Object obj); 164 165 public Iterator iterator() { 166 return toList().iterator(); 167 } 168 169 public abstract List toList(); 170 171 public boolean equals(Object o) { 172 if (!(o instanceof FlowSet)) return false; 173 FlowSet other = (FlowSet)o; 174 if (size() != other.size()) return false; 175 Iterator it = toList().iterator(); 176 while (it.hasNext()) 177 if (!other.contains(it.next())) return false; 178 return true; 179 } 180 181 public String toString() { 182 StringBuffer buffer = new StringBuffer ("{"); 183 Iterator it = toList().iterator(); 184 if (it.hasNext()) { 185 buffer.append(it.next()); 186 187 while(it.hasNext()) 188 buffer.append(", " + it.next()); 189 } 190 buffer.append("}"); 191 return buffer.toString(); 192 } 193 } 194 195 | Popular Tags |