Example #1
0
        /// <summary>
        /// The function returns a list sorted by Group id, Users nickname and Timestemp
        /// </summary>
        /// <param name="msgs">List to sort</param>
        /// <returns></returns>
        public override List <GuiMessage> action(List <GuiMessage> msgs)
        {
            int i = 0, count;
            MessageComperator comperator = new MessageComperator();

            //  sort the list by group id
            msgs.Sort(comperator);

            // sort the list by name
            if (msgs.Count > 0)
            {
                count = 1;
                // find the range of the current group in the list, so we can sort that range by name
                string     tempGroup = msgs[i].G_id;
                SortByName sbn       = new SortByName();
                while (i + count < msgs.Count)
                {
                    if (tempGroup.Equals(msgs[i + count].G_id))
                    {
                        count++;
                    }
                    else
                    {
                        // send to SortByName to sort the wanted range
                        if (i + count < msgs.Count)
                        {
                            sbn.sortRange(i, count, msgs);
                        }
                        tempGroup = msgs[i + count].G_id;
                        i         = i + count;
                        count     = 1;
                    }
                }
                sbn.sortRange(i, count, msgs);
            }
            return(msgs);
        }
Example #2
0
 public SortByTime()
 {
     comperator = new MessageComperator();
 }