-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupedFolderSet.cs
57 lines (50 loc) · 1.29 KB
/
GroupedFolderSet.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Text;
namespace DupsBegone
{
public class GroupedFolderSet : Dictionary<string, List<FolderItem>>
{
public GroupedFolderSet() : base()
{
}
public int AddFolder( string hash, FolderItem folder )
{
List<FolderItem> folderList;
if ( this.TryGetValue(hash, out folderList) ) {
folderList.Add(folder);
} else {
folderList = new List<FolderItem>();
folderList.Add(folder);
this.Add(hash, folderList);
}
return folderList.Count;
}
/// <summary>
/// Return a form of this object with non-duplicates removed.
/// </summary>
/// <returns>The non dups removed.</returns>
public GroupedFolderSet WithNonDupsRemoved()
{
var gfs = new GroupedFolderSet();
foreach (KeyValuePair<string,List<FolderItem>> kvp in this) {
if ( kvp.Value.Count > 1 )
gfs.Add(kvp.Key, kvp.Value);
}
return gfs;
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
List<FolderItem> folderList;
foreach (KeyValuePair<string,List<FolderItem>> kvp in this) {
folderList = kvp.Value;
sb.AppendLine("Group:" + kvp.Key );
foreach (FolderItem fi in folderList) {
sb.AppendLine("..Item Path:" + fi.getFullPath());
}
}
return sb.ToString();
}
}
}