Skip to content

Commit

Permalink
fix: make RankingSummaryStudent comparable
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzocorallo committed Jul 8, 2024
1 parent 1d968a3 commit da2da53
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace PoliNetwork.Graduatorie.Parser.Utils.Output;

[Serializable]
[JsonObject(MemberSerialization.Fields, NamingStrategyType = typeof(CamelCaseNamingStrategy))]
public class RankingSummaryStudent : IEquatable<RankingSummaryStudent>
public class RankingSummaryStudent : IEquatable<RankingSummaryStudent>, IComparable<RankingSummaryStudent>
{
public readonly string? Course;
public readonly string? Phase;
Expand Down Expand Up @@ -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;


Expand Down

0 comments on commit da2da53

Please sign in to comment.