<commit_before>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using Realms;

#nullable enable

namespace osu.Game.Models
{
    [ExcludeFromDynamicCompile]
    [MapTo("BeatmapSet")]
    public class RealmBeatmapSet : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<RealmBeatmapSet>, IBeatmapSetInfo
    {
        [PrimaryKey]
        public Guid ID { get; set; } = Guid.NewGuid();

        [Indexed]
        public int OnlineID { get; set; } = -1;

        public DateTimeOffset DateAdded { get; set; }

        public IBeatmapMetadataInfo? Metadata => Beatmaps.FirstOrDefault()?.Metadata;

        public IList<RealmBeatmap> Beatmaps { get; } = null!;

        public IList<RealmNamedFileUsage> Files { get; } = null!;

        public bool DeletePending { get; set; }

        public string Hash { get; set; } = string.Empty;

        /// <summary>
        /// Whether deleting this beatmap set should be prohibited (due to it being a system requirement to be present).
        /// </summary>
        public bool Protected { get; set; }

        public double MaxStarDifficulty => Beatmaps.Max(b => b.StarRating);

        public double MaxLength => Beatmaps.Max(b => b.Length);

        public double MaxBPM => Beatmaps.Max(b => b.BPM);

        /// <summary>
        /// Returns the storage path for the file in this beatmapset with the given filename, if any exists, otherwise null.
        /// The path returned is relative to the user file storage.
        /// </summary>
        /// <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 RealmBeatmap 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 (IsManaged && other.IsManaged)
                return ID == other.ID;

            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);
        }

        public override string ToString() => Metadata?.ToString() ?? base.ToString();

        IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;

        IEnumerable<INamedFileUsage> IBeatmapSetInfo.Files => Files;
    }
}
<commit_msg>Fix incorrect type check<commit_after>﻿// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using Realms;

#nullable enable

namespace osu.Game.Models
{
    [ExcludeFromDynamicCompile]
    [MapTo("BeatmapSet")]
    public class RealmBeatmapSet : RealmObject, IHasGuidPrimaryKey, IHasRealmFiles, ISoftDelete, IEquatable<RealmBeatmapSet>, IBeatmapSetInfo
    {
        [PrimaryKey]
        public Guid ID { get; set; } = Guid.NewGuid();

        [Indexed]
        public int OnlineID { get; set; } = -1;

        public DateTimeOffset DateAdded { get; set; }

        public IBeatmapMetadataInfo? Metadata => Beatmaps.FirstOrDefault()?.Metadata;

        public IList<RealmBeatmap> Beatmaps { get; } = null!;

        public IList<RealmNamedFileUsage> Files { get; } = null!;

        public bool DeletePending { get; set; }

        public string Hash { get; set; } = string.Empty;

        /// <summary>
        /// Whether deleting this beatmap set should be prohibited (due to it being a system requirement to be present).
        /// </summary>
        public bool Protected { get; set; }

        public double MaxStarDifficulty => Beatmaps.Max(b => b.StarRating);

        public double MaxLength => Beatmaps.Max(b => b.Length);

        public double MaxBPM => Beatmaps.Max(b => b.BPM);

        /// <summary>
        /// Returns the storage path for the file in this beatmapset with the given filename, if any exists, otherwise null.
        /// The path returned is relative to the user file storage.
        /// </summary>
        /// <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 (IsManaged && other.IsManaged)
                return ID == other.ID;

            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);
        }

        public override string ToString() => Metadata?.ToString() ?? base.ToString();

        IEnumerable<IBeatmapInfo> IBeatmapSetInfo.Beatmaps => Beatmaps;

        IEnumerable<INamedFileUsage> IBeatmapSetInfo.Files => Files;
    }
}

{'fraction_non_alphanumeric': 0.10459016393442623, 'fraction_numerical': 0.001639344262295082, 'mean_word_length': 2.4007803790412487, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4649899', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1672, 'n_words': 511}