33 import java.util.HashSet;
34 import java.util.Iterator;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Set;
38
39 import javax.xml.parsers.ParserConfigurationException;
40
41 import org.xml.sax.SAXException;
42
43 class Merger {
44
45 /**
46 * @param in array of files with XML reports
47 * @param out file to put results
48 * @param conflictResolver ConflictResolver to resolve conflicts during merge
49 */
50 public boolean merge(File[] in, File out, ConflictResolver conflictResolver) throws SAXException,
51 ParserConfigurationException, IOException{
52 // Maps with statistics
53 Map[] inputs = new Map[in.length];
54 // read statistics
55 for (int i = 0; i < in.length; i++) {
56 XMLReportReader reader = new XMLReportReader();
57 Map<Object, Object> map = reader.readIDs(in[i]);
58 inputs[i] = map;
59 }
60
61 // shift word workgroups id renaming
62 int allCnt = 0;
63 // rename id's and find conflicts
64 Set<String> all = new HashSet<>();
65 List<String> conflicts = new ArrayList<>();
66 for (int i = 0; i < in.length; i++) {
67 int workdirsInFile = 0;
68 Iterator<Object> it = inputs[i].keySet().iterator();
69 Map<Object, Object> newMap = new HashMap<>();
70 while (it.hasNext()) {
71 Object o = it.next();
72 // this is workdir ID
73 if (o instanceof Integer) {
74 Integer id = (Integer) o;
75 Integer nid = new Integer(id.intValue() + allCnt);
76 newMap.put(id, nid);
77 workdirsInFile++;
78 }
79 // this is test result url
80 if (o instanceof String) {
81 String url = (String) o;
82 if (all.contains(url) && !conflicts.contains(url)) {
83 conflicts.add(url);
84 }
85 all.add(url);
86 TestResultDescr td = (TestResultDescr)inputs[i].get(o);
87 td.setID(td.getID() + allCnt);
88 newMap.put(url, td);
|
33 import java.util.HashSet;
34 import java.util.Iterator;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.Set;
38
39 import javax.xml.parsers.ParserConfigurationException;
40
41 import org.xml.sax.SAXException;
42
43 class Merger {
44
45 /**
46 * @param in array of files with XML reports
47 * @param out file to put results
48 * @param conflictResolver ConflictResolver to resolve conflicts during merge
49 */
50 public boolean merge(File[] in, File out, ConflictResolver conflictResolver) throws SAXException,
51 ParserConfigurationException, IOException{
52 // Maps with statistics
53 Map<?, ?>[] inputs = new Map<?, ?>[in.length];
54 // read statistics
55 for (int i = 0; i < in.length; i++) {
56 XMLReportReader reader = new XMLReportReader();
57 Map<?, ?> map = reader.readIDs(in[i]);
58 inputs[i] = map;
59 }
60
61 // shift word workgroups id renaming
62 int allCnt = 0;
63 // rename id's and find conflicts
64 Set<String> all = new HashSet<>();
65 List<String> conflicts = new ArrayList<>();
66 for (int i = 0; i < in.length; i++) {
67 int workdirsInFile = 0;
68 Iterator<?> it = inputs[i].keySet().iterator();
69 Map<Object, Object> newMap = new HashMap<>();
70 while (it.hasNext()) {
71 Object o = it.next();
72 // this is workdir ID
73 if (o instanceof Integer) {
74 Integer id = (Integer) o;
75 Integer nid = new Integer(id.intValue() + allCnt);
76 newMap.put(id, nid);
77 workdirsInFile++;
78 }
79 // this is test result url
80 if (o instanceof String) {
81 String url = (String) o;
82 if (all.contains(url) && !conflicts.contains(url)) {
83 conflicts.add(url);
84 }
85 all.add(url);
86 TestResultDescr td = (TestResultDescr)inputs[i].get(o);
87 td.setID(td.getID() + allCnt);
88 newMap.put(url, td);
|