|
15 | 15 | */
|
16 | 16 | package org.utplsql.sqldev.model.runner;
|
17 | 17 |
|
| 18 | +import java.util.ArrayList; |
| 19 | +import java.util.Collections; |
18 | 20 | import java.util.Enumeration;
|
19 | 21 | import java.util.HashSet;
|
| 22 | +import java.util.List; |
20 | 23 | import java.util.Set;
|
21 | 24 |
|
22 | 25 | import javax.swing.Icon;
|
23 | 26 | import javax.swing.tree.DefaultMutableTreeNode;
|
24 | 27 |
|
25 | 28 | import org.utplsql.sqldev.resources.UtplsqlResources;
|
26 | 29 |
|
27 |
| -public class ItemNode extends DefaultMutableTreeNode { |
| 30 | +public class ItemNode extends DefaultMutableTreeNode implements Comparable<ItemNode> { |
28 | 31 |
|
29 | 32 | private static final long serialVersionUID = -4053143673822661743L;
|
30 | 33 |
|
31 | 34 | public ItemNode(Item userObject) {
|
32 | 35 | super(userObject, userObject instanceof Suite);
|
33 | 36 | }
|
| 37 | + |
| 38 | + @Override |
| 39 | + public int compareTo(ItemNode other) { |
| 40 | + return getId().compareTo(other.getId()); |
| 41 | + } |
34 | 42 |
|
35 | 43 | public String getId() {
|
36 | 44 | return ((Item) getUserObject()).getId();
|
@@ -153,5 +161,41 @@ public Icon getWarningIcon() {
|
153 | 161 | public Icon getInfoIcon() {
|
154 | 162 | return ((Item) getUserObject()).getInfoIcon();
|
155 | 163 | }
|
| 164 | + |
| 165 | + /** |
| 166 | + * Calculates non-overlapping items. |
| 167 | + * |
| 168 | + * This can be used to build a list of suites to be started by utPLSQL while ensuring that |
| 169 | + * |
| 170 | + * - all requested tests are executed, but not more than once |
| 171 | + * - the test execution is efficient by ensuring that the list is as short as possible |
| 172 | + * |
| 173 | + * This means if all tests of a suite shall be executed that the suit should be |
| 174 | + * part of the result list and not all of its tests. |
| 175 | + * |
| 176 | + * In other words, top-level nodes are preferred to produce an optimal result. |
| 177 | + * |
| 178 | + * @param selectedNodes all selected nodes must be part of the same tree |
| 179 | + * @return non-overlapping set of nodes |
| 180 | + */ |
| 181 | + public static Set<ItemNode> createNonOverlappingSet(List<ItemNode> selectedNodes) { |
| 182 | + HashSet<ItemNode> result = new HashSet<>(); |
| 183 | + if (selectedNodes != null && selectedNodes.size() > 0) { |
| 184 | + HashSet<ItemNode> expandedResult = new HashSet<>(); |
| 185 | + List<ItemNode> sortedNodes = new ArrayList<>(selectedNodes); |
| 186 | + Collections.sort(sortedNodes); |
| 187 | + for (ItemNode sortedNode : sortedNodes) { |
| 188 | + if (!expandedResult.contains(sortedNode)) { |
| 189 | + result.add(sortedNode); |
| 190 | + Enumeration<?> expandedNodes = sortedNode.preorderEnumeration(); |
| 191 | + while (expandedNodes.hasMoreElements()) { |
| 192 | + ItemNode expandedNode = (ItemNode) expandedNodes.nextElement(); |
| 193 | + expandedResult.add(expandedNode); |
| 194 | + } |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | + return result; |
| 199 | + } |
156 | 200 |
|
157 | 201 | }
|
0 commit comments