/// <summary>
        /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <KingOfConcertGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci,
                                                                  GetKeyDelegate getKey, bool sort)
        {
            SortedLocaleGrouping           slg  = new SortedLocaleGrouping(ci);
            List <KingOfConcertGroup <T> > list = CreateGroups(slg);

            foreach (T item in items)
            {
                int index = 0;
                if (slg.SupportsPhonetics)
                {
                    //check if your database has yomi string for item
                    //if it does not, then do you want to generate Yomi or ask the user for this item.
                    //index = slg.GetGroupIndex(getKey(Yomiof(item)));
                }
                else
                {
                    index = slg.GetGroupIndex(getKey(item));
                }
                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (KingOfConcertGroup <T> group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); });
                }
            }

            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Create a list of AlphaGroup{T} with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <param name="itemClickCommand">The command to execute on a click</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaGroupListGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci,
                                                                   GetKeyDelegate getKey, bool sort = true, MvxAsyncCommand <T> itemClickCommand = null)
        {
            var list = new List <AlphaGroupListGroup <T> >();

            foreach (var item in items)
            {
                var index = getKey(item);

                if (list.All(a => a.Key != index))
                {
                    list.Add(new AlphaGroupListGroup <T>(index, itemClickCommand));
                }

                if (!string.IsNullOrEmpty(index))
                {
                    list.Find(a => a.Key == index).Add(item);
                }
            }

            if (sort)
            {
                foreach (var group in list)
                {
                    group.Sort((c0, c1) => ci.CompareInfo.Compare(getKey(c0), getKey(c1)));
                }
            }

            return(list);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a list of AlphaGroup{T} with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="getSortKey">A delegate to get the key for sorting from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <param name="itemClickCommand">The command to execute on a click.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <DateListGroupCollection <T> > CreateGroups(IEnumerable <T> items,
                                                                       GetKeyDelegate getKey,
                                                                       GetSortKeyDelegate getSortKey,
                                                                       bool sort = true,
                                                                       RelayCommand <T>?itemClickCommand = null)
        {
            ThrowIfNull(items);

            var list = new List <DateListGroupCollection <T> >();

            foreach (T item in items)
            {
                string index = getKey(item);

                if (list.All(a => a.Key != index))
                {
                    list.Add(new DateListGroupCollection <T>(index, itemClickCommand));
                }

                if (!string.IsNullOrEmpty(index))
                {
                    list.Find(a => a.Key == index).Add(item);
                }
            }

            if (sort)
            {
                foreach (DateListGroupCollection <T> group in list)
                {
                    group.Sort((c0, c1) => getSortKey(c1).Date.Day.CompareTo(getSortKey(c0).Date.Day));
                }
            }

            return(list);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor with initial items.
        /// </summary>
        /// <param name="vtok">Delegate used by the set to get keys for
        /// items. Cannot be <c>null</c>.</param>
        /// <param name="items">Items to add to the set initially.</param>
        public SortedKeyedSet(GetKeyDelegate vtok, IEnumerable <T> items)
        {
            Debug.Assert(vtok != null);
            Debug.Assert(items != null);

            this.vtok = vtok;
            foreach (T item in items)
            {
                Add(item);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, GetKeyDelegate getKey)
        {
            Grouping slg = new Grouping();
            List <AlphaKeyGroup <T> > list = CreateGroups(slg);

            foreach (T item in items)
            {
                int index = 0;
                index = slg.GetGroupIndex(getKey(item));
                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }
            return(list);
        }
Ejemplo n.º 6
0
        public static IEnumerable <TValue> MergeLists <TKey, TValue>(GetKeyDelegate <TKey, TValue> getKey, params IEnumerable <TValue>[] listsToMerge)
        {
            if (listsToMerge.Length <= 0)
            {
                return(null);
            }
            if (listsToMerge.Length == 1)
            {
                return(listsToMerge[0]);
            }
            Dictionary <TKey, TValue> dictionary = new Dictionary <TKey, TValue>();

            foreach (IEnumerable <TValue> enumerable in listsToMerge)
            {
                foreach (TValue item in enumerable)
                {
                    TKey key = getKey(item);
                    dictionary[key] = item;
                }
            }
            return(dictionary.Values);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Default constructor. Creates an empty set.
        /// </summary>
        /// <param name="vtok">Delegate used by the set to get keys for
        /// items. Cannot be <c>null</c>.</param>
        public SortedKeyedSet(GetKeyDelegate vtok)
        {
            Debug.Assert(vtok != null);

            this.vtok = vtok;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            List <AlphaKeyGroup <T> > list = CreateGroups(SortedLocalGrouping);

            foreach (T item in items)
            {
                int index = 0;

                {
                    string label = getKey(item);
                    index = SortedLocalGrouping.IndexOf(label[0].ToString().ToLower());
                }
                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (AlphaKeyGroup <T> group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); });
                }
            }

            return(list);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            SortedLocaleGrouping      slg  = new SortedLocaleGrouping(ci);
            List <AlphaKeyGroup <T> > list = new List <AlphaKeyGroup <T> >();

            foreach (string key in slg.GroupDisplayNames)
            {
                if (key == "...")
                {
                    list.Add(new AlphaKeyGroup <T>(GlobeGroupKey));
                }
                else
                {
                    list.Add(new AlphaKeyGroup <T>(key));
                }
            }

            foreach (T item in items)
            {
                int index = slg.GetGroupIndex(getKey(item));
                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (AlphaKeyGroup <T> group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); });
                }
            }

            return(list);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            CharacterGroupings        slg  = new CharacterGroupings();
            List <AlphaKeyGroup <T> > list = CreateGroups(slg);

            foreach (T item in items)
            {
                try
                {
                    string index = "";
                    index = slg.Lookup(getKey(item));
                    if (string.IsNullOrEmpty(index) == false)
                    {
                        list.Find(a => a.Key == index).Add(item);
                    }
                }
                catch
                {
                }
            }

            if (sort)
            {
                foreach (AlphaKeyGroup <T> group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); });
                }
            }

            return(list);
        }
        /// <summary>
        /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            //SortedLocaleGrouping slg = new SortedLocaleGrouping(ci);
            List <AlphaKeyGroup <T> > list = new List <AlphaKeyGroup <T> >();

            //foreach (var cg in cgs)
            //{
            //	if (string.IsNullOrEmpty(cg.Label))
            //	{
            //		list.Add(new AlphaKeyGroup<T>(GlobeGroupKey));
            //	}
            //	else
            //	{
            //		list.Add(new AlphaKeyGroup<T>(cg.Label));
            //	}
            //}

            //var cgs = new Windows.Globalization.Collation.CharacterGroupings();
            //var group = from item in items group item by cgs.Lookup(getKey(item)) into g;

            foreach (T item in items)
            {
                var key   = getKey(item);
                var label = "";
                //cgs.Lookup(key);
                if (string.IsNullOrEmpty(label))
                {
                    label = GlobeGroupKey;
                }
            }

            if (sort)
            {
                foreach (AlphaKeyGroup <T> group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); });
                }
            }

            return(list);
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     Create a list of AlphaGroup with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static OptimizedObservableCollection<AlphaKeyGroup> CreateGroups(IEnumerable<object> items, CultureInfo ci,
            GetKeyDelegate getKey,
            bool sort = true)
        {
            var slg = new CharacterGroupings();
            var list = CreateGroups(slg);

            foreach (var item in items)
            {
                var lookUp = getKey(item);

                if (string.IsNullOrEmpty(lookUp))
                    continue;

                var index = slg.Lookup(lookUp);
                if (string.IsNullOrEmpty(index) == false)
                {
                    list.Find(a => a.Key.EqualsIgnoreCase(index)).Items.Add(item);
                }
            }

            var max = list.Select(p => p.Count).Max();

            if (sort)
            {
                foreach (var group in list)
                {
                    group.OrderKey = getKey;
                    var percent = group.Count > 1 ? Math.Log(group.Count, max) : Math.Log(2, max) / 2;
                    percent = Math.Max(.1, percent);
                    if (double.IsNaN(percent))
                        percent = 0.1;
                    if (group.Count == 0)
                        percent = 0;

                    group.GridLeftLength = new GridLength(percent, GridUnitType.Star);
                    group.GridRightLength = new GridLength(1 - percent, GridUnitType.Star);

                    var asList = group.ToList();
                    asList.Sort((x, y) => string.Compare(getKey(x), getKey(y), StringComparison.Ordinal));
                    group.SwitchTo(asList);

                    group.CollectionChanged += (sender, args) =>
                    {
                        max = list.Select(p => p.Count).Max();
                        foreach (var other in list)
                        {
                            percent = other.Count > 1 ? Math.Log(other.Count, max) : Math.Log(2, max) / 2;
                            percent = Math.Max(.1, percent);
                            if (double.IsNaN(percent))
                                percent = 0.1;
                            if (other.Count == 0)
                                percent = 0;

                            other.GridLeftLength = new GridLength(percent, GridUnitType.Star);
                            other.GridRightLength = new GridLength(1 - percent, GridUnitType.Star);
                        }
                    };
                }
            }

            return new OptimizedObservableCollection<AlphaKeyGroup>(list);
        }
        /// <summary>
        /// Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static ObservableCollection <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            var slg  = new SortedLocaleGrouping(ci);
            var list = CreateGroups(slg);

            foreach (var item in items)
            {
                var index = 0;
                if (slg.SupportsPhonetics)
                {
                    //check if your database has yomi string for item
                    //if it does not, then do you want to generate Yomi or ask the user for this item.
                    //index = slg.GetGroupIndex(getKey(Yomiof(item)));
                }
                else
                {
                    index = slg.GetGroupIndex(getKey(item));
                }
                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }
            if (sort)
            {
                foreach (var group in list)
                {
                    group.ToList().Sort((c0, c1) => ci.CompareInfo.Compare(getKey(c0), getKey(c1)));
                }
            }
            return(list);
        }
Ejemplo n.º 14
0
        /// <summary>
        ///     Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="getSortKey">A delegate to get the key for sorting from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <DateListGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey,
                                                             GetSortKeyDelegate getSortKey, bool sort)
        {
            var list = new List <DateListGroup <T> >();

            foreach (var item in items)
            {
                var index = getKey(item);

                if (list.All(a => a.Key != index))
                {
                    list.Add(new DateListGroup <T>(index));
                }

                if (!string.IsNullOrEmpty(index))
                {
                    list.Find(a => a.Key == index).Add(item);
                }
            }

            if (sort)
            {
                foreach (var group in list)
                {
                    group.Sort((c0, c1) => getSortKey(c1).Date.Day.CompareTo(getSortKey(c0).Date.Day));
                }
            }

            return(list);
        }
        public static List <StringKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            var list = new List <StringKeyGroup <T> >();

            foreach (var item in items)
            {
                var itemKey = getKey(item);//.Substring(0, 1).ToLower();

                var itemGroup      = list.FirstOrDefault(li => li.Key == itemKey);
                var itemGroupIndex = itemGroup != null?list.IndexOf(itemGroup) : -1;

                if (itemGroupIndex == -1)
                {
                    list.Add(new StringKeyGroup <T>(itemKey));
                    itemGroupIndex = list.Count - 1;
                }
                if (itemGroupIndex >= 0 && itemGroupIndex < list.Count)
                {
                    list[itemGroupIndex].Add(item);
                }
            }

            if (sort)
            {
                //foreach (var group in list)
                //{
                //    group.ToList().Sort((c0, c1) => ci.CompareInfo.Compare(getKey(c0).ToShortDateString(), getKey(c1).ToShortDateString()));
                //}
            }

            return(list);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Create a list of AlphaGroup&lt;T&gt; with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static List <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            SortedLocaleGrouping      slg  = new SortedLocaleGrouping(ci);
            List <AlphaKeyGroup <T> > list = CreateGroups(slg);

            foreach (T item in items)
            {
                int index = slg.GetGroupIndex(getKey(item));
                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }

            if (sort)
            {
                foreach (AlphaKeyGroup <T> group in list)
                {
                    group.Sort((c0, c1) => { return(ci.CompareInfo.Compare(getKey(c0), getKey(c1))); });
                }
            }

            return(list);
        }
Ejemplo n.º 17
0
            public static List <GroupFav <TopicFav> > CreateGroups(List <TopicFav> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
            {
                Microsoft.Phone.Globalization.SortedLocaleGrouping slg = new Microsoft.Phone.Globalization.SortedLocaleGrouping(ci);
                List <GroupFav <TopicFav> > list = new List <GroupFav <TopicFav> >();

                list.Add(new GroupFav <TopicFav>("Hardware"));
                list.Add(new GroupFav <TopicFav>("Périphériques"));
                list.Add(new GroupFav <TopicFav>("PC portables"));
                list.Add(new GroupFav <TopicFav>("Techno. Mobiles"));
                list.Add(new GroupFav <TopicFav>("Overclock & Tuning"));
                list.Add(new GroupFav <TopicFav>("Apple        "));
                list.Add(new GroupFav <TopicFav>("Vidéo & Son"));
                list.Add(new GroupFav <TopicFav>("Photo Numérique"));
                list.Add(new GroupFav <TopicFav>("Jeux-vidéo"));
                list.Add(new GroupFav <TopicFav>("Windows & Software"));
                list.Add(new GroupFav <TopicFav>("Réseaux grand public"));
                list.Add(new GroupFav <TopicFav>("Réseaux Pro"));
                list.Add(new GroupFav <TopicFav>("OS Alternatifs"));
                list.Add(new GroupFav <TopicFav>("Programmation"));
                list.Add(new GroupFav <TopicFav>("Graphisme"));
                list.Add(new GroupFav <TopicFav>("Achats & Ventes"));
                list.Add(new GroupFav <TopicFav>("Emploi & Etudes"));
                list.Add(new GroupFav <TopicFav>("Projets distribués"));
                list.Add(new GroupFav <TopicFav>("Discussions"));

                items.Add(new TopicFav()
                {
                    TopicNameFav            = " ",
                    TopicCatIdFav           = " ",
                    TopicIdFav              = " ",
                    TopicCatNameFav         = " ",
                    TopicUriFav             = "",
                    TopicLastPostDateDouble = 0,
                    TopicLastPost           = "",
                    TopicNumberOfPages      = "",
                    TopicPageNumber         = "",
                });
                foreach (TopicFav item in items)
                {
                    int i     = 0;
                    int index = -1;
                    foreach (var it in list)
                    {
                        string currentKey = it.Key;
                        if (currentKey == item.TopicCatNameFav)
                        {
                            index = i;
                        }
                        i++;
                    }
                    if (index != -1)
                    {
                        list[index].Add(item);
                    }
                }
                return(list);
            }
Ejemplo n.º 18
0
            public static List <GroupFav <TopicNorm> > CreateGroups(List <TopicNorm> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
            {
                Microsoft.Phone.Globalization.SortedLocaleGrouping slg = new Microsoft.Phone.Globalization.SortedLocaleGrouping(ci);
                List <GroupFav <TopicNorm> > list = new List <GroupFav <TopicNorm> >();

                list.Add(new GroupFav <TopicNorm>("page 1"));
                list.Add(new GroupFav <TopicNorm>("page 2"));
                list.Add(new GroupFav <TopicNorm>("page 3"));
                list.Add(new GroupFav <TopicNorm>("page 4"));
                list.Add(new GroupFav <TopicNorm>("page 5"));
                list.Add(new GroupFav <TopicNorm>("page 6"));
                list.Add(new GroupFav <TopicNorm>("page 7"));
                list.Add(new GroupFav <TopicNorm>("page 8"));
                list.Add(new GroupFav <TopicNorm>("page 9"));
                list.Add(new GroupFav <TopicNorm>("page 10"));
                list.Add(new GroupFav <TopicNorm>("page 11"));
                list.Add(new GroupFav <TopicNorm>("page 12"));
                list.Add(new GroupFav <TopicNorm>("page 13"));
                list.Add(new GroupFav <TopicNorm>("page 14"));
                list.Add(new GroupFav <TopicNorm>("page 15"));
                list.Add(new GroupFav <TopicNorm>("page 16"));
                list.Add(new GroupFav <TopicNorm>("page 17"));
                list.Add(new GroupFav <TopicNorm>("page 18"));
                list.Add(new GroupFav <TopicNorm>("page 19"));
                list.Add(new GroupFav <TopicNorm>("page 20"));

                //items.Add(new TopicNorm()
                //{
                //    TopicCatId="",
                //    TopicDrap="",
                //    TopicGroup
                //    TopicIconUri

                //    TopicLastPostDateDouble = 0,
                //    TopicLastPost = "",
                //    TopicNumberOfPages = "",
                //    TopicPageNumber = "",
                //});
                foreach (TopicNorm item in items)
                {
                    int i     = 0;
                    int index = -1;
                    foreach (var it in list)
                    {
                        string currentKey = it.Key;
                        if (currentKey == item.TopicGroup)
                        {
                            index = i;
                        }
                        i++;
                    }
                    if (index != -1)
                    {
                        list[index].Add(item);
                    }
                }
                return(list);
            }
        public static ObservableCollection <StringKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci, GetKeyDelegate getKey, bool sort)
        {
            var list = new ObservableCollection <StringKeyGroup <T> >();

            foreach (var item in items)
            {
                var index = -1;
                for (var i = 0; i < list.Count; i++)
                {
                    if (list[i].Key.Equals(getKey(item)))
                    {
                        index = i;
                        break;
                    }
                }
                if (index == -1)
                {
                    list.Add(new StringKeyGroup <T>(getKey(item)));
                    index = list.Count - 1;
                }
                if (index >= 0 && index < list.Count)
                {
                    list[index].Add(item);
                }
            }
            if (sort)
            {
                foreach (var group in list)
                {
                    group.ToList().Sort((c0, c1) => ci.CompareInfo.Compare(getKey(c0), getKey(c1)));
                }
            }
            return(list);
        }
Ejemplo n.º 20
0
        /// <summary>
        ///     Create a list of AlphaGroup<T> with keys set by a SortedLocaleGrouping.
        /// </summary>
        /// <param name="items">The items to place in the groups.</param>
        /// <param name="ci">The CultureInfo to group and sort by.</param>
        /// <param name="getKey">A delegate to get the key from an item.</param>
        /// <param name="sort">Will sort the data if true.</param>
        /// <returns>An items source for a LongListSelector</returns>
        public static OptimizedObservableCollection <AlphaKeyGroup <T> > CreateGroups(IEnumerable <T> items, CultureInfo ci,
                                                                                      GetKeyDelegate getKey,
                                                                                      bool sort)
        {
            var slg  = new CharacterGroupings();
            var list = CreateGroups(slg);

            foreach (T item in items)
            {
                var lookUp = getKey(item);

                if (string.IsNullOrEmpty(lookUp))
                {
                    continue;
                }

                var index  = slg.Lookup(lookUp);
                var indexs = index.ToUpper();

                try
                {
                    list.Find(a => a.Key.Equals(indexs, StringComparison.CurrentCultureIgnoreCase)).Items.Add(item);
                }
                catch
                {
                    list.FirstOrDefault().Items.Add(item);
                }


                if (sort)
                {
                    foreach (AlphaKeyGroup <T> group in list)
                    {
                        group.OrderKey = getKey;
                        var asList = group.ToList();
                        asList.Sort((x, y) => string.Compare(getKey(x), getKey(y), StringComparison.Ordinal));
                        group.SwitchTo(asList);
                    }
                }
            }

            return(new OptimizedObservableCollection <AlphaKeyGroup <T> >(list));
        }
/// This method checks its arguments and assigns them to the fields of this class.
///
/// internal ListEnumerable(IList<T> list, GetKeyDelegate getKey, K key) {
///      this.list = list;
///      this.getKey = getKey;
///      this.key = key;
/// }
/// <@throws>
/// ArgumetnNullException if any argument is null.
/// </@throws>
/// <param name="key">
/// The key to look up in the list.
/// </param>
/// <param name="list">
/// The list in which to do the search.
/// </param>
/// <param name="getKey">
/// The delegate to pull keys out of elements.
/// </param>
        public ListEnumerable(IList <T> list, GetKeyDelegate getKey, K key)
        {
        }