Skip to content

Commit

Permalink
add - Added calendar component comparison
Browse files Browse the repository at this point in the history
---

From now on, you can compare between two similar calendar components, as long as they are of the same type.

---

Type: add
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 11, 2024
1 parent 58bc6f0 commit ea2d75c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 8 deletions.
14 changes: 12 additions & 2 deletions VisualCard.Calendar/Parts/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,24 @@ public bool Equals(Calendar source, Calendar target)
return
PartComparison.PartsArrayEnumEqual(source.partsArray, target.partsArray) &&
PartComparison.StringsEqual(source.strings, target.strings) &&
PartComparison.IntegersEqual(source.integers, target.integers)
PartComparison.IntegersEqual(source.integers, target.integers) &&
PartComparison.CompareCalendarComponents(source.events, target.events) &&
PartComparison.CompareCalendarComponents(source.todos, target.todos) &&
PartComparison.CompareCalendarComponents(source.journals, target.journals) &&
PartComparison.CompareCalendarComponents(source.freeBusyList, target.freeBusyList) &&
PartComparison.CompareCalendarComponents(source.timeZones, target.timeZones)
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 946631297;
int hashCode = -1266621595;
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarEvent>>.Default.GetHashCode(events);
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarTodo>>.Default.GetHashCode(todos);
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarJournal>>.Default.GetHashCode(journals);
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarFreeBusy>>.Default.GetHashCode(freeBusyList);
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarTimeZone>>.Default.GetHashCode(timeZones);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
Expand Down
6 changes: 4 additions & 2 deletions VisualCard.Calendar/Parts/CalendarEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,17 @@ public bool Equals(CalendarEvent source, CalendarEvent target)
return
PartComparison.PartsArrayEnumEqual(source.partsArray, target.partsArray) &&
PartComparison.StringsEqual(source.strings, target.strings) &&
PartComparison.IntegersEqual(source.integers, target.integers)
PartComparison.IntegersEqual(source.integers, target.integers) &&
PartComparison.CompareCalendarComponents(source.alarms, target.alarms)
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 1333672311;
int hashCode = -177474982;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarAlarm>>.Default.GetHashCode(alarms);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
Expand Down
8 changes: 6 additions & 2 deletions VisualCard.Calendar/Parts/CalendarTimeZone.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,19 @@ public bool Equals(CalendarTimeZone source, CalendarTimeZone target)
return
PartComparison.PartsArrayEnumEqual(source.partsArray, target.partsArray) &&
PartComparison.StringsEqual(source.strings, target.strings) &&
PartComparison.IntegersEqual(source.integers, target.integers)
PartComparison.IntegersEqual(source.integers, target.integers) &&
PartComparison.CompareCalendarComponents(source.standards, target.standards) &&
PartComparison.CompareCalendarComponents(source.daylights, target.daylights)
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 1333672311;
int hashCode = -1226557388;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarStandard>>.Default.GetHashCode(standards);
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarDaylight>>.Default.GetHashCode(daylights);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
Expand Down
6 changes: 4 additions & 2 deletions VisualCard.Calendar/Parts/CalendarTodo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,17 @@ public bool Equals(CalendarTodo source, CalendarTodo target)
return
PartComparison.PartsArrayEnumEqual(source.partsArray, target.partsArray) &&
PartComparison.StringsEqual(source.strings, target.strings) &&
PartComparison.IntegersEqual(source.integers, target.integers)
PartComparison.IntegersEqual(source.integers, target.integers) &&
PartComparison.CompareCalendarComponents(source.alarms, target.alarms)
;
}

/// <inheritdoc/>
public override int GetHashCode()
{
int hashCode = 1333672311;
int hashCode = -177474982;
hashCode = hashCode * -1521134295 + base.GetHashCode();
hashCode = hashCode * -1521134295 + EqualityComparer<List<CalendarAlarm>>.Default.GetHashCode(alarms);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarPartsArrayEnum, List<BaseCalendarPartInfo>>>.Default.GetHashCode(partsArray);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarStringsEnum, string>>.Default.GetHashCode(strings);
hashCode = hashCode * -1521134295 + EqualityComparer<Dictionary<CalendarIntegersEnum, int>>.Default.GetHashCode(integers);
Expand Down
24 changes: 24 additions & 0 deletions VisualCard.Calendar/Parts/Comparers/PartComparison.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,30 @@ internal static bool IntegersEqual(
return equal;
}

internal static bool CompareCalendarComponents<TComponent>(
IList<TComponent> source,
IList<TComponent> target)
where TComponent : Calendar
{
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
List<bool> results = [];
for (int i = 0; i < source.Count; i++)
{
TComponent sourcePart = source[i];
TComponent targetPart = target[i];
bool equals = sourcePart == targetPart;
results.Add(equals);
}
return !results.Contains(false);
}

private static bool VerifyLists<TValue>(
IList<TValue> source,
IList<TValue> target)
Expand Down

0 comments on commit ea2d75c

Please sign in to comment.