Пример #1
0
        /// <summary>
        /// Merges current list with the list of lists specified in the parameter.
        /// </summary>
        /// <param name="lists">Lists to merge with.</param>
        /// <returns>Merged list.</returns>
        public PFKeyValueList <K, V> Merge(PFList <PFKeyValueList <K, V> > lists)
        {
            PFKeyValueList <K, V> mergedList = new PFKeyValueList <K, V>();

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

            foreach (stKeyValuePair <K, V> item in this)
            {
                mergedList.Add(item);
            }

            for (int listInx = 0; listInx < lists.Count; listInx++)
            {
                PFKeyValueList <K, V> tempList = lists[listInx];
                if (tempList != null)
                {
                    foreach (stKeyValuePair <K, V> item in tempList)
                    {
                        mergedList.Add(item);
                    }
                }
            }

            return(mergedList);
        }
Пример #2
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);
        }
Пример #3
0
        /// <summary>
        /// Copies current list to a new list.
        /// </summary>
        /// <returns>Copy of list.</returns>
        public PFKeyValueList <K, V> Copy()
        {
            PFKeyValueList <K, V> newList = new PFKeyValueList <K, V>();

            foreach (stKeyValuePair <K, V> item in this)
            {
                newList.Add(item);
            }

            return(newList);
        }
Пример #4
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);
        }
Пример #5
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);
        }
Пример #6
0
        /// <summary>
        /// Converts currentg instance to another PFKeyValueList object.
        /// </summary>
        /// <returns>PFKeyValueList object.</returns>
        public PFKeyValueList <K, V> CopyThisToPFKeyValueList()
        {
            PFKeyValueList <K, V> kvlist = new PFKeyValueList <K, V>();
            stKeyValuePair <K, V> kvp    = default(stKeyValuePair <K, V>);

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

            return(kvlist);
        }
Пример #7
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 PFKeyValueList <K, V> Merge(PFKeyValueList <K, V> list)
        {
            PFKeyValueList <K, V> mergedList = new PFKeyValueList <K, V>();

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

            foreach (stKeyValuePair <K, V> item in this)
            {
                mergedList.Add(item);
            }

            foreach (stKeyValuePair <K, V> item in list)
            {
                mergedList.Add(item);
            }

            return(mergedList);
        }
Пример #8
0
        /// <summary>
        /// Creates and initializes an instance of the class by loading a serialized version of the instance stored as a xml formatted string.
        /// </summary>
        /// <param name="xmlString">String containing the xml formatted representation of an instance of this class.</param>
        /// <returns>An instance of PFKeyValueList.</returns>
        public static PFKeyValueListSorted <K, V> LoadFromXmlString(string xmlString)
        {
            PFKeyValueList <K, V> kvlist = default(PFKeyValueList <K, V>);

            try
            {
                kvlist = PFKeyValueList <K, V> .LoadFromXmlString(xmlString);
            }
            catch (System.Exception ex)
            {
                StringBuilder errMsg = new StringBuilder();
                errMsg.Length = 0;
                errMsg.Append("Error while loading xml string:");
                errMsg.Append(Environment.NewLine);
                errMsg.Append(ex.Message);
                errMsg.Append(Environment.NewLine);
                errMsg.Append("XML must contain definition for a PFKeyValueList object. That object will be converted into a PFKeyValueListSorted object.");
                throw new System.Exception(errMsg.ToString());
            }
            return(ConvertPFKeyValueListToSortedList(kvlist));
        }
Пример #9
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 PFKeyValueList <K, V> ConcatenateLists(PFList <PFKeyValueList <K, V> > lists)
        {
            PFKeyValueList <K, V> concatenatedList = new PFKeyValueList <K, V>();

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

            for (int listInx = 0; listInx < lists.Count; listInx++)
            {
                PFKeyValueList <K, V> tempList = lists[listInx];
                if (tempList != null)
                {
                    foreach (stKeyValuePair <K, V> item in tempList)
                    {
                        concatenatedList.Add(item);
                    }
                }
            }

            return(concatenatedList);
        }
Пример #10
0
        /// <summary>
        /// Converts instance of this class into an XML document.
        /// </summary>
        /// <returns>XmlDocument</returns>
        /// ///<remarks>XML Serialization and XmlDocument class are used for the transformation.</remarks>
        public XmlDocument ToXmlDocument()
        {
            PFKeyValueList <K, V> kvlist = ConvertThisToPFKeyValueList();

            return(kvlist.ToXmlDocument());
        }
Пример #11
0
        /// <summary>
        /// Returns a string containing the contents of the object in XML format.
        /// </summary>
        /// <returns>String value in xml format.</returns>
        /// ///<remarks>XML Serialization is used for the transformation.</remarks>
        public string ToXmlString()
        {
            PFKeyValueList <K, V> kvlist = ConvertThisToPFKeyValueList();

            return(kvlist.ToXmlString());
        }
Пример #12
0
        /// <summary>
        /// Creates and initializes an instance of the class by loading a serialized version of the instance from a file.
        /// </summary>
        /// <param name="filePath">Full path for the input file.</param>
        /// <returns>An instance of PFKeyValueList.</returns>
        public static PFKeyValueListSorted <K, V> LoadFromXmlFile(string filePath)
        {
            PFKeyValueList <K, V> kvlist = PFKeyValueList <K, V> .LoadFromXmlFile(filePath);

            return(ConvertPFKeyValueListToSortedList(kvlist));
        }
Пример #13
0
        /// <summary>
        /// Saves the public property values contained in the current instance to the specified file. Serialization is used for the save.
        /// </summary>
        /// <param name="filePath">Full path for output file.</param>
        public void SaveToXmlFile(string filePath)
        {
            PFKeyValueList <K, V> kvlist = ConvertThisToPFKeyValueList();

            kvlist.SaveToXmlFile(filePath);
        }