-
-
-\ 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);
diff --git a/.idea/shelf/Uncommitted_changes_before_rebase__Changes_.xml b/.idea/shelf/Uncommitted_changes_before_rebase__Changes_.xml
deleted file mode 100644
index 7ca5b90..0000000
--- a/.idea/shelf/Uncommitted_changes_before_rebase__Changes_.xml
+++ /dev/null
@@ -1,4 +0,0 @@
-
-
-
-
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index a734d54..63a1573 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -10,8 +10,11 @@
+
+
+
diff --git a/src/Main.java b/src/Main.java
index bf337cb..ae4645e 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -21,6 +21,7 @@ public class Main {
boolean showProgress = false;
boolean deleteDups = false;
boolean recordFolder = false;
+ boolean showDebug = false;
List paths = new ArrayList<>();
@@ -35,6 +36,7 @@ public class Main {
if (i.equalsIgnoreCase("-p") || i.equalsIgnoreCase("-progress")) { showProgress = true;}
if (i.equalsIgnoreCase("-f") || i.equalsIgnoreCase("-folder")) { recordFolder = true;}
if (i.equalsIgnoreCase("-d") || i.equalsIgnoreCase("-delete")) { deleteDups = true;}
+ if (i.equalsIgnoreCase("-debug")) { showDebug = true;}
}
@@ -43,9 +45,13 @@ public class Main {
return;
}
- /*System.out.println("Folders: " + paths.size());
- System.out.println("Color: " + doTheColorThingy);
- System.out.println("Progressbar: " + showProgress); */
+ if (showDebug) {
+ System.out.println("Folders: " + paths.size());
+ System.out.println("Color: " + doTheColorThingy);
+ System.out.println("Delete: " + deleteDups);
+ System.out.println("Progressbar: " + showProgress);
+ }
+
List pathList = new ArrayList<>();
List allFiles = new ArrayList<>();
diff --git a/src/ThreadedCompare.java b/src/ThreadedCompare.java
index 795c37f..a4203a9 100644
--- a/src/ThreadedCompare.java
+++ b/src/ThreadedCompare.java
@@ -21,18 +21,19 @@ public class ThreadedCompare extends Thread {
try {
if (sameContent(file1, file2)) {
List bothList = new ArrayList<>();
+ String md5 = getMD5Sum(file1.toFile());
bothList.add(file1);
bothList.add(file2);
//here it is trying to add the values in the HashMap so everything is nice and clear
- Main.fileMap.putIfAbsent(getMD5Sum(file1.toFile()), bothList);
+ Main.fileMap.putIfAbsent(md5, bothList);
if (!bothList.isEmpty()) {
- Main.fileMap.get(getMD5Sum(file1.toFile())).remove(file1);
- Main.fileMap.get(getMD5Sum(file1.toFile())).remove(file2);
- Main.fileMap.get(getMD5Sum(file1.toFile())).addAll(bothList);
+ Main.fileMap.get(md5).remove(file1);
+ Main.fileMap.get(md5).remove(file2);
+ Main.fileMap.get(md5).addAll(bothList);
}