public virtual void TestPutGetRemove()
        {
            Assert.IsTrue(mm.Put("key1", "value1"));
            Assert.IsTrue(mm.Put("key1", "value2"));
            Assert.IsTrue(mm.Put("key1", "value3"));
            Assert.IsTrue(mm.Put("key2", "value4"));
            Assert.IsTrue(mm.Put("key2", "value5"));
            Assert.AreEqual(3, mm.ValueCount("key1"));
            Assert.AreEqual(2, mm.ValueCount("key2"));
            Assert.AreEqual(5, mm.Size());
            var coll = mm.Get("key1");

            Assert.AreEqual(3, coll.Count);
            coll = mm.Remove("key2");
            Assert.AreEqual(2, coll.Count);
            Assert.AreEqual(0, mm.ValueCount("key2"));
            Assert.AreEqual(0, mm.Get("key2").Count);
            Assert.IsFalse(mm.Remove("key1", "value4"));
            Assert.AreEqual(3, mm.Size());
            Assert.IsTrue(mm.Remove("key1", "value2"));
            Assert.AreEqual(2, mm.Size());
            Assert.IsTrue(mm.Remove("key1", "value1"));
            Assert.AreEqual(1, mm.Size());
            var enumerator = mm.Get("key1").GetEnumerator();

            enumerator.MoveNext();
            Assert.AreEqual("value3", enumerator.Current);
        }
예제 #2
0
        public void TestAddAll()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(2, 5);
            map.Add(2, 4);
            map.Add(2, 3);
            map.Add(1, 5);
            map.Add(1, 6);
            IMultiMap <int, int> map2 = HashMultiMap <int, int> .Create();

            map.Add(7, 5);
            map.Add(7, 4);
            map.Add(7, 3);
            map.Add(8, 5);
            map.Add(8, 6);
            map.AddAll(map2);
            foreach (int key in map2.Keys)
            {
                Assert.IsTrue(map.ContainsKey(key));
                foreach (int value in map2.Get(key))
                {
                    Assert.IsTrue(map.ContainsValue(value));
                }
            }
        }
예제 #3
0
 /// <summary>
 /// This method add all the the pairs of received map.
 /// </summary>
 /// <param name="map">map to be added to HashMultiMap.</param>
 public void AddAll(IMultiMap <K, V> map)
 {
     foreach (K key in map.Keys)
     {
         foreach (V value in map.Get(key))
         {
             Add(key, value);
         }
     }
 }
예제 #4
0
        public void TestGet()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(2, 3);
            map.Add(2, 4);
            map.Add(2, 5);
            foreach (int item in map.Get(2))
            {
                Assert.IsTrue(item == 3 || item == 4 || item == 5);
            }
        }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="event"></param>
 public void Post(Object @event)
 {
     handlersByTypeLock.EnterReadLock();
     try
     {
         var handlers = handlersByType.Get(@event.GetType());
         foreach (EventHandler eventHandler in handlers)
         {
             EnqueueEvent(@event, eventHandler);
         }
     }
     finally
     {
         handlersByTypeLock.ExitReadLock();
     }
     DispatchQueuedEvents();
 }