public static IMultiValueDictionary <K, V> Distinct <K, V>(this IMultiValueDictionary <K, V> first, IMultiValueDictionary <K, V> second)
        {
            // INSTRUCTIONS :
            // Return only the items that exist in "first" OR "second", but not both

            throw new NotImplementedException();
        }
        public static IMultiValueDictionary <K, V> Except <K, V>(this IMultiValueDictionary <K, V> first, IMultiValueDictionary <K, V> second)
        {
            // INSTRUCTIONS :
            // Return the items that exist in "first" but NOT in "second"

            throw new NotImplementedException();
        }
        public static IMultiValueDictionary <K, V> Union <K, V>(this IMultiValueDictionary <K, V> first, IMultiValueDictionary <K, V> second)
        {
            // INSTRUCTIONS :
            // * Return all items from "first" and "second" in a new Multivalue Dictionary

            throw new NotImplementedException();
        }
        public static IMultiValueDictionary <K, V> Intersection <K, V>(this IMultiValueDictionary <K, V> first, IMultiValueDictionary <K, V> second)
        {
            // INSTRUCTIONS :
            // * Return only the items that exist in BOTH "first" and "second" in a new Multivalue Dictionary

            throw new NotImplementedException();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Time Complexity - O(n) (foreach loops)
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        public static IMultiValueDictionary <K, V> Distinct <K, V>(this IMultiValueDictionary <K, V> first, IMultiValueDictionary <K, V> second)
        {
            // INSTRUCTIONS :
            // Return only the items that exist in "first" OR "second", but not both

            var mvd = new MultiValueDictionary <K, V>();

            foreach (var item in first.Items())
            {
                if (second.Items().Contains(item))
                {
                    mvd.Add(item.Key, item.Value);
                }
            }

            foreach (var item in second.Items())
            {
                if (first.Items().Contains(item))
                {
                    mvd.Add(item.Key, item.Value);
                }
            }

            return(mvd);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Time Complexity - O(n)
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        public static IMultiValueDictionary <K, V> Union <K, V>(this IMultiValueDictionary <K, V> first, IMultiValueDictionary <K, V> second)
        {
            // INSTRUCTIONS :
            // * Return all items from "first" and "second" in a new Multivalue Dictionary

            /// Time Complexity - O(n)

            if (first.Items().Any() && second.Items().Any())
            {
                return(new MultiValueDictionary <K, V>());
            }
            if (first.Items().Any() && second.Items().Any())
            {
                foreach (var value in second)
                {
                    first.Add(value.Key, value.Value);
                    return(first);
                }
            }
            else if (first.Items().Any() && !second.Items().Any())
            {
                return(first);
            }
            else
            {
                return(second);
            }

            return(new MultiValueDictionary <K, V>());
        }
 public InvokableServiceContextImpl(ICollectionFactory collectionFactory, PortableObjectBoxConverter portableObjectBoxConverter, object serviceImplementation, Type serviceInterface, Guid guid, IMultiValueDictionary <string, MethodDescriptor> methodDescriptorsByName)
 {
     this.collectionFactory          = collectionFactory;
     this.portableObjectBoxConverter = portableObjectBoxConverter;
     this.serviceImplementation      = serviceImplementation;
     this.serviceInterface           = serviceInterface;
     this.guid = guid;
     this.methodDescriptorsByName = methodDescriptorsByName;
 }
Ejemplo n.º 8
0
        protected override void PutMany(IMultiValueDictionary <int, string> collection, params string[] values)
        {
            var pairs = new List <KeyValuePair <int, IEnumerable <string> > >();

            foreach (var value in values)
            {
                pairs.Add(new KeyValuePair <int, IEnumerable <string> >(Interlocked.Increment(ref _lastKey), new [] { value }));
            }
            collection.PutMany(pairs);
        }
Ejemplo n.º 9
0
        public void Setup()
        {
            _multiValueDictionary = _database.GetMultiValueDictionary <int, Book>("BooksByInt");
            _multiValueDictionary.Clear();

            var books = new List <KeyValuePair <int, IEnumerable <Book> > >();

            for (int i = 0; i < N; ++i)
            {
                var book = new Book();
                books.Add(new KeyValuePair <int, IEnumerable <Book> >(i, new [] { book }));
            }
            _multiValueDictionary.PutMany(books);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Time Complexity - O(n)
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        public static IMultiValueDictionary <K, V> Except <K, V>(this IMultiValueDictionary <K, V> first, IMultiValueDictionary <K, V> second)
        {
            // INSTRUCTIONS :
            // Return the items that exist in "first" but NOT in "second"

            var mvd = new MultiValueDictionary <K, V>();

            foreach (var item in first.Items())
            {
                if (!second.Items().Contains(item))
                {
                    mvd.Add(item.Key, item.Value);
                }
            }
            return(mvd);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Time Complexity - O(n)
        /// </summary>
        /// <typeparam name="K"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="first"></param>
        /// <param name="second"></param>
        /// <returns></returns>
        public static IMultiValueDictionary <K, V> Intersection <K, V>(this IMultiValueDictionary <K, V> first, IMultiValueDictionary <K, V> second)
        {
            // INSTRUCTIONS :
            // * Return only the items that exist in BOTH "first" and "second" in a new Multivalue Dictionary

            var mvd = new MultiValueDictionary <K, V>();

            foreach (var item in first.Items())
            {
                if (second.Items().Contains(item))
                {
                    mvd.Add(item.Key, item.Value);
                }
            }
            return(mvd);
        }
Ejemplo n.º 12
0
 protected override void Put(IMultiValueDictionary <int, string> collection, string value)
 {
     collection.Put(Interlocked.Increment(ref _lastKey), value);
 }
Ejemplo n.º 13
0
 public DocumentDatabase(IDatabase database)
 {
     _database          = database;
     _documents         = database.GetOrCreateBag <DocumentEntity>("Documents");
     _documentIdsByName = database.GetOrCreateMultiValueDictionary <string, RowId>("DocumentIdsByName");
 }
Ejemplo n.º 14
0
 public RemoteServiceInvocationValidatorImpl(Type serviceInterface, Guid serviceGuid, IMultiValueDictionary <string, MethodInfo> methodsByName)
 {
     this.serviceInterface = serviceInterface;
     this.serviceGuid      = serviceGuid;
     this.methodsByName    = methodsByName;
 }
 /// <summary>
 /// Constructor for injecting multiValueDictionary object
 /// </summary>
 public Initializer(IMultiValueDictionary <string, string> multiValueDictionary)
 {
     _multiValueDictionary = multiValueDictionary;
 }
Ejemplo n.º 16
0
 public LookupFromDictionary(IMultiValueDictionary <TKey, TValue> multiValueDictionary)
 {
     _multiValueDictionary = multiValueDictionary;
 }
Ejemplo n.º 17
0
 public void Setup()
 {
     nvd = new MultiValueDictionaryImpl <string, string>();
 }
Ejemplo n.º 18
0
 protected override void RemoveLastPutValue(IMultiValueDictionary <int, string> collection)
 {
     collection.RemoveAll(_lastKey);
 }
        /// <summary>
        /// Calls the corresponding operation based on the input command. Formats/Acknowlegdes the output.
        /// </summary>
        public static void CallOperation(string operation, IMultiValueDictionary <string, string> mvd)
        {
            if (operation == null)
            {
                Print("Invalid Operation");
                return;
            }

            string[] ops     = operation.Split(SEPARATOR);
            string   command = null;
            string   key     = null;
            string   val     = null;

            if (ops.Length >= 1)
            {
                command = ops[0];
            }
            if (ops.Length >= 2)
            {
                key = ops[1];
            }
            if (ops.Length == 3)
            {
                val = ops[2];
            }

            try
            {
                int counter;
                switch (command.ToUpper())
                {
                case "ADD":
                    mvd.Add(key, val);
                    Print("Added");
                    break;

                case "REMOVE":
                    mvd.Remove(key, val);
                    Print("Removed");
                    break;

                case "VALUEEXISTS":
                    bool isValExist = mvd.CheckValueExists(key, val);
                    if (isValExist)
                    {
                        Print("true");
                    }
                    else
                    {
                        Print("false");
                    }
                    break;

                case "MEMBERS":
                    List <string> members = mvd.GetMembers(key);
                    counter = 0;
                    if (members.Count == 0)
                    {
                        Print("(empty set)");
                    }
                    else
                    {
                        foreach (string s in members)
                        {
                            Print(++counter + ") " + s);
                        }
                    }
                    break;

                case "REMOVEALL":
                    mvd.RemoveAll(key);
                    Print("Removed");
                    break;

                case "KEYEXISTS":
                    bool isKeyExist = mvd.CheckKeyExists(key);
                    if (isKeyExist)
                    {
                        Print("true");
                    }
                    else
                    {
                        Print("false");
                    }
                    break;

                case "KEYS":
                    List <string> keys = mvd.GetKeys();
                    counter = 0;
                    if (keys.Count == 0)
                    {
                        Print("(empty set)");
                    }
                    else
                    {
                        foreach (string s in keys)
                        {
                            Print(++counter + ") " + s);
                        }
                    }
                    break;

                case "CLEAR":
                    mvd.Clear();
                    Print("Cleared");
                    break;

                case "ALLMEMBERS":
                    List <string> allMembers = mvd.GetAllMembers();
                    counter = 0;
                    if (allMembers.Count == 0)
                    {
                        Print("(empty set)");
                    }
                    else
                    {
                        foreach (string s in allMembers)
                        {
                            Print(++counter + ") " + s);
                        }
                    }
                    break;

                case "ITEMS":
                    Dictionary <string, List <string> > items = mvd.GetItems();
                    counter = 0;
                    if (items.Count == 0)
                    {
                        Print("(empty set)");
                    }
                    else
                    {
                        foreach (KeyValuePair <string, List <string> > kvp in items)
                        {
                            List <string> list = kvp.Value;
                            foreach (string s in list)
                            {
                                Print(++counter + ") " + kvp.Key + ": " + s);
                            }
                        }
                    }
                    break;

                case "HELP":
                    ShowOperationList();
                    break;

                default:
                    Print("Invalid Input. Please refer to the command list above or type HELP");
                    break;
                }
            }
            catch (Exception e)
            {
                Print(e.Message);
            }
        }