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)); } } }
public ValueSet(TKey key, IMultiMap <TKey, TVal> parent, TVal value) { Key = key; Parent = parent; hashSet = new HashSet <TVal>(parent.ComparerValue); hashSet.Add(value); }
public MultiMap(IMultiMap <K, V> map) { this.map = new Dictionary <K, ICollection <V> >(map.Count); this.collectionFactory = () => new List <V>(); this.autoClean = true; AddRange(map); }
public void TestAdd() { IMultiMap <int, int> map = HashMultiMap <int, int> .Create(); map.Add(2, 3); Assert.IsTrue(map.ContainsKeyValuePair(new System.Collections.Generic.KeyValuePair <int, int>(2, 3))); }
private void PopulateCollectionFromSecureCookie(string cookieName, IMultiMap <string, string> map) { var item = this.GetCookieByName(cookieName); var cookieValue = this.GetValueFromCookie(item); if (string.IsNullOrWhiteSpace(cookieValue)) { return; } var builder = new UriBuilder("http://domain.com" + cookieValue); string serializedCollection = builder.Query.TrimStart('?'); var path = builder.Path; string checkSum = path.StartsWith(this.Prefix(), StringComparison.Ordinal) ? path.Substring(this.Prefix().Length) : string.Empty; if (checkSum != this.GenerateCompositeHash(cookieName, serializedCollection)) { return; } UrlEncodingExtender.ParseValue(map, serializedCollection); }
public void TestContainsValue() { IMultiMap <int, int> map = HashMultiMap <int, int> .Create(); map.Add(4, 6); Assert.IsTrue(map.ContainsValue(6)); }
/// <summary> /// Initialize an instance of <see cref="MultiMap{TKey1, TKey2}"/>. /// </summary> /// <param name="map">Existed map.</param> /// <param name="comparer1">Comparer of key1.</param> /// <param name="comparer2">Comparer of key2.</param> /// <exception cref="ArgumentNullException">When <paramref name="map"/> is <see langword="null"/>.</exception> public MultiMap(IMultiMap <TKey1, TKey2> map, IEqualityComparer <TKey1> comparer1, IEqualityComparer <TKey2> comparer2) : this(map?.Count ?? 0, comparer1, comparer2) { foreach (var item in map ?? throw ExceptionHelper.ArgumentNull(nameof(map))) { Add(item.Key1, item.Key2); } }
public void TestContainsKey() { IMultiMap <int, int> map = HashMultiMap <int, int> .Create(); map.Add(3, 2); Assert.IsTrue(map.ContainsKey(3)); Assert.IsFalse(map.ContainsKey(45)); }
public void Add <K2, V2>(IMultiMap <K2, V2> arg) where K2 : K where V2 : V { foreach (var item1 in arg) { Add(item1.Key, item1.Value); } }
public void TestClear() { IMultiMap <int, int> map = HashMultiMap <int, int> .Create(); Assert.IsTrue(map.CountPairs == 0); map.Add(1, 2); map.Clear(); Assert.IsTrue(map.CountPairs == 0); }
/// <summary> /// Creates a read-only view of the specified multi-map. /// </summary> /// <param name="map">The multi-map.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="map"/> is null.</exception> public ReadOnlyMultiMap(IMultiMap <TKey, TValue> map) { if (map == null) { throw new ArgumentNullException(@"map"); } this.map = map; }
public void AddRange(IMultiMap <K, V> map) { foreach (K k in map.Keys) { foreach (V v in map[k]) { Add(k, v); } } }
/// <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); } } }
/// <summary> /// Constructor that gets the finder of methods marked with specific atrributes. /// </summary> /// <param name="finder"></param> public EventBus(IHandlerFindingStrategy finder) { //TODO : readerwriterlockslim , conccurentdictionary. //Replace with ninject tools. this.finder = finder; handlersByType = HashMultiMap<Type, EventHandler>.Create(); handlersByTypeLock = new ReaderWriterLockSlim(); eventsToDispatch = new ThreadLocal<Queue<EventWithHandler>>(() => { return new Queue<EventWithHandler>(); }); isDispatching = new ThreadLocal<Boolean>(() => { return false; }); }
/// <summary> /// Constructor that gets the finder of methods marked with specific atrributes. /// </summary> /// <param name="finder"></param> public EventBus(IHandlerFindingStrategy finder) { //TODO : readerwriterlockslim , conccurentdictionary. //Replace with ninject tools. this.finder = finder; handlersByType = HashMultiMap <Type, EventHandler> .Create(); handlersByTypeLock = new ReaderWriterLockSlim(); eventsToDispatch = new ThreadLocal <Queue <EventWithHandler> >(() => { return(new Queue <EventWithHandler>()); }); isDispatching = new ThreadLocal <Boolean>(() => { return(false); }); }
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); } }
public void TestGetSet() { IMultiMap <int, int> map = HashMultiMap <int, int> .Create(); map.Add(2, 3); map.Add(2, 4); map.Add(2, 5); System.Collections.Generic.ISet <int> set = map.GetSet(2); Assert.IsTrue(set.Contains(3)); Assert.IsTrue(set.Contains(4)); Assert.IsTrue(set.Contains(5)); }
public void Add <K2, V2>(IMultiMap <K2, V2> newMultiMap) where K2 : K where V2 : V { foreach (K2 newKey in newMultiMap.Keys) { foreach (V2 newValue in newMultiMap[newKey]) { Add(newKey, newValue); } } }
public void Add <K2, V2>(IMultiMap <K2, V2> pMultiMap) where K2 : K where V2 : V { foreach (K2 key in pMultiMap.Keys) { foreach (V2 value in pMultiMap[key]) { Add(key, value); // Calls Add for every Key Value pair in added Multimap } } }
/// <summary> /// This getting an object and extract all the methods marked with Subscribe attribute. /// </summary> /// <param name="subscriber">The object whose methods are desired to be event handlers</param> /// <returns>MultiMap between a key which is event type and a value which is the event handler contains a target object and methodInfo</returns> public IMultiMap <Type, EventHandler> FindAllHandlers(Object subscriber) { IMultiMap <Type, EventHandler> methodsInSubscriber = HashMultiMap <Type, EventHandler> .Create(); foreach (MethodInfo method in GetMarkedMethods(subscriber)) { ParameterInfo[] parmetersTypes = method.GetParameters(); Type eventType = parmetersTypes[0].ParameterType; EventHandler handler = new EventHandler(subscriber, method); methodsInSubscriber.Add(eventType, handler); } return(methodsInSubscriber); }
public void TestRemoveAll() { IMultiMap <int, int> map = HashMultiMap <int, int> .Create(); map.Add(2, 3); map.Add(2, 4); map.Add(2, 5); map.RemoveAll(2); Assert.IsFalse(map.ContainsKey(2)); Assert.IsFalse(map.ContainsValue(4)); Assert.IsFalse(map.ContainsValue(5)); Assert.IsFalse(map.ContainsValue(3)); }
public void TestCountPairs() { IMultiMap <int, int> map = HashMultiMap <int, int> .Create(); map.Add(2, 3); map.Add(2, 4); map.Add(2, 5); map.Add(7, 8); map.Add(7, 5); map.Add(1, 5); map.Add(29, 5); Assert.IsTrue(map.CountPairs == 7); }
public void TestCountPair() { IMultiMap <int, int> map = HashMultiMap <int, int> .Create(); map.Add(1, 3); map.Add(2, 3); map.Add(3, 4); map.Add(4, 5); map.Add(5, 6); Assert.IsTrue(map.CountPairs == 5); map.Clear(); Assert.IsTrue(map.CountPairs == 0); }
public void Merge(IMultiMap <TKey, TValue> toMergeWith) { if (toMergeWith == null) { return; } foreach (KeyValuePair <TKey, ISet <TValue> > pair in toMergeWith) { foreach (TValue value in pair.Value) { this.Add(pair.Key, value); } } }
/// <summary> /// This getting an object and extract all the methods marked with Subscribe attribute. /// </summary> /// <param name="subscriber">The object whose methods are desired to be event handlers</param> /// <returns>MultiMap between a key which is event type and a value which is the event handler contains a target object and methodInfo</returns> public IMultiMap <Type, EventHandler> FindAllHandlers(Object subscriber) { IMultiMap <Type, EventHandler> methodsInSubscriber = HashMultiMap <Type, EventHandler> .Create(); foreach (MethodInfo method in GetMarkedMethods(subscriber)) { Subscribe attr = (Subscribe)method.GetCustomAttribute(typeof(Subscribe)); int priority = attr.GetPriority(); ParameterInfo[] parmetersTypes = method.GetParameters(); Type eventType = parmetersTypes[0].ParameterType; EventHandler handler = new EventHandler(subscriber, method, priority); methodsInSubscriber.Add(eventType, handler); } return(methodsInSubscriber); }
/// <summary> /// Register the instance as subscriber through atrribute subscribe. /// </summary> /// <param name="object">Instance to registred as subscriber to events.</param> public void Register(Object @object) { IMultiMap <Type, EventHandler> methodsInSubscriber = finder.FindAllHandlers(@object); handlersByTypeLock.EnterWriteLock(); try { handlersByType.AddAll(methodsInSubscriber); } catch (Exception e) { //add logger message. } finally { handlersByTypeLock.ExitWriteLock(); } }
public static void ParseValue(IMultiMap <string, string> result, string value) { var clean = value.TrimStart('?'); var parts = clean.Split('&'); foreach (var part in parts) { var subParts = part.Split(new[] { '=' }, 2, StringSplitOptions.None); var key = Uri.UnescapeDataString(subParts[0]); if (string.IsNullOrWhiteSpace(key)) { continue; } result.Add(key, subParts.Length == 1 ? string.Empty : Uri.UnescapeDataString(subParts[1])); } }
/// <summary> /// Unregister the instance as subscriber. /// </summary> /// <Preconditions> /// @object is not null. /// The method Regiter is activated on the instance @object. /// </Preconditions> /// <param name="object">Instance to be unregistered</param> public void UnRegister(Object @object) { IMultiMap <Type, EventHandler> methodsInListener = finder.FindAllHandlers(@object); ISet <EventHandler> eventMethodsInListner = null; foreach (Type eventType in methodsInListener.Keys) { eventMethodsInListner = methodsInListener.GetSet(eventType); handlersByTypeLock.EnterWriteLock(); try { ISet <EventHandler> currentHandlers = handlersByType.GetSet(eventType); if (!eventMethodsInListner.IsSubsetOf(currentHandlers)) { throw new ArgumentException("missing event handlers for an annotated method. Is " + @object.ToString() + " registered?"); } currentHandlers.RemoveAll <EventHandler>(eventMethodsInListner); } finally { handlersByTypeLock.ExitWriteLock(); } } }
public static void ParseValue(IMultiMap <string, string> collection, string value) { ParseValueInternal( value, collection.Add); }
public IMultiMapDebugView(IMultiMap <K, V> multiMap) { this.multiMap = multiMap ?? throw ExceptionHelper.ArgumentNull(nameof(multiMap)); }
/// <summary> /// Obtains a read-only view of another multi-map. /// </summary> /// <param name="map">The multi-map.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="map"/> is null.</exception> public static IMultiMap <TKey, TValue> ReadOnly(IMultiMap <TKey, TValue> map) { return(new ReadOnlyMultiMap <TKey, TValue>(map)); }
public void Init() { mm = Client.GetMultiMap<object, object>(TestSupport.RandomString()); }