/// <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); }
/// <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> /// 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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }