Skip to content

Commit

Permalink
ref - Refactored part comparison
Browse files Browse the repository at this point in the history
---

Type: ref
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 9, 2024
1 parent 4edc659 commit c18d734
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 81 deletions.
70 changes: 18 additions & 52 deletions VisualCard.Calendar/Parts/Comparers/PartComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,8 @@ internal static bool PartsArrayEnumEqual(
if (!exists)
return false;

// Verify the lists
if (!VerifyLists(kvp.Value, parts))
return false;

// Now, compare between two parts
List<bool> results = [];
for (int i = 0; i < parts.Count; i++)
{
BaseCalendarPartInfo sourcePart = kvp.Value[i];
BaseCalendarPartInfo targetPart = parts[i];
bool equals = sourcePart == targetPart;
results.Add(equals);
}
return !results.Contains(false);
// Compare between the lists
return CompareLists(kvp.Value, parts);
});
return equal;
}
Expand All @@ -81,20 +69,8 @@ internal static bool StringsEqual(
if (!exists)
return false;

// Verify the lists
if (!VerifyLists(kvp.Value, parts))
return false;

// Now, compare between two parts
List<bool> results = [];
for (int i = 0; i < parts.Count; i++)
{
CalendarValueInfo<string> sourcePart = kvp.Value[i];
CalendarValueInfo<string> targetPart = parts[i];
bool equals = sourcePart == targetPart;
results.Add(equals);
}
return !results.Contains(false);
// Compare between the lists
return CompareLists(kvp.Value, parts);
});
return equal;
}
Expand All @@ -118,43 +94,33 @@ internal static bool IntegersEqual(
if (!exists)
return false;

// Verify the lists
if (!VerifyLists(kvp.Value, parts))
return false;

// Now, compare between two parts
List<bool> results = [];
for (int i = 0; i < parts.Count; i++)
{
CalendarValueInfo<double> sourcePart = kvp.Value[i];
CalendarValueInfo<double> targetPart = parts[i];
bool equals = sourcePart == targetPart;
results.Add(equals);
}
return !results.Contains(false);
// Compare between the lists
return CompareLists(kvp.Value, parts);
});
return equal;
}

internal static bool CompareCalendarComponents<TComponent>(
IList<TComponent> source,
IList<TComponent> target)
where TComponent : Calendar
where TComponent : Calendar =>
CompareLists(source, target);

internal static bool CompareLists<TValue>(
IList<TValue> source,
IList<TValue> target)
{
// Verify the lists
if (!VerifyLists(source, target))
return false;

// If they are really equal using the equals operator, return true.
if (source == target)
return true;

// Now, test the equality
// Now, compare between two parts
List<bool> results = [];
for (int i = 0; i < source.Count; i++)
for (int i = 0; i < target.Count; i++)
{
TComponent sourcePart = source[i];
TComponent targetPart = target[i];
bool equals = sourcePart == targetPart;
TValue sourcePart = source[i];
TValue targetPart = target[i];
bool equals = sourcePart?.Equals(targetPart) ?? false;
results.Add(equals);
}
return !results.Contains(false);
Expand Down
34 changes: 5 additions & 29 deletions VisualCard/Parts/Comparers/PartComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,12 @@ internal static bool PartsArrayEnumEqual(
// Now, test the equality
bool equal = source.All(kvp =>
{
bool exists = target.TryGetValue(kvp.Key, out List<BaseCardPartInfo> parts);
bool exists = target.TryGetValue(kvp.Key, out var parts);
if (!exists)
return false;

// Verify the lists
if (!VerifyLists(kvp.Value, parts))
return false;

// Now, compare between two parts
List<bool> results = [];
for (int i = 0; i < parts.Count; i++)
{
BaseCardPartInfo sourcePart = kvp.Value[i];
BaseCardPartInfo targetPart = parts[i];
bool equals = sourcePart == targetPart;
results.Add(equals);
}
return !results.Contains(false);
// Compare between the lists
return CompareLists(kvp.Value, parts);
});
return equal;
}
Expand All @@ -81,20 +69,8 @@ internal static bool StringsEqual(
if (!exists)
return false;

// Verify the lists
if (!VerifyLists(kvp.Value, parts))
return false;

// Now, compare between two parts
List<bool> results = [];
for (int i = 0; i < parts.Count; i++)
{
CardValueInfo<string> sourcePart = kvp.Value[i];
CardValueInfo<string> targetPart = parts[i];
bool equals = sourcePart == targetPart;
results.Add(equals);
}
return !results.Contains(false);
// Compare between the lists
return CompareLists(kvp.Value, parts);
});
return equal;
}
Expand Down

0 comments on commit c18d734

Please sign in to comment.