public static IComparer <KeyValuePair <TKey, TValue> > NewComparator <TKey, TValue>(PagingPredicate <TKey, TValue> pagingPredicate) { return(new SortingComparer <TKey, TValue>(pagingPredicate.GetComparator(), pagingPredicate.GetIterationType())); }
public static SortedQueryResultSet <TKey, TValue> GetSortedQueryResultSet <TKey, TValue>(ISet <KeyValuePair <TKey, TValue> > list, PagingPredicate <TKey, TValue> pagingPredicate, IterationType iterationType) { if (list == null || list.Count == 0) { return(new SortedQueryResultSet <TKey, TValue>()); } IComparer <KeyValuePair <TKey, TValue> > comparer = SortingUtil.NewComparator(pagingPredicate.GetComparator(), iterationType); List <KeyValuePair <TKey, TValue> > sortedList = new List <KeyValuePair <TKey, TValue> >(); sortedList.AddRange(list); sortedList.Sort(comparer); KeyValuePair <int, KeyValuePair <TKey, TValue> > nearestAnchorEntry = pagingPredicate.GetNearestAnchorEntry(); int nearestPage = nearestAnchorEntry.Key; int page = pagingPredicate.GetPage(); int pageSize = pagingPredicate.GetPageSize(); int begin = pageSize * (page - nearestPage - 1); int size = sortedList.Count; if (begin > size) { return(new SortedQueryResultSet <TKey, TValue>()); } int end = begin + pageSize; if (end > size) { pageSize = size - begin; } SetAnchor(sortedList, pagingPredicate, nearestPage); List <KeyValuePair <TKey, TValue> > subList = sortedList.GetRange(begin, pageSize); return(new SortedQueryResultSet <TKey, TValue>(comparer, subList, iterationType)); }