Fixed Duplicates in HashMap

This commit is contained in:
bly 2023-01-03 13:37:58 +01:00
parent 529322e933
commit 075bd9511f
2 changed files with 26 additions and 23 deletions

27
.idea/workspace.xml generated
View file

@ -4,10 +4,9 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="9b57ac51-c870-474b-9dfd-64a5fc490635" name="Changes" comment="Just a Test">
<list default="true" id="9b57ac51-c870-474b-9dfd-64a5fc490635" name="Changes" comment="Removing not needed lines">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ConsoleColors.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ConsoleColors.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/ThreadedCompare.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/ThreadedCompare.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -30,12 +29,12 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
@ -73,7 +72,14 @@
<option name="project" value="LOCAL" />
<updated>1672703881482</updated>
</task>
<option name="localTasksCounter" value="5" />
<task id="LOCAL-00005" summary="Removing not needed lines">
<created>1672704560597</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1672704560597</updated>
</task>
<option name="localTasksCounter" value="6" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -102,6 +108,7 @@
<component name="VcsManagerConfiguration">
<MESSAGE value="First Creation" />
<MESSAGE value="Just a Test" />
<option name="LAST_COMMIT_MESSAGE" value="Just a Test" />
<MESSAGE value="Removing not needed lines" />
<option name="LAST_COMMIT_MESSAGE" value="Removing not needed lines" />
</component>
</project>

View file

@ -20,21 +20,17 @@ public class ThreadedCompare extends Thread {
for (Path file2 : pathsToCompareTo) {
try {
if (sameContent(file1, file2)) {
List<Path> bothPaths = new ArrayList<>();
bothPaths.add(file1);
bothPaths.add(file2);
List<Path> 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);