Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Feb 2, 2025
1 parent 4b5c33f commit 6900ba3
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 149 deletions.
2 changes: 1 addition & 1 deletion JL.Core.Tests/Deconjugation/DeconjugatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Deconjugate_わからない()
bool success = false;
foreach (Form form in result)
{
if (form.Text is expectedText && form.Process.Count > 0 && form.Process[0] is expectedProcess)
if (form is { Text: expectedText, Process.Count: > 0 } && form.Process[0] is expectedProcess)
{
success = true;
break;
Expand Down
6 changes: 3 additions & 3 deletions JL.Core.Tests/LookupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ public void LookupText_始まる()

// Assert
Assert.That(actual, Is.EqualTo(expected)
.Using<LookupResult, LookupResult>((a, e) =>
.Using<LookupResult, LookupResult>(static (a, e) =>
a.MatchedText == e.MatchedText
&& a.Dict == e.Dict
&& (e.Frequencies is not null ? (a.Frequencies?.SequenceEqual(e.Frequencies) ?? false) : a.Frequencies is null)
&& (e.Frequencies is not null ? a.Frequencies?.SequenceEqual(e.Frequencies) ?? false : a.Frequencies is null)
&& a.PrimarySpelling == e.PrimarySpelling
&& a.DeconjugatedMatchedText == e.DeconjugatedMatchedText
&& (e.Readings is not null ? (a.Readings?.SequenceEqual(e.Readings) ?? false) : a.Readings is null)
&& (e.Readings is not null ? a.Readings?.SequenceEqual(e.Readings) ?? false : a.Readings is null)
&& a.FormattedDefinitions == e.FormattedDefinitions
&& a.EntryId == e.EntryId));
}
Expand Down
4 changes: 2 additions & 2 deletions JL.Core/Deconjugation/Form.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public override int GetHashCode()
}
}

public static bool operator ==(Form? left, Form? right) => left is not null ? left.Equals(right) : right is null;
public static bool operator !=(Form? left, Form? right) => left is not null ? !left.Equals(right) : right is not null;
public static bool operator ==(Form? left, Form? right) => left?.Equals(right) ?? right is null;
public static bool operator !=(Form? left, Form? right) => !left?.Equals(right) ?? right is not null;
}
4 changes: 2 additions & 2 deletions JL.Core/Dicts/CustomWordDict/CustomWordRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,6 @@ public override int GetHashCode()
}
}

public static bool operator ==(CustomWordRecord? left, CustomWordRecord? right) => left is not null ? left.Equals(right) : right is null;
public static bool operator !=(CustomWordRecord? left, CustomWordRecord? right) => left is not null ? !left.Equals(right) : right is not null;
public static bool operator ==(CustomWordRecord? left, CustomWordRecord? right) => left?.Equals(right) ?? right is null;
public static bool operator !=(CustomWordRecord? left, CustomWordRecord? right) => !left?.Equals(right) ?? right is not null;
}
29 changes: 1 addition & 28 deletions JL.Core/Dicts/Dict.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace JL.Core.Dicts;

public sealed class Dict(DictType type, string name, string path, bool active, int priority, int size, DictOptions options) : IEquatable<Dict>
public sealed class Dict(DictType type, string name, string path, bool active, int priority, int size, DictOptions options)
{
public DictType Type { get; } = type;
public string Name { get; set; } = name;
Expand All @@ -21,31 +21,4 @@ public sealed class Dict(DictType type, string name, string path, bool active, i
#pragma warning disable CA2227
[JsonIgnore] public IDictionary<string, IList<IDictRecord>> Contents { get; set; } = FrozenDictionary<string, IList<IDictRecord>>.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 Dict other
&& string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Path, other.Path, StringComparison.OrdinalIgnoreCase)
&& Type == other.Type;
}

public bool Equals(Dict? other)
{
return other is not null
&& string.Equals(Name, other.Name, StringComparison.OrdinalIgnoreCase)
&& string.Equals(Path, other.Path, StringComparison.OrdinalIgnoreCase)
&& Type == other.Type;
}
}
4 changes: 2 additions & 2 deletions JL.Core/Dicts/EPWING/Nazeka/EpwingNazekaRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ public override int GetHashCode()
}
}

public static bool operator ==(EpwingNazekaRecord? left, EpwingNazekaRecord? right) => left is not null ? left.Equals(right) : right is null;
public static bool operator !=(EpwingNazekaRecord? left, EpwingNazekaRecord? right) => left is not null ? !left.Equals(right) : right is not null;
public static bool operator ==(EpwingNazekaRecord? left, EpwingNazekaRecord? right) => left?.Equals(right) ?? right is null;
public static bool operator !=(EpwingNazekaRecord? left, EpwingNazekaRecord? right) => !left?.Equals(right) ?? right is not null;
}
4 changes: 2 additions & 2 deletions JL.Core/Dicts/EPWING/Yomichan/EpwingYomichanRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,6 @@ public override int GetHashCode()
}
}

public static bool operator ==(EpwingYomichanRecord? left, EpwingYomichanRecord? right) => left is not null ? left.Equals(right) : right is null;
public static bool operator !=(EpwingYomichanRecord? left, EpwingYomichanRecord? right) => left is not null ? !left.Equals(right) : right is not null;
public static bool operator ==(EpwingYomichanRecord? left, EpwingYomichanRecord? right) => left?.Equals(right) ?? right is null;
public static bool operator !=(EpwingYomichanRecord? left, EpwingYomichanRecord? right) => !left?.Equals(right) ?? right is not null;
}
4 changes: 2 additions & 2 deletions JL.Core/Dicts/JMdict/JmdictRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,6 @@ public override int GetHashCode()
}
}

public static bool operator ==(JmdictRecord? left, JmdictRecord? right) => left is not null ? left.Equals(right) : right is null;
public static bool operator !=(JmdictRecord? left, JmdictRecord? right) => left is not null ? !left.Equals(right) : right is not null;
public static bool operator ==(JmdictRecord? left, JmdictRecord? right) => left?.Equals(right) ?? right is null;
public static bool operator !=(JmdictRecord? left, JmdictRecord? right) => !left?.Equals(right) ?? right is not null;
}
8 changes: 4 additions & 4 deletions JL.Core/Dicts/JMdict/JmdictRecordBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ private static (string[]?[]? exclusiveWordClasses, string[]? wordClassesSharedBy

return wordClassesSharedByAllSensesList.Count is 0
? (wordClasses.TrimToArray(), null)
: exclusiveWordClassesList.All(ewc => ewc is null)
: exclusiveWordClassesList.All(static ewc => ewc is null)
? (null, wordClassesSharedByAllSensesList.TrimToArray())
: (exclusiveWordClassesList.Select(ewc => ewc?.TrimToArray()).ToArray(), wordClassesSharedByAllSensesList.TrimToArray());
: (exclusiveWordClassesList.Select(static ewc => ewc?.TrimToArray()).ToArray(), wordClassesSharedByAllSensesList.TrimToArray());
}

private static (string[]?[]? exclusiveSenseFieldValues, string[]? fieldValuesSharedByAllSenses) GetSenseFields(List<string[]?> senseField)
Expand Down Expand Up @@ -384,8 +384,8 @@ private static (string[]?[]? exclusiveSenseFieldValues, string[]? fieldValuesSha

return fieldValuesSharedByAllSenses.Count is 0
? (senseField.TrimListOfNullableElementsToArray(), null)
: exclusiveSenseFieldValues.All(ewc => ewc is null)
: exclusiveSenseFieldValues.All(static ewc => ewc is null)
? (null, fieldValuesSharedByAllSenses.TrimToArray())
: (exclusiveSenseFieldValues.Select(ewc => ewc?.TrimToArray()).ToArray(), fieldValuesSharedByAllSenses.TrimToArray());
: (exclusiveSenseFieldValues.Select(static ewc => ewc?.TrimToArray()).ToArray(), fieldValuesSharedByAllSenses.TrimToArray());
}
}
4 changes: 2 additions & 2 deletions JL.Core/Dicts/JMnedict/JmnedictRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ public override int GetHashCode()
}
}

public static bool operator ==(JmnedictRecord? left, JmnedictRecord? right) => left is not null ? left.Equals(right) : right is null;
public static bool operator !=(JmnedictRecord? left, JmnedictRecord? right) => left is not null ? !left.Equals(right) : right is not null;
public static bool operator ==(JmnedictRecord? left, JmnedictRecord? right) => left?.Equals(right) ?? right is null;
public static bool operator !=(JmnedictRecord? left, JmnedictRecord? right) => !left?.Equals(right) ?? right is not null;
}
4 changes: 2 additions & 2 deletions JL.Core/Dicts/PitchAccent/PitchAccentRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ public override int GetHashCode()
return HashCode.Combine(Spelling, Reading);
}

public static bool operator ==(PitchAccentRecord? left, PitchAccentRecord? right) => left is not null ? left.Equals(right) : right is null;
public static bool operator !=(PitchAccentRecord? left, PitchAccentRecord? right) => left is not null ? !left.Equals(right) : right is not null;
public static bool operator ==(PitchAccentRecord? left, PitchAccentRecord? right) => left?.Equals(right) ?? right is null;
public static bool operator !=(PitchAccentRecord? left, PitchAccentRecord? right) => !left?.Equals(right) ?? right is not null;
}
30 changes: 1 addition & 29 deletions JL.Core/Freqs/Freq.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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) : IEquatable<Freq>
public sealed class Freq(FreqType type, string name, string path, bool active, int priority, int size, int maxValue, FreqOptions options)
{
public FreqType Type { get; } = type;
public string Name { get; set; } = name;
Expand All @@ -22,32 +22,4 @@ public sealed class Freq(FreqType type, string name, string path, bool active, i
#pragma warning disable CA2227
[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;
}
}
4 changes: 2 additions & 2 deletions JL.Core/Lookup/LookupResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ public bool Equals(LookupResult? other)
&& FormattedDefinitions == other.FormattedDefinitions;
}

public static bool operator ==(LookupResult? left, LookupResult? right) => left is not null ? left.Equals(right) : right is null;
public static bool operator !=(LookupResult? left, LookupResult? right) => left is not null ? !left.Equals(right) : right is not null;
public static bool operator ==(LookupResult? left, LookupResult? right) => left?.Equals(right) ?? right is null;
public static bool operator !=(LookupResult? left, LookupResult? right) => !left?.Equals(right) ?? right is not null;
}
65 changes: 0 additions & 65 deletions JL.Core/Utilities/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,71 +183,6 @@ internal static void AddRange<T>(this ConcurrentBag<T> source, IEnumerable<T> it
: list.ToArray();
}

internal static T[][] ToSingleElementArrayIfIdentical<T>(this List<T[]> list) where T : class
{
if (list.Count is 1)
{
return list.ToArray();
}

T[] firstElemenmt = list[0];
for (int i = 1; i < list.Count; i++)
{
if (!list[i].SequenceEqual(firstElemenmt))
{
return list.ToArray();
}
}

return [firstElemenmt];
}

internal static T[]?[]? TrimListOfNullableElementsToSingleElementArrayIfIdentical<T>(this List<T[]?> list) where T : class
{
if (list.Count is 0)
{
return null;
}

T[]? firstElement = list[0];
if (list.Count is 1)
{
return firstElement is not null
? [firstElement]
: null;
}

bool allElementsAreNull = true;
for (int i = 0; i < list.Count; i++)
{
if (list[i] is not null)
{
allElementsAreNull = false;
break;
}
}

bool allElementsAreIdentical = firstElement is not null;
if (!allElementsAreNull && allElementsAreIdentical)
{
for (int i = 1; i < list.Count; i++)
{
T[]? currentItem = list[i];
if (currentItem is null || !currentItem.SequenceEqual(firstElement!))
{
allElementsAreIdentical = false;
break;
}
}
}

return allElementsAreNull
? null
: allElementsAreIdentical
? [firstElement]
: list.ToArray();
}

internal static string GetPooledString(this string str)
{
return Utils.StringPoolInstance.GetOrAdd(str);
Expand Down
4 changes: 2 additions & 2 deletions JL.Core/WordClass/JmdictWordClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ public override int GetHashCode()
}
}

public static bool operator ==(JmdictWordClass? left, JmdictWordClass? right) => left is not null ? left.Equals(right) : right is null;
public static bool operator !=(JmdictWordClass? left, JmdictWordClass? right) => left is not null ? !left.Equals(right) : right is not null;
public static bool operator ==(JmdictWordClass? left, JmdictWordClass? right) => left?.Equals(right) ?? right is null;
public static bool operator !=(JmdictWordClass? left, JmdictWordClass? right) => !left?.Equals(right) ?? right is not null;
}
2 changes: 1 addition & 1 deletion JL.Core/WordClass/JmdictWordClassUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ internal static Task Serialize()
{
JmdictRecord jmdictRecord = (JmdictRecord)jmdictRecordList[i];
string[] wordClasses = s_usedWordClasses
.Intersect((jmdictRecord.WordClasses?.Where(wc => wc is not null).SelectMany(static wc => wc!) ?? [])
.Intersect((jmdictRecord.WordClasses?.Where(static wc => wc is not null).SelectMany(static wc => wc!) ?? [])
.Union(jmdictRecord.WordClassesSharedByAllSenses ?? [])).ToArray();

if (wordClasses.Length is 0)
Expand Down

0 comments on commit 6900ba3

Please sign in to comment.