Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

A Concurrent Collection: a MultiMap Generic Collection Class in C# - Part 2

, 5 Jun 2009
MultiMap is similar to a .NET Dictionary collection type, but accepts duplicate Key,Value pairs during addition. The MultiMap collection is also a concurrent collection.
ConsoleTest.zip
ConsoleTest
bin
Release
ConsoleTest.exe
MultiMap.dll
Properties
MultiMap
bin
Release
MultiMap.dll
MultiMap.suo
Properties
MultiMapTest
bin
Release
MultiMap.dll
MultiMapTest.exe
Properties
Settings.settings
Demo.zip
Demo
MultiMap.dll
MultiMapTest.exe
MultiMap.zip
MultiMap.dll
MultiMapTest.zip
Debug
MultiMap.dll
MultiMap.pdb
MultiMapTest.exe
MultiMapTest.pdb
MultiMapTest.vshost.exe
MultiMap.dll
MultiMap.pdb
MultiMapTest.exe
MultiMapTest.pdb
MultiMapTest.vshost.exe
MultiMapTest.vshost.exe.manifest
obj
Debug
MultiMapTest.csproj.GenerateResource.Cache
MultiMapTest.exe
MultiMapTest.Form1.resources
MultiMapTest.pdb
MultiMapTest.Properties.Resources.resources
TempPE
Release
MultiMapTest.csproj.GenerateResource.Cache
MultiMapTest.exe
MultiMapTest.Form1.resources
MultiMapTest.pdb
MultiMapTest.Properties.Resources.resources
TempPE
Settings.settings
Debug
ConsoleTest.exe
ConsoleTest.pdb
ConsoleTest.vshost.exe
MultiMap.dll
MultiMap.pdb
ConsoleTest.exe
ConsoleTest.pdb
ConsoleTest.vshost.exe
ConsoleTest.vshost.exe.manifest
MultiMap.dll
MultiMap.pdb
obj
Debug
ConsoleTest.exe
ConsoleTest.pdb
TempPE
Release
ConsoleTest.exe
ConsoleTest.pdb
ResolveAssemblyReference.cache
TempPE
Debug
MultiMap.dll
MultiMap.pdb
MultiMap.dll
MultiMap.pdb
obj
Debug
MultiMap.dll
MultiMap.pdb
TempPE
Release
MultiMap.dll
MultiMap.pdb
TempPE
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BK.Util;

namespace MultiMapTest
{
    public partial class Form1 : Form
    {
        private MultimapBK<string, string> multiMap;

        MultimapBK<string, string>.MultimapEnum enumMultimap;

        public Form1()
        {
            InitializeComponent();
            multiMap = new MultimapBK<string, string>();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "Hello";
            richTextBox2.AppendText("Just Click Go button to begin");
            richTextBox1.AppendText("This is a limited dictionary to demonstrate C# Generic Multi Map Collection.  Just Search for: Hello, Happy or World");
            
            multiMap.Add("hello", "used to express a greeting, answer a telephone, or attract attention.");
            multiMap.Add("hello", "an exclamation of surprise, wonder, elation, etc");
            multiMap.Add("hello", "used derisively to question the comprehension, intelligence, or common sense of the person being addressed");

            multiMap.Add("happy", "delighted, pleased, or glad, as over a particular thing: to be happy to see a person. ");
            multiMap.Add("happy", "characterized by or indicative of pleasure, contentment, or joy: a happy mood; a happy frame of mind.");
            multiMap.Add("happy", "favored by fortune; fortunate or lucky: a happy, fruitful land. ");
            multiMap.Add("happy", "apt or felicitous, as actions, utterances, or ideas.");
            multiMap.Add("happy", "obsessed by or quick to use the item indicated (usually used in combination): a trigger-happy gangster. Everybody is gadget-happy these days. ");

            multiMap.Add("world", "the earth or globe, considered as a planet.");
            multiMap.Add("world", "a particular division of the earth.");
            multiMap.Add("world", "the earth or a part of it, with its inhabitants, affairs, etc., during a particular period: the ancient world.");
            multiMap.Add("world", "the public generally: The whole world knows it");
            multiMap.Add("world", "the class of persons devoted to the affairs, interests, or pursuits of this life: The world worships success. ");
            multiMap.Add("world", "everything that exists; the universe; the macrocosm.");
            multiMap.Add("world", "any indefinitely great expanse.");
            multiMap.Add("world", "any heavenly body;");

            enumMultimap = multiMap.GetEnumerator();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            richTextBox2.Clear();

            string ItemToDisplay = multiMap.GetFirstItem(textBox1.Text.ToLower());

            if (null != ItemToDisplay)
            {

                richTextBox2.AppendText(ItemToDisplay);
            }
            else
            {
                richTextBox2.AppendText("No Item matches this search");
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            richTextBox2.Clear();
            string retVal = multiMap.Iterate(textBox1.Text.ToLower());

            if (retVal != null)
            {
                richTextBox2.AppendText(retVal);
            }
            else
            {
                richTextBox2.AppendText("No more meaning found in Dictionary");
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            multiMap.Dispose();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            richTextBox2.Clear();
            textBox1.Clear();
            
            if (enumMultimap.MoveNext())
            {
                textBox1.Text = enumMultimap.Current.Key;

                while (enumMultimap.Current.Value.MoveNext())
                {
                    richTextBox2.AppendText(enumMultimap.Current.Value.Current);
                    richTextBox2.AppendText(":\n");
                }

                //string MeaningToPrint = enumMultimap.Current.Value.Next;
                //while (MeaningToPrint != null)
                //{
                //    richTextBox2.AppendText(MeaningToPrint);
                //    richTextBox2.AppendText(":\n");
                //    MeaningToPrint = enumMultimap.Current.Value.Next;
                //}
            }
            else
            {
                richTextBox2.AppendText("No More Entry in Dictionary. Resetting to start from begining");
                enumMultimap.Reset();
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Bharath K A
Software Developer (Senior)
United States United States
No Biography provided

| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 5 Jun 2009
Article Copyright 2009 by Bharath K A
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid