[chore:] implemented intersection (combiner) and its usage
This commit is contained in:
@@ -22,6 +22,7 @@ public class CombineAddresses
|
||||
{
|
||||
if (type == "difference") return Difference(address_lists);
|
||||
if (type == "union") return Union(address_lists);
|
||||
if (type == "intersection") return Intersection(address_lists);
|
||||
|
||||
return null;
|
||||
});
|
||||
@@ -115,12 +116,10 @@ public class CombineAddresses
|
||||
result.KasPersons.Add(person);
|
||||
|
||||
progress.Increment();
|
||||
if (progress.LogAction != null)
|
||||
{
|
||||
var logMessage =
|
||||
$"Person mit refsid {person.refsid} verglichen mit {restUnion.Count} Personen des Restes.";
|
||||
await Dispatcher.UIThread.InvokeAsync(() => progress.LogAction?.Invoke(logMessage));
|
||||
}
|
||||
if (progress.LogAction == null) continue;
|
||||
var logMessage =
|
||||
$"Person mit refsid {person.refsid} verglichen mit {restUnion.Count} Personen des Restes.";
|
||||
await Dispatcher.UIThread.InvokeAsync(() => progress.LogAction?.Invoke(logMessage));
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -148,7 +147,51 @@ public class CombineAddresses
|
||||
var logMessage =
|
||||
$"{percent:F1}%: Person mit {person.refsid} hinzugefügt (aktuell {result.KasPersons.Count} Einträge)";
|
||||
|
||||
// Sicher, nicht blockierend:
|
||||
if (progress == null) continue;
|
||||
if (Dispatcher.UIThread.CheckAccess())
|
||||
progress.LogAction?.Invoke(logMessage);
|
||||
else
|
||||
Dispatcher.UIThread.Post(() => progress.LogAction?.Invoke(logMessage));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public async Task<KasAddressList> MoveDuplicatesToNew()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<KasAddressList> Intersection(List<KasAddressList> address_lists, Progress progress = null)
|
||||
{
|
||||
var result = new KasAddressList("intersection");
|
||||
|
||||
if (address_lists == null || address_lists.Count == 0)
|
||||
return result;
|
||||
|
||||
// Nur die erste Liste als Ausgangspunkt verwenden
|
||||
var baseList = address_lists[0];
|
||||
var otherLists = address_lists.Skip(1).ToList();
|
||||
|
||||
var total = baseList.KasPersons.Count;
|
||||
var processed = 0;
|
||||
|
||||
foreach (var person in baseList.KasPersons)
|
||||
{
|
||||
// Prüfen, ob Person in *allen* anderen Listen vorkommt
|
||||
var isInAll = otherLists.All(list =>
|
||||
list.KasPersons.Any(existing => CompareAddresses(existing, person)));
|
||||
|
||||
if (isInAll)
|
||||
result.KasPersons.Add(person);
|
||||
|
||||
processed++;
|
||||
var percent = processed / (double)total * 100;
|
||||
var logMessage =
|
||||
$"{percent:F1}%: Person mit {person.refsid} geprüft – {(isInAll ? "in allen enthalten" : "nicht überall vorhanden")}";
|
||||
|
||||
// Sicher und nicht blockierend loggen
|
||||
if (progress != null)
|
||||
{
|
||||
if (Dispatcher.UIThread.CheckAccess())
|
||||
@@ -162,16 +205,6 @@ public class CombineAddresses
|
||||
}
|
||||
|
||||
|
||||
public async Task<KasAddressList> MoveDuplicatesToNew()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<KasAddressList> Intersection()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<KasAddressList> SymmetricDifference()
|
||||
{
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user