<commit_before>﻿// Copyright (c) 2007-2018 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Collections.Generic;
using System.Linq;
using OpenTK.Input;

namespace osu.Framework.Input.Bindings
{
    /// <summary>
    /// Represent a combination of more than one <see cref="InputKey"/>s.
    /// </summary>
    public class KeyCombination : IEquatable<KeyCombination>
    {
        /// <summary>
        /// The keys.
        /// </summary>
        public readonly IEnumerable<InputKey> Keys;

        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="keys">The keys.</param>
        public KeyCombination(IEnumerable<InputKey> keys)
        {
            Keys = keys.OrderBy(k => (int)k).ToArray();
        }

        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="keys">A comma-separated (KeyCode) string representation of the keys.</param>
        public KeyCombination(string keys)
            : this(keys.Split(',').Select(s => (InputKey)int.Parse(s)))
        {
        }

        /// <summary>
        /// Check whether the provided input is a valid pressedKeys for this combination.
        /// </summary>
        /// <param name="pressedKeys">The potential pressedKeys for this combination.</param>
        /// <returns>Whether the pressedKeys keys are valid.</returns>
        public bool IsPressed(KeyCombination pressedKeys) => !Keys.Except(pressedKeys.Keys).Any();

        public bool Equals(KeyCombination other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Keys.SequenceEqual(other.Keys);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != GetType()) return false;
            return Equals((KeyCombination)obj);
        }

        public override int GetHashCode() => Keys != null ? Keys.Select(b => b.GetHashCode()).Aggregate((h1, h2) => h1 * 17 + h2) : 0;

        public static implicit operator KeyCombination(InputKey singleKey) => new KeyCombination(new[] { singleKey });

        public static implicit operator KeyCombination(string stringRepresentation) => new KeyCombination(stringRepresentation);

        public static implicit operator KeyCombination(InputKey[] keys) => new KeyCombination(keys);

        public override string ToString() => Keys?.Select(b => ((int)b).ToString()).Aggregate((s1, s2) => $"{s1},{s2}") ?? string.Empty;

        public string ReadableString() => Keys?.Select(getReadableKey).Aggregate((s1, s2) => $"{s1}+{s2}") ?? string.Empty;

        private string getReadableKey(InputKey key)
        {
            if (key >= InputKey.FirstJoystickHatRightButton)
                return $"Joystick Hat{key - InputKey.FirstJoystickHatRightButton} Right";
            if (key >= InputKey.FirstJoystickHatLeftButton)
                return $"Joystick Hat{key - InputKey.FirstJoystickHatLeftButton} Left";
            if (key >= InputKey.FirstJoystickHatDownButton)
                return $"Joystick Hat{key - InputKey.FirstJoystickHatDownButton} Down";
            if (key >= InputKey.FirstJoystickHatUpButton)
                return $"Joystick Hat{key - InputKey.FirstJoystickHatUpButton} Up";
            if (key >= InputKey.FirstJoystickAxisPositiveButton)
                return $"Joystick Axis{key - InputKey.FirstJoystickAxisPositiveButton} +";
            if (key >= InputKey.FirstJoystickAxisNegativeButton)
                return $"Joystick Axis{key - InputKey.FirstJoystickAxisNegativeButton} -";
            if (key >= InputKey.FirstJoystickButton)
                return $"Joystick{key - InputKey.FirstJoystickButton}";

            switch (key)
            {
                case InputKey.None:
                    return string.Empty;
                case InputKey.Shift:
                    return "Shift";
                case InputKey.Control:
                    return "Ctrl";
                case InputKey.Alt:
                    return "Alt";
                case InputKey.Super:
                    return "Win";
                case InputKey.Escape:
                    return "Esc";
                case InputKey.BackSpace:
                    return "Backsp";
                case InputKey.Insert:
                    return "Ins";
                case InputKey.Delete:
                    return "Del";
                case InputKey.PageUp:
                    return "Pgup";
                case InputKey.PageDown:
                    return "Pgdn";
                case InputKey.CapsLock:
                    return "Caps";
                case InputKey.Number0:
                case InputKey.Keypad0:<commit_msg>Space out the axis index in keycombination string<commit_after>﻿// Copyright (c) 2007-2018 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE

using System;
using System.Collections.Generic;
using System.Linq;
using OpenTK.Input;

namespace osu.Framework.Input.Bindings
{
    /// <summary>
    /// Represent a combination of more than one <see cref="InputKey"/>s.
    /// </summary>
    public class KeyCombination : IEquatable<KeyCombination>
    {
        /// <summary>
        /// The keys.
        /// </summary>
        public readonly IEnumerable<InputKey> Keys;

        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="keys">The keys.</param>
        public KeyCombination(IEnumerable<InputKey> keys)
        {
            Keys = keys.OrderBy(k => (int)k).ToArray();
        }

        /// <summary>
        /// Construct a new instance.
        /// </summary>
        /// <param name="keys">A comma-separated (KeyCode) string representation of the keys.</param>
        public KeyCombination(string keys)
            : this(keys.Split(',').Select(s => (InputKey)int.Parse(s)))
        {
        }

        /// <summary>
        /// Check whether the provided input is a valid pressedKeys for this combination.
        /// </summary>
        /// <param name="pressedKeys">The potential pressedKeys for this combination.</param>
        /// <returns>Whether the pressedKeys keys are valid.</returns>
        public bool IsPressed(KeyCombination pressedKeys) => !Keys.Except(pressedKeys.Keys).Any();

        public bool Equals(KeyCombination other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Keys.SequenceEqual(other.Keys);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != GetType()) return false;
            return Equals((KeyCombination)obj);
        }

        public override int GetHashCode() => Keys != null ? Keys.Select(b => b.GetHashCode()).Aggregate((h1, h2) => h1 * 17 + h2) : 0;

        public static implicit operator KeyCombination(InputKey singleKey) => new KeyCombination(new[] { singleKey });

        public static implicit operator KeyCombination(string stringRepresentation) => new KeyCombination(stringRepresentation);

        public static implicit operator KeyCombination(InputKey[] keys) => new KeyCombination(keys);

        public override string ToString() => Keys?.Select(b => ((int)b).ToString()).Aggregate((s1, s2) => $"{s1},{s2}") ?? string.Empty;

        public string ReadableString() => Keys?.Select(getReadableKey).Aggregate((s1, s2) => $"{s1}+{s2}") ?? string.Empty;

        private string getReadableKey(InputKey key)
        {
            if (key >= InputKey.FirstJoystickHatRightButton)
                return $"Joystick Hat {key - InputKey.FirstJoystickHatRightButton} Right";
            if (key >= InputKey.FirstJoystickHatLeftButton)
                return $"Joystick Hat {key - InputKey.FirstJoystickHatLeftButton} Left";
            if (key >= InputKey.FirstJoystickHatDownButton)
                return $"Joystick Hat {key - InputKey.FirstJoystickHatDownButton} Down";
            if (key >= InputKey.FirstJoystickHatUpButton)
                return $"Joystick Hat {key - InputKey.FirstJoystickHatUpButton} Up";
            if (key >= InputKey.FirstJoystickAxisPositiveButton)
                return $"Joystick Axis {key - InputKey.FirstJoystickAxisPositiveButton} +";
            if (key >= InputKey.FirstJoystickAxisNegativeButton)
                return $"Joystick Axis {key - InputKey.FirstJoystickAxisNegativeButton} -";
            if (key >= InputKey.FirstJoystickButton)
                return $"Joystick {key - InputKey.FirstJoystickButton}";

            switch (key)
            {
                case InputKey.None:
                    return string.Empty;
                case InputKey.Shift:
                    return "Shift";
                case InputKey.Control:
                    return "Ctrl";
                case InputKey.Alt:
                    return "Alt";
                case InputKey.Super:
                    return "Win";
                case InputKey.Escape:
                    return "Esc";
                case InputKey.BackSpace:
                    return "Backsp";
                case InputKey.Insert:
                    return "Ins";
                case InputKey.Delete:
                    return "Del";
                case InputKey.PageUp:
                    return "Pgup";
                case InputKey.PageDown:
                    return "Pgdn";
                case InputKey.CapsLock:
                    return "Caps";
                case InputKey.Number0:
                case InputKey.Keypad0:
{'fraction_non_alphanumeric': 0.11272690803329656, 'fraction_numerical': 0.005014542172299669, 'mean_word_length': 1.9546666666666668, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 93, 'https://': 2, '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': '5892026', 'n_tokens_mistral': 2748, 'n_tokens_neox': 2569, 'n_words': 645}