\ No newline at end of file
Index: src/ThreadedCompare.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
<+>import java.io.*;\nimport java.nio.file.Files;\nimport java.nio.file.Path;\nimport java.security.MessageDigest;\nimport java.security.NoSuchAlgorithmException;\nimport java.util.ArrayList;\nimport java.util.List;\npublic class ThreadedCompare extends Thread {\n private final List pathsToCompareTo;\n private final List pathsToBeCompared;\n public ThreadedCompare (List pathsToBeCompared, List pathsToCompareTo) {\n this.pathsToBeCompared = pathsToBeCompared;\n this.pathsToCompareTo = pathsToCompareTo;\n }\n @Override\n public void run() {\n\n //Compare every File\n for (Path file1 : pathsToBeCompared) {\n for (Path file2 : pathsToCompareTo) {\n try {\n if (sameContent(file1, file2)) {\n List bothPaths = new ArrayList<>();\n bothPaths.add(file1);\n bothPaths.add(file2);\n\n //here it is trying to add the values in the HashMap\n if (Main.fileMap.containsKey(getMD5Sum(file1.toFile()))) {\n if (!Main.fileMap.get(getMD5Sum(file1.toFile())).contains(file1)) {\n Main.fileMap.get(getMD5Sum(file1.toFile())).add(file1);\n }\n if (!Main.fileMap.get(getMD5Sum(file1.toFile())).contains(file2)) {\n Main.fileMap.get(getMD5Sum(file1.toFile())).add(file2);\n }\n } else {\n Main.fileMap.put(getMD5Sum(file1.toFile()), bothPaths);\n }\n }\n } catch (IOException e) {\n throw new RuntimeException(e);\n }\n }\n //Update the Progress that can be found in The Main Class\n Main.progress += 1;\n }\n //Update the thread Completion Counter that can be found in the Main Class\n Main.completedThreads += 1;\n }\n private boolean sameContent(Path file1, Path file2) throws IOException {\n if (file1 != file2) {\n return Files.mismatch(file1, file2) == -1;\n }\n return false;\n }\n\n //this is used to get the MD5 String of one of the files (one of them is just fine since they both have the same value)\n private String getMD5Sum (File file) throws IOException {\n MessageDigest messageDigest = null;\n try {\n messageDigest = MessageDigest.getInstance(\"MD5\");\n } catch (NoSuchAlgorithmException e) {\n throw new RuntimeException(e);\n }\n FileInputStream fis = new FileInputStream(file);\n\n byte[] dataBytes = new byte[1024];\n\n int unread = 0;\n while ((unread = fis.read(dataBytes)) != -1) {\n messageDigest.update(dataBytes, 0, unread);\n }\n byte[] mdbytes = messageDigest.digest();\n StringBuilder sb = new StringBuilder();\n for (byte mdbyte : mdbytes) {\n sb.append(Integer.toString((mdbyte & 0xff) + 0x100, 16).substring(1));\n }\n return sb.toString();\n }\n}\n
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/ThreadedCompare.java b/src/ThreadedCompare.java
--- a/src/ThreadedCompare.java (revision 529322e933c3315c287f3b352957b605fec7ba91)
+++ b/src/ThreadedCompare.java (date 1672749422338)
@@ -20,21 +20,17 @@
for (Path file2 : pathsToCompareTo) {
try {
if (sameContent(file1, file2)) {
- List bothPaths = new ArrayList<>();
- bothPaths.add(file1);
- bothPaths.add(file2);
+ List bothList = new ArrayList<>();
+
+ bothList.add(file1);
+ bothList.add(file2);
//here it is trying to add the values in the HashMap
- if (Main.fileMap.containsKey(getMD5Sum(file1.toFile()))) {
- if (!Main.fileMap.get(getMD5Sum(file1.toFile())).contains(file1)) {
- Main.fileMap.get(getMD5Sum(file1.toFile())).add(file1);
- }
- if (!Main.fileMap.get(getMD5Sum(file1.toFile())).contains(file2)) {
- Main.fileMap.get(getMD5Sum(file1.toFile())).add(file2);
- }
- } else {
- Main.fileMap.put(getMD5Sum(file1.toFile()), bothPaths);
- }
+ Main.fileMap.putIfAbsent(getMD5Sum(file1.toFile()), bothList);
+
+ Main.fileMap.get(getMD5Sum(file1.toFile())).removeAll(bothList);
+ Main.fileMap.get(getMD5Sum(file1.toFile())).addAll(bothList);
+
}
} catch (IOException e) {
throw new RuntimeException(e);