示例#1
0
 private static void ExecuteElementsCommand(TwoKeysDictionary <int, int, int> twoKeysDictionary)
 {
     foreach (Tuple <int, int, int> twoKeyValuePair in twoKeysDictionary)
     {
         AppendLine($"First Key: {twoKeyValuePair.Item1}, Second Key: {twoKeyValuePair.Item2}, Value: {twoKeyValuePair.Item3}");
     }
 }
示例#2
0
        private static void ExecuteContainsCommand(string[] tokens, TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int  key1     = int.Parse(tokens[1]);
            int  key2     = int.Parse(tokens[2]);
            bool contains = twoKeysDictionary.Contains(key1, key2);

            AppendLine(contains.ToString());
        }
示例#3
0
        private static void ExecuteRemoveCommand(string[] tokens, TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int  key1      = int.Parse(tokens[1]);
            int  key2      = int.Parse(tokens[2]);
            bool isRemoved = twoKeysDictionary.Remove(key1, key2);

            AppendLine(isRemoved.ToString());
        }
示例#4
0
        public static void Main(string[] args)
        {
            TwoKeysDictionary <int, int, int> twoKeysDictionary = new TwoKeysDictionary <int, int, int>();

            ExecuteCommands(twoKeysDictionary);

            Console.WriteLine(outputBuilder.ToString().TrimEnd());
        }
示例#5
0
        private static void ExecuteAddCommand(string[] tokens, TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int key1  = int.Parse(tokens[1]);
            int key2  = int.Parse(tokens[2]);
            int value = int.Parse(tokens[3]);

            bool isCommandSuccessful = twoKeysDictionary.Add(key1, key2, value);

            AppendLine(isCommandSuccessful.ToString());
        }
示例#6
0
        private static void ExecuteCommands(TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int commandsCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < commandsCount; i++)
            {
                string commandLine = Console.ReadLine();
                ExecuteCommands(commandLine, twoKeysDictionary);
            }
        }
示例#7
0
        private static void ExecuteValueCommand(string[] tokens, TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int key1 = int.Parse(tokens[1]);
            int key2 = int.Parse(tokens[2]);

            try
            {
                int value = twoKeysDictionary[key1, key2];
                AppendLine(value.ToString());
            }
            catch (KeyNotFoundException knfe)
            {
                AppendLine(knfe.Message);
            }
        }
示例#8
0
        private static void ExecuteCommands(string commandLine, TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            string[] tokens  = commandLine.Split();
            string   command = tokens[0];

            switch (command)
            {
            case "count":
                ExecuteCountCommand(twoKeysDictionary);
                break;

            case "contains":
                ExecuteContainsCommand(tokens, twoKeysDictionary);
                break;

            case "add":
                ExecuteAddCommand(tokens, twoKeysDictionary);
                break;

            case "remove":
                ExecuteRemoveCommand(tokens, twoKeysDictionary);
                break;

            case "clear":
                ExecuteClearCommand(twoKeysDictionary);
                break;

            case "value":
                ExecuteValueCommand(tokens, twoKeysDictionary);
                break;

            case "values":
                ExecuteValuesCommand(twoKeysDictionary);
                break;

            case "elements":
                ExecuteElementsCommand(twoKeysDictionary);
                break;

            default:
                break;
            }
        }
示例#9
0
        private static void ExecuteCountCommand(TwoKeysDictionary <int, int, int> twoKeysDictionary)
        {
            int count = twoKeysDictionary.Count;

            AppendLine(count.ToString());
        }
示例#10
0
 private static void ExecuteValuesCommand(TwoKeysDictionary <int, int, int> twoKeysDictionary)
 {
     AppendLine(string.Join(", ", twoKeysDictionary.Values));
 }
示例#11
0
 private static void ExecuteClearCommand(TwoKeysDictionary <int, int, int> twoKeysDictionary)
 {
     twoKeysDictionary.Clear();
 }