Skip to content

Commit

Permalink
to squash
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Jan 13, 2019
1 parent 10fc72a commit 51636a1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

import com.github.checkstyle.parser.CheckstyleReportsParser;

Expand Down Expand Up @@ -115,20 +120,59 @@ public void addRecords(List<CheckstyleRecord> newRecords,
*/
private static List<CheckstyleRecord> produceDiff(
List<CheckstyleRecord> list1, List<CheckstyleRecord> list2) {
final List<CheckstyleRecord> diff = new ArrayList<>();
for (CheckstyleRecord rec1 : list1) {
if (!isInList(list2, rec1)) {
diff.add(rec1);
}
// final List<CheckstyleRecord> diff = new ArrayList<>();
// for (CheckstyleRecord rec1 : list1) {
// if (!isInList(list2, rec1)) {
// diff.add(rec1);
// }
// }
// for (CheckstyleRecord rec2 : list2) {
// if (!isInList(list1, rec2)) {
// diff.add(rec2);
// }
// }
diff1.list1 = list1;
diff1.list2 = list2;
diff2.list2 = list1;
diff2.list1 = list2;

final Future<List<CheckstyleRecord>> future1 = EXEC.submit(diff1);
final Future<List<CheckstyleRecord>> future2 = EXEC.submit(diff2);

final List<CheckstyleRecord> diff;
final List<CheckstyleRecord> other;
try {
diff = future1.get();
other = future2.get();
}
for (CheckstyleRecord rec2 : list2) {
if (!isInList(list1, rec2)) {
diff.add(rec2);
}
catch (InterruptedException | ExecutionException ex) {
throw new IllegalStateException("Multi-threading failure reported", ex);
}
diff.addAll(other);
return diff;
}

private static final ExecutorService EXEC = Executors.newCachedThreadPool();
private static final MultiThreadedDiff diff1 = new MultiThreadedDiff();
private static final MultiThreadedDiff diff2 = new MultiThreadedDiff();

private static class MultiThreadedDiff implements Callable<List<CheckstyleRecord>> {
private List<CheckstyleRecord> list1;
private List<CheckstyleRecord> list2;

@Override
public List<CheckstyleRecord> call() throws Exception {
final List<CheckstyleRecord> diff = new ArrayList<>();
for (CheckstyleRecord rec1 : list1) {
if (!isInList(list2, rec1)) {
diff.add(rec1);
}
}
return diff;
}

}

/**
* Compares the record against list of records.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private MultiThreadedParser(Path xml, int readerIndex) {
this.readerIndex = readerIndex;
}

@Override
public DiffReport call() throws Exception {
System.out.println("Parsing " + xml + ". " + new SimpleDateFormat("yyyy.MM.dd HH.mm.ss.SSS").format(new Date()));
final DiffReport output = new DiffReport();
Expand Down

0 comments on commit 51636a1

Please sign in to comment.