コード例 #1
0
        /// <summary>
        /// Produces a copy of this list in which the item order has been randomized.
        /// </summary>
        /// <returns>List containing items in random order.</returns>
        public PFKeyValueList <K, V> Randomize()
        {
            PFKeyValueList <K, V> randomizedList = new PFKeyValueList <K, V>();
            PFKeyValueListSorted <int, stKeyValuePair <K, V> > sortList = new PFKeyValueListSorted <int, stKeyValuePair <K, V> >();
            RandomNumber rnd = new RandomNumber();
            int          min = 0;
            int          max = 200000000;

            for (int i = 0; i < this.Count; i++)
            {
                stKeyValuePair <K, V> item = this[i];
                int key = rnd.GenerateRandomNumber(min, max);
                sortList.Add(key, item);
            }

            IEnumerator <KeyValuePair <int, stKeyValuePair <K, V> > > enumerator = sortList.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <int, stKeyValuePair <K, V> > keyValuePair = new stKeyValuePair <int, stKeyValuePair <K, V> >(enumerator.Current.Key, enumerator.Current.Value);
                randomizedList.Add(keyValuePair.Value);
            }



            return(randomizedList);
        }
        /// <summary>
        /// Compares two keys that are string values.
        /// </summary>
        /// <param name="x">First key/value pair to compare.</param>
        /// <param name="y">Second key/value pair to compare.</param>
        /// <returns>Less than zero: x precedes y in the sort order.  Zero: x occurs in the same position in the sort order as y. Greater than zero: x follows y in the sort order. </returns>
        public static int CompareKeyValueListStringString(stKeyValuePair <string, string> x, stKeyValuePair <string, string> y)
        {
            int ret = 0;

            if (x.Key != null && y.Key != null)
            {
                ret = x.Key.CompareTo(y.Key);
            }
            else
            {
                if (x.Key != null)
                {
                    ret = 1;
                }
                else if (y.Key != null)
                {
                    ret = -1;
                }
                else
                {
                    ret = 0;
                }
            }

            return(ret);
        }
コード例 #3
0
        /// <summary>
        /// Merges current list with the list specified in the parameter.
        /// </summary>
        /// <param name="list">List to merge with.</param>
        /// <returns>Merged list.</returns>
        public PFKeyValueListSorted <K, V> Merge(PFKeyValueListSorted <K, V> list)
        {
            PFKeyValueListSorted <K, V> mergedList = new PFKeyValueListSorted <K, V>();

            if (list == null)
            {
                return(mergedList);
            }

            IEnumerator <KeyValuePair <K, V> > enumerator = this.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumerator.Current.Key, enumerator.Current.Value);
                mergedList.Add(keyValuePair.Key, keyValuePair.Value);
            }


            IEnumerator <KeyValuePair <K, V> > enumList = list.GetEnumerator();

            while (enumList.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumList.Current.Key, enumList.Current.Value);
                mergedList.Add(keyValuePair.Key, keyValuePair.Value);
            }

            return(mergedList);
        }
コード例 #4
0
        /// <summary>
        /// Routine that concatenates two or more lists into one list.
        /// </summary>
        /// <param name="lists">List of list objects to be concatenated.</param>
        /// <returns>Concatenated list.</returns>
        public static PFKeyValueListSorted <K, V> ConcatenateLists(PFList <PFKeyValueListSorted <K, V> > lists)
        {
            PFKeyValueListSorted <K, V> concatenatedList = new PFKeyValueListSorted <K, V>();

            if (lists == null)
            {
                return(concatenatedList);
            }

            for (int listInx = 0; listInx < lists.Count; listInx++)
            {
                PFKeyValueListSorted <K, V> tempList = lists[listInx];
                if (tempList != null)
                {
                    IEnumerator <KeyValuePair <K, V> > enumerator = tempList.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        // Get current key value pair
                        stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumerator.Current.Key, enumerator.Current.Value);
                        concatenatedList.Add(keyValuePair.Key, keyValuePair.Value);
                    }
                }
            }

            return(concatenatedList);
        }
コード例 #5
0
        /// <summary>
        /// Searches for and returns key/value pair that has matching key.
        /// </summary>
        /// <param name="keyToFind">Key to search for.</param>
        /// <returns>Object containing key and value. Returns empty key/val object if not found.</returns>
        public stKeyValuePair <K, V> Find(string keyToFind)
        {
            stKeyValuePair <K, V> retval = default(stKeyValuePair <K, V>);

            foreach (stKeyValuePair <K, V> kvp in this)
            {
                if (kvp.Key.ToString() == keyToFind)
                {
                    retval = kvp;
                }
            }
            return(retval);
        }
コード例 #6
0
        /// <summary>
        /// Converts PFKeyValueList object to PFKeyValueListSorted object.
        /// </summary>
        /// <param name="kvlist"></param>
        /// <returns>PFKeyValueListSorted object.</returns>
        public static PFKeyValueListSorted <K, V> ConvertPFKeyValueListToSortedList(PFKeyValueList <K, V> kvlist)
        {
            PFKeyValueListSorted <K, V> kvlistSorted = new PFKeyValueListSorted <K, V>();

            kvlist.SetToBOF();
            stKeyValuePair <K, V> stKeyValuePair = kvlist.FirstItem;

            while (!kvlist.EOF)
            {
                kvlistSorted.Add(stKeyValuePair.Key, stKeyValuePair.Value);
                stKeyValuePair = kvlist.NextItem;
            }
            return(kvlistSorted);
        }
コード例 #7
0
        /// <summary>
        /// Copies current list to a new list.
        /// </summary>
        /// <returns>Copy of list.</returns>
        public PFKeyValueListSorted <K, V> Copy()
        {
            PFKeyValueListSorted <K, V> newList = new PFKeyValueListSorted <K, V>();

            IEnumerator <KeyValuePair <K, V> > enumerator = this.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumerator.Current.Key, enumerator.Current.Value);
                newList.Add(keyValuePair.Key, keyValuePair.Value);
            }

            return(newList);
        }
コード例 #8
0
        /// <summary>
        /// Converts PFKeyValueListSorted object to PFKeyValueList object.
        /// </summary>
        /// <returns>PFKeyValueList object.</returns>
        public PFKeyValueList <K, V> ConvertThisToPFKeyValueList()
        {
            PFKeyValueList <K, V> kvlist = new PFKeyValueList <K, V>();

            IEnumerator <KeyValuePair <K, V> > enumerator = GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumerator.Current.Key, enumerator.Current.Value);
                kvlist.Add(keyValuePair);
            }

            return(kvlist);
        }
コード例 #9
0
        /// <summary>
        /// Converts current instance of a PFKeyValueList object to PFList object.
        /// </summary>
        /// <returns>PFList object.</returns>
        public PFList <stKeyValuePair <K, V> > ConvertThisToPFList()
        {
            PFList <stKeyValuePair <K, V> > list = new PFList <stKeyValuePair <K, V> >();
            stKeyValuePair <K, V>           kvp  = default(stKeyValuePair <K, V>);

            if (this.Count > 0)
            {
                this.SetToBOF();
                kvp = this.FirstItem;
                while (this.EOF == false)
                {
                    list.Add(new stKeyValuePair <K, V>(kvp.Key, kvp.Value));
                    kvp = this.NextItem;
                }
            }

            return(list);
        }
コード例 #10
0
        //properties

        //methods

        /// <summary>
        /// Compares two keys that are int values.
        /// </summary>
        /// <param name="x">First key/value pair to compare.</param>
        /// <param name="y">Second key/value pair to compare.</param>
        /// <returns>Less than zero: x precedes y in the sort order.  Zero: x occurs in the same position in the sort order as y. Greater than zero: x follows y in the sort order. </returns>
        public static int CompareKeyValueListIntString(stKeyValuePair <int, string> x, stKeyValuePair <int, string> y)
        {
            int ret = 0;

            if (x.Key < y.Key)
            {
                ret = -1;
            }
            else if (x.Key > y.Key)
            {
                ret = 1;
            }
            else
            {
                ret = 0;
            }

            return(ret);
        }
コード例 #11
0
        /// <summary>
        /// Merges current list with the array of lists specified in the parameter.
        /// </summary>
        /// <param name="lists">Lists to merge with.</param>
        /// <returns>Merged list.</returns>
        public PFKeyValueListSorted <K, V> Merge(PFKeyValueListSorted <K, V>[] lists)
        {
            PFKeyValueListSorted <K, V> mergedList = new PFKeyValueListSorted <K, V>();

            if (lists == null)
            {
                return(mergedList);
            }

            IEnumerator <KeyValuePair <K, V> > enumerator = this.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Get current key value pair
                stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumerator.Current.Key, enumerator.Current.Value);
                mergedList.Add(keyValuePair.Key, keyValuePair.Value);
            }


            for (int listInx = 0; listInx < lists.Length; listInx++)
            {
                PFKeyValueListSorted <K, V> tempList = lists[listInx];
                if (tempList != null)
                {
                    IEnumerator <KeyValuePair <K, V> > enumTempList = tempList.GetEnumerator();
                    while (enumTempList.MoveNext())
                    {
                        // Get current key value pair
                        stKeyValuePair <K, V> keyValuePair = new stKeyValuePair <K, V>(enumTempList.Current.Key, enumTempList.Current.Value);
                        mergedList.Add(keyValuePair.Key, keyValuePair.Value);
                    }
                }
            }

            return(mergedList);
        }
コード例 #12
0
        /// <summary>
        /// Removes the item identified by the specified key from the list.
        /// </summary>
        /// <param name="keyToRemove">Key to search for and remove.</param>
        public void Remove(string keyToRemove)
        {
            stKeyValuePair <K, V> keyval = this.Find(keyToRemove);

            this.Remove(keyval);
        }