|
114 | 114 | import java.util.Collections;
|
115 | 115 | import java.util.function.IntFunction;
|
116 | 116 | import java.util.HashMap;
|
| 117 | +import java.util.HashSet; |
117 | 118 | import java.util.Iterator;
|
118 | 119 | import java.util.LinkedHashMap;
|
119 | 120 | import java.util.LinkedHashSet;
|
120 | 121 | import java.util.List;
|
121 | 122 | import java.util.Map;
|
122 | 123 | import java.util.Set;
|
123 | 124 | import java.util.Stack;
|
| 125 | +import java.util.stream.Collectors; |
124 | 126 |
|
125 | 127 | /**
|
126 | 128 | * Extractor for intra-procedural expression-level control flow graphs.
|
@@ -228,33 +230,18 @@ private static List<Node> flattenNestedList(Collection<?> lists, List<Node> outp
|
228 | 230 |
|
229 | 231 | /**
|
230 | 232 | * Creates an order preserving concatenation of the nodes in `xs` and `ys` without duplicates.
|
231 |
| - * Returns `null`, or an `Node` or a `List<Node>`. |
| 233 | + * Returns `null`, or an `Node`, or a `List<Node>`. |
232 | 234 | */
|
| 235 | + @SuppressWarnings("unchecked") |
233 | 236 | private static Object union(Object xs, Object ys) {
|
234 |
| - if (xs == null) return ys; |
235 |
| - if (ys == null) return xs; |
236 |
| - if (xs instanceof List<?>) { |
237 |
| - @SuppressWarnings("unchecked") |
238 |
| - List<Node> xsCopy = new ArrayList<Node>((List<Node>) xs); |
239 |
| - for (Node y : createCollection(ys)) if (!xsCopy.contains(y)) xsCopy.add(y); |
240 |
| - return xsCopy; |
| 237 | + Set<Node> set = new HashSet<>(); |
| 238 | + List<Node> result = flattenNestedList(Arrays.asList(xs, ys)).stream().filter(set::add).collect(Collectors.toList()); |
| 239 | + if (result.size() == 0) { |
| 240 | + return null; |
| 241 | + } else if (result.size() == 1) { |
| 242 | + return result.get(0); |
241 | 243 | } else {
|
242 |
| - if (ys instanceof List<?>) { |
243 |
| - @SuppressWarnings("unchecked") |
244 |
| - List<Object> lys = (List<Object>) ys; |
245 |
| - if (!lys.contains(xs)) { |
246 |
| - lys = new ArrayList<Object>(lys); |
247 |
| - lys.add(0, xs); |
248 |
| - } |
249 |
| - return lys; |
250 |
| - } else if (xs == ys) { |
251 |
| - return xs; |
252 |
| - } else { |
253 |
| - List<Node> res = new ArrayList<Node>(2); |
254 |
| - res.add((Node) xs); |
255 |
| - res.add((Node) ys); |
256 |
| - return res; |
257 |
| - } |
| 244 | + return result; |
258 | 245 | }
|
259 | 246 | }
|
260 | 247 |
|
|
0 commit comments