Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Feb 1, 2025
1 parent 87da4fc commit 74c5701
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions JL.Core/Dicts/JMdict/KanjiElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ public bool Equals(KanjiElement other)
{
return Keb == other.Keb && KeInfList.SequenceEqual(other.KeInfList);
}

public static bool operator ==(KanjiElement left, KanjiElement right) => left.Equals(right);
public static bool operator !=(KanjiElement left, KanjiElement right) => !left.Equals(right);
}
3 changes: 3 additions & 0 deletions JL.Core/Dicts/JMdict/ReadingElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ public bool Equals(ReadingElement other)
&& ReRestrList.SequenceEqual(other.ReRestrList)
&& ReInfList.SequenceEqual(other.ReInfList);
}

public static bool operator ==(in ReadingElement left, in ReadingElement right) => left.Equals(right);
public static bool operator !=(in ReadingElement left, in ReadingElement right) => !left.Equals(right);
}
3 changes: 3 additions & 0 deletions JL.Core/Dicts/JMnedict/Translation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ public bool Equals(Translation other)
{
return NameTypeList.SequenceEqual(other.NameTypeList) && TransDetList.SequenceEqual(other.TransDetList);
}

public static bool operator ==(Translation left, Translation right) => left.Equals(right);
public static bool operator !=(Translation left, Translation right) => !left.Equals(right);
}
30 changes: 28 additions & 2 deletions JL.Core/Freqs/Freq.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System.Collections.Frozen;
using System.Text.Json.Serialization;
using JL.Core.Freqs.Options;

namespace JL.Core.Freqs;

public sealed class Freq(FreqType type, string name, string path, bool active, int priority, int size, int maxValue, FreqOptions options)
public sealed class Freq(FreqType type, string name, string path, bool active, int priority, int size, int maxValue, FreqOptions options) : IEquatable<Freq>
{
public FreqType Type { get; } = type;
public string Name { get; set; } = name;
Expand All @@ -24,4 +23,31 @@ public sealed class Freq(FreqType type, string name, string path, bool active, i
[JsonIgnore] public IDictionary<string, IList<FrequencyRecord>> Contents { get; set; } = FrozenDictionary<string, IList<FrequencyRecord>>.Empty;
#pragma warning restore CA2227


public override int GetHashCode()
{
unchecked
{
int hash = (17 * 37) + Name.GetHashCode(StringComparison.OrdinalIgnoreCase);
hash = (hash * 37) + Path.GetHashCode(StringComparison.OrdinalIgnoreCase);
hash = (hash * 37) + Type.GetHashCode();
return hash;
}
}

public override bool Equals(object? obj)
{
return obj is Freq other
&& string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Path, other.Path, StringComparison.OrdinalIgnoreCase)
&& Type == other.Type;
}

public bool Equals(Freq? other)
{
return other is not null
&& string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Path, other.Path, StringComparison.OrdinalIgnoreCase)
&& Type == other.Type;
}
}

0 comments on commit 74c5701

Please sign in to comment.