From da2da53e28b711b42a16a464133987899897dde6 Mon Sep 17 00:00:00 2001 From: Lorenzo Date: Mon, 8 Jul 2024 15:26:57 +0200 Subject: [PATCH] fix: make RankingSummaryStudent comparable --- .../Utils/Output/RankingSummaryStudent.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/PoliNetwork.Graduatorie.Parser/Utils/Output/RankingSummaryStudent.cs b/PoliNetwork.Graduatorie.Parser/Utils/Output/RankingSummaryStudent.cs index 52e783ef..a9ef094c 100644 --- a/PoliNetwork.Graduatorie.Parser/Utils/Output/RankingSummaryStudent.cs +++ b/PoliNetwork.Graduatorie.Parser/Utils/Output/RankingSummaryStudent.cs @@ -11,7 +11,7 @@ namespace PoliNetwork.Graduatorie.Parser.Utils.Output; [Serializable] [JsonObject(MemberSerialization.Fields, NamingStrategyType = typeof(CamelCaseNamingStrategy))] -public class RankingSummaryStudent : IEquatable +public class RankingSummaryStudent : IEquatable, IComparable { public readonly string? Course; public readonly string? Phase; @@ -48,21 +48,24 @@ public bool Equals(RankingSummaryStudent? other) Year == other.Year; } - public int Compare(RankingSummaryStudent o) + public int CompareTo(RankingSummaryStudent? other) { - var i = (Year ?? 0) - (o.Year ?? 0); + if (ReferenceEquals(this, other)) return 0; + if (ReferenceEquals(null, other)) return 1; + + var i = (Year ?? 0) - (other.Year ?? 0); if (i != 0) return i < 0 ? -1 : 1; - i = string.CompareOrdinal(Course ?? "", o.Course ?? ""); + i = string.CompareOrdinal(Course ?? "", other.Course ?? ""); if (i != 0) return i < 0 ? -1 : 1; - i = string.CompareOrdinal(Phase ?? "", o.Phase ?? ""); + i = string.CompareOrdinal(Phase ?? "", other.Phase ?? ""); if (i != 0) return i < 0 ? -1 : 1; - i = (int)(School ?? SchoolEnum.Unknown) - (int)(o.School ?? SchoolEnum.Unknown); + i = (int)(School ?? SchoolEnum.Unknown) - (int)(other.School ?? SchoolEnum.Unknown); if (i != 0) return i < 0 ? -1 : 1; - i = Url?.CompareTo(o.Url) ?? 0; + i = Url?.CompareTo(other.Url) ?? 0; if (i != 0) return i < 0 ? -1 : 1;