mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 10:33:30 +08:00
Standardise implementations
This commit is contained in:
parent
63bc415565
commit
1d962648c2
@ -151,25 +151,29 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
public override string ToString() => this.GetDisplayTitle();
|
||||
|
||||
public bool Equals(IBeatmapInfo other)
|
||||
public bool Equals(BeatmapInfo other)
|
||||
{
|
||||
if (other is BeatmapInfo b)
|
||||
return Equals(b);
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (other == null) return false;
|
||||
|
||||
if (OnlineID > 0 && other?.OnlineID > 0)
|
||||
return other.OnlineID == OnlineID;
|
||||
if (ID != 0 && other.ID != 0)
|
||||
return ID == other.ID;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Equals(BeatmapInfo other)
|
||||
public bool Equals(IBeatmapInfo other)
|
||||
{
|
||||
if (ID == 0 || other?.ID == 0)
|
||||
// one of the two BeatmapInfos we are comparing isn't sourced from a database.
|
||||
// fall back to reference equality.
|
||||
return ReferenceEquals(this, other);
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (other == null) return false;
|
||||
|
||||
return ID == other?.ID;
|
||||
if (other is BeatmapInfo b && Equals(b))
|
||||
return true;
|
||||
|
||||
if (OnlineID > 0 && other.OnlineID > 0)
|
||||
return other.OnlineID == OnlineID;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool AudioEquals(BeatmapInfo other) => other != null && BeatmapSet != null && other.BeatmapSet != null &&
|
||||
|
@ -66,32 +66,29 @@ namespace osu.Game.Beatmaps
|
||||
|
||||
public bool Protected { get; set; }
|
||||
|
||||
public bool Equals(IBeatmapSetInfo other)
|
||||
{
|
||||
if (other is BeatmapSetInfo b)
|
||||
return Equals(b);
|
||||
|
||||
if (OnlineID > 0 && other?.OnlineID > 0)
|
||||
return other.OnlineID == OnlineID;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Equals(BeatmapSetInfo other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (other == null) return false;
|
||||
|
||||
if (ID != 0 && other.ID != 0)
|
||||
return ID == other.ID;
|
||||
|
||||
if (OnlineBeatmapSetID.HasValue && other.OnlineBeatmapSetID.HasValue)
|
||||
return OnlineBeatmapSetID == other.OnlineBeatmapSetID;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Hash) && !string.IsNullOrEmpty(other.Hash))
|
||||
return Hash == other.Hash;
|
||||
public bool Equals(IBeatmapSetInfo other)
|
||||
{
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (other == null) return false;
|
||||
|
||||
return ReferenceEquals(this, other);
|
||||
if (other is BeatmapSetInfo b && Equals(b))
|
||||
return true;
|
||||
|
||||
if (OnlineID > 0 && other.OnlineID > 0)
|
||||
return other.OnlineID == OnlineID;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#region Implementation of IHasOnlineID
|
||||
|
@ -20,7 +20,7 @@ namespace osu.Game.Models
|
||||
[ExcludeFromDynamicCompile]
|
||||
[Serializable]
|
||||
[MapTo("Beatmap")]
|
||||
public class RealmBeatmap : RealmObject, IHasGuidPrimaryKey, IBeatmapInfo
|
||||
public class RealmBeatmap : RealmObject, IHasGuidPrimaryKey, IBeatmapInfo, IEquatable<RealmBeatmap>
|
||||
{
|
||||
[PrimaryKey]
|
||||
public Guid ID { get; set; } = Guid.NewGuid();
|
||||
@ -98,14 +98,28 @@ namespace osu.Game.Models
|
||||
|
||||
#endregion
|
||||
|
||||
public bool Equals(RealmBeatmap? other)
|
||||
{
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (other == null) return false;
|
||||
|
||||
return ID == other.ID;
|
||||
}
|
||||
|
||||
#region Implementation of IEquatable<IBeatmapInfo>
|
||||
|
||||
public bool Equals(IBeatmapInfo? other)
|
||||
{
|
||||
if (other is RealmBeatmap b)
|
||||
return b.ID == ID;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (other == null) return false;
|
||||
|
||||
if (OnlineID > 0 && other?.OnlineID > 0)
|
||||
if (other is RealmBeatmap b && Equals(b))
|
||||
return true;
|
||||
|
||||
if (!string.IsNullOrEmpty(Hash) && !string.IsNullOrEmpty(other.Hash))
|
||||
return Hash == other.Hash;
|
||||
|
||||
if (OnlineID > 0 && other.OnlineID > 0)
|
||||
return other.OnlineID == OnlineID;
|
||||
|
||||
return false;
|
||||
|
@ -53,32 +53,26 @@ namespace osu.Game.Models
|
||||
/// <param name="filename">The name of the file to get the storage path of.</param>
|
||||
public string? GetPathForFile(string filename) => Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.File.StoragePath;
|
||||
|
||||
public bool Equals(IBeatmapSetInfo? other)
|
||||
{
|
||||
if (other is RealmBeatmapSet b)
|
||||
return b.ID == ID;
|
||||
|
||||
if (OnlineID > 0 && other?.OnlineID > 0)
|
||||
return other.OnlineID == OnlineID;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Equals(RealmBeatmapSet? other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (other == null) return false;
|
||||
|
||||
if (IsManaged && other.IsManaged)
|
||||
return ID == other.ID;
|
||||
return ID == other.ID;
|
||||
}
|
||||
|
||||
public bool Equals(IBeatmapSetInfo? other)
|
||||
{
|
||||
if (ReferenceEquals(this, other)) return true;
|
||||
if (other == null) return false;
|
||||
|
||||
if (other is RealmBeatmapSet b && Equals(b))
|
||||
return true;
|
||||
|
||||
if (OnlineID > 0 && other.OnlineID > 0)
|
||||
return OnlineID == other.OnlineID;
|
||||
|
||||
if (!string.IsNullOrEmpty(Hash) && !string.IsNullOrEmpty(other.Hash))
|
||||
return Hash == other.Hash;
|
||||
|
||||
return ReferenceEquals(this, other);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString() => Metadata?.ToString() ?? base.ToString();
|
||||
|
Loading…
Reference in New Issue
Block a user