diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index aa72b15..7b7b9ca 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -10,7 +10,9 @@
-
+
+
+
@@ -72,7 +74,7 @@
-
+
@@ -260,7 +262,14 @@
1679508433400
-
+
+ 1679508468115
+
+
+
+ 1679508468115
+
+
diff --git a/src/Main.java b/src/Main.java
index 92a1d33..93ed1f4 100644
--- a/src/Main.java
+++ b/src/Main.java
@@ -121,7 +121,8 @@ public class Main {
//sectionedList gives the thread their Assigned Part of Files and allFiles are all the Files
- ThreadedCompare threadedCompare = new ThreadedCompare(sectionedList, allFiles);
+
+ ThreadedCompare threadedCompare = new ThreadedCompare(sectionedList);
threadedCompare.start();
}
@@ -136,6 +137,13 @@ public class Main {
}
}
+ ArrayList toRemove = new ArrayList();
+ for (String md5: fileMap.keySet()) {
+ if (Main.fileMap.get(md5).size() == 1) {
+ toRemove.add(md5);
+ }
+ }
+ fileMap.keySet().removeAll(toRemove);
//now everything is finished and the Filemap (hashmap with all Dups) can be printed out in a nice view
//System.out.println(fileMap);
diff --git a/src/ThreadedCompare.java b/src/ThreadedCompare.java
index a4203a9..358c5d9 100644
--- a/src/ThreadedCompare.java
+++ b/src/ThreadedCompare.java
@@ -4,55 +4,49 @@ import java.nio.file.Path;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
public class ThreadedCompare extends Thread {
private final List pathsToCompareTo;
- private final List pathsToBeCompared;
- public ThreadedCompare (List pathsToBeCompared, List pathsToCompareTo) {
- this.pathsToBeCompared = pathsToBeCompared;
+ //private HashMap> threadFileMap = new HashMap<>();
+
+ public ThreadedCompare (List pathsToCompareTo) {
+
this.pathsToCompareTo = pathsToCompareTo;
}
@Override
public void run() {
- //Compare every File
- for (Path file1 : pathsToBeCompared) {
- for (Path file2 : pathsToCompareTo) {
- 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(md5, bothList);
-
- if (!bothList.isEmpty()) {
-
- Main.fileMap.get(md5).remove(file1);
- Main.fileMap.get(md5).remove(file2);
- Main.fileMap.get(md5).addAll(bothList);
- }
-
-
- }
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ for (Path file : pathsToCompareTo) {
+ List fileArray = new ArrayList<>();
+ assert fileArray != null;
+ fileArray.add(file);
+ String MD5;
+ try {
+ MD5 = getMD5Sum(file.toFile());
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
- //Update the Progress that can be found in The Main Class
- Main.progress += 1;
+
+
+ if (Main.fileMap.containsKey(MD5)) {
+ fileArray.addAll(Main.fileMap.get(MD5));
+ Main.fileMap.put(MD5, fileArray);
+ } else {
+ Main.fileMap.put(MD5, fileArray);
+ }
+
+
+ Main.progress++;
}
- //Update the thread Completion Counter that can be found in the Main Class
- Main.completedThreads += 1;
- }
- private boolean sameContent(Path file1, Path file2) throws IOException {
- if (file1 != file2) {
- return Files.mismatch(file1, file2) == -1;
- }
- return false;
+
+
+ Main.completedThreads++;
+
+
+
+
+
}
//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)