<commit_before>﻿using Evolve.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Evolve.Migration
{
    public sealed class MigrationVersion : IComparable<MigrationVersion>, IComparable
    {
        private const string InvalidObjectType = "Object must be of type MigrationVersion.";

        public MigrationVersion(string version)
        {
            Check.NotNullOrEmpty(version, nameof(version));
            
            Version = version.Replace('_', '.');
            if (!MatchPattern.IsMatch(Version)) throw new EvolveConfigurationException();

            VersionParts = Version.Split('.').Select(long.Parse).ToList();
        }

        public static Regex MatchPattern => new Regex("^[0-9]+(?:.[0-9]+)*$");

        public string Version { get; private set; }

        public List<long> VersionParts { get; set; }

        public int CompareTo(MigrationVersion other)
        {
            if (other == null) return 1;

            using (IEnumerator<long> e1 = VersionParts.GetEnumerator())
            using (IEnumerator<long> e2 = other.VersionParts.GetEnumerator())
            {
                while (e1.MoveNext())
                {
                    if (!e2.MoveNext())
                        return 1;

                    if (e1.Current.CompareTo(e2.Current) == 0)
                        continue;

                    return e1.Current.CompareTo(e2.Current);
                }
                return e2.MoveNext() ? -1 : 0;
            }
        }

        public int CompareTo(object obj)
        {
            if (obj != null && !(obj is MigrationVersion))
                throw new ArgumentException(InvalidObjectType);

            return CompareTo(obj as MigrationVersion);
        }

        public override bool Equals(object obj) => (CompareTo(obj as MigrationVersion) == 0);

        public static bool operator >(MigrationVersion operand1, MigrationVersion operand2) => operand1.CompareTo(operand2) == 1;

        public static bool operator <(MigrationVersion operand1, MigrationVersion operand2) => operand1.CompareTo(operand2) == -1;

        public static bool operator >=(MigrationVersion operand1, MigrationVersion operand2) => operand1.CompareTo(operand2) >= 0;

        public static bool operator <=(MigrationVersion operand1, MigrationVersion operand2) => operand1.CompareTo(operand2) <= 0;

        public override int GetHashCode() => Version.GetHashCode();

        public override string ToString()
        {
            return Version;
        }
    }
}<commit_msg>Refactoring<commit_after>﻿using Evolve.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Evolve.Migration
{
    public sealed class MigrationVersion : IComparable<MigrationVersion>, IComparable
    {
        private const string InvalidObjectType = "Object must be of type MigrationVersion.";

        public MigrationVersion(string version)
        {
            Check.NotNullOrEmpty(version, nameof(version));
            
            Version = version.Replace('_', '.');
            if (!MatchPattern.IsMatch(Version)) throw new EvolveConfigurationException();

            VersionParts = Version.Split('.').Select(long.Parse).ToList();
        }

        public static Regex MatchPattern => new Regex("^[0-9]+(?:.[0-9]+)*$");

        public string Version { get; private set; }

        public List<long> VersionParts { get; set; }

        public int CompareTo(MigrationVersion other)
        {
            if (other == null) return 1;

            using (IEnumerator<long> e1 = VersionParts.GetEnumerator())
            using (IEnumerator<long> e2 = other.VersionParts.GetEnumerator())
            {
                while (e1.MoveNext())
                {
                    if (!e2.MoveNext())
                        return 1;

                    if (e1.Current.CompareTo(e2.Current) == 0)
                        continue;

                    return e1.Current.CompareTo(e2.Current);
                }
                return e2.MoveNext() ? -1 : 0;
            }
        }

        public int CompareTo(object obj)
        {
            if (obj != null && !(obj is MigrationVersion))
                throw new ArgumentException(InvalidObjectType);

            return CompareTo(obj as MigrationVersion);
        }

        public override bool Equals(object obj) => (CompareTo(obj as MigrationVersion) == 0);

        public static bool operator >(MigrationVersion operand1, MigrationVersion operand2) => operand1.CompareTo(operand2) == 1;

        public static bool operator <(MigrationVersion operand1, MigrationVersion operand2) => operand1.CompareTo(operand2) == -1;

        public static bool operator >=(MigrationVersion operand1, MigrationVersion operand2) => operand1.CompareTo(operand2) >= 0;

        public static bool operator <=(MigrationVersion operand1, MigrationVersion operand2) => operand1.CompareTo(operand2) <= 0;

        public override int GetHashCode() => Version.GetHashCode();

        public override string ToString() => Version;
    }
}
{'fraction_non_alphanumeric': 0.10364906832298136, 'fraction_numerical': 0.015139751552795032, 'mean_word_length': 2.2634578847371754, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 32, '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': '118956', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1319, 'n_words': 337}