将多个集合排序并显示不同的段落（分页）<br>
采用{@link BoundedPriorityQueue}实现分页取局部

@param <T> 集合元素类型
@param pageNo 页码，从1开始计数，0和1效果相同
@param pageSize 每页的条目数
@param comparator 比较器
@param colls 集合数组
@return 分页后的段落内容
970723
@SafeVarargs
	public static <T> List<T> sortPageAll(int pageNo, int pageSize, Comparator<T> comparator, Collection<T>... colls) {
		final List<T> list = new ArrayList<>(pageNo * pageSize);
		for (Collection<T> coll : colls) {
			list.addAll(coll);
		}
		if (null != comparator) {
			Collections.sort(list, comparator);
		}

		return page(pageNo, pageSize, list);
	}
831193
public static Page<Computer> page(int page, int pageSize, String sortBy, String order, String filter) {
        return 
            find.where()
                .ilike("name", "%" + filter + "%")
                .orderBy(sortBy + " " + order)
                .fetch("company")
                .findPagingList(pageSize)
                .getPage(page);
    }
626210
@Override
    public int compareTo(BLine other) {

        int pageCompare = new Integer(pageId).compareTo(other.pageId);
        if (pageCompare != 0) {
            return pageCompare;
        }

        int xCompare = new Float(region.x).compareTo(other.region.x);
        if (xCompare != 0) {
            return xCompare;
        }
        int yCompare = new Float(region.y).compareTo(other.region.y);
        return yCompare;
    }
1224903
private Collection<String> getPages(String startDate, String endDate, List<Dimension> dimensions,
      ApiDimensionFilter countryFilter, Queue<Pair<String, FilterOperator>> toProcess, int rowLimit) {
    String country = GoogleWebmasterFilter.countryFilterToString(countryFilter);

    ConcurrentLinkedDeque<String> allPages = new ConcurrentLinkedDeque<>();
    int r = 0;
    while (r <= GET_PAGES_RETRIES) {
      ++r;
      log.info(String.format("Get pages at round %d with size %d.", r, toProcess.size()));
      ConcurrentLinkedDeque<Pair<String, FilterOperator>> nextRound = new ConcurrentLinkedDeque<>();
      ExecutorService es = Executors.newFixedThreadPool(10,
          ExecutorsUtils.newDaemonThreadFactory(Optional.of(log), Optional.of(this.getClass().getSimpleName())));

      while (!toProcess.isEmpty()) {
        submitJob(toProcess.poll(), countryFilter, startDate, endDate, dimensions, es, allPages, nextRound, rowLimit);
      }
      //wait for jobs to finish and start next round if necessary.
      try {
        es.shutdown();
        boolean terminated = es.awaitTermination(5, TimeUnit.MINUTES);
        if (!terminated) {
          es.shutdownNow();
          log.warn("Timed out while getting all pages for country-{} at round {}. Next round now has size {}.", country,
              r, nextRound.size());
        }
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }

      if (nextRound.isEmpty()) {
        break;
      }
      toProcess = nextRound;
      coolDown(r, PAGES_GET_COOLDOWN_TIME);
    }
    if (r == GET_PAGES_RETRIES + 1) {
      throw new RuntimeException(
          String.format("Getting all pages reaches the maximum number of retires %d. Date range: %s ~ %s. Country: %s.",
              GET_PAGES_RETRIES, startDate, endDate, country));
    }
    return allPages;
  }
41266
public static final <T> void quickSort(List<T> list, Comparator<T> comparator)
    {
        quickSort(list, 0, list.size()-1, comparator);
    }
348201
public static <T extends Comparable<?>> List<T> topN(Iterable<T> coll, int n) {
		return Ordering.natural().greatestOf(coll, n);
	}
1117636
public SearchOptions setPage(int page, int pageSize) {
    checkArgument(page >= 1, "Page must be greater or equal to 1 (got " + page + ")");
    int lastResultIndex = page * pageSize;
    checkArgument(lastResultIndex <= MAX_RETURNABLE_RESULTS, "Can return only the first %s results. %sth result asked.", MAX_RETURNABLE_RESULTS, lastResultIndex);
    setLimit(pageSize);
    setOffset((page * this.limit) - this.limit);
    return this;
  }
1007101
synchronized int size( int priority) {
    if (priority < 0 || priority >= LEVEL) {
      throw new IllegalArgumentException("Unsupported priority: " + priority);
    }
    return priorityQueues.get(priority).size();
  }
670224
public Queue<SessionSchedulable> createSessionQueue(
      ScheduleComparator comparator) {
    int initCapacity = snapshotSessions.size() == 0 ?
        1 : snapshotSessions.size();
    Queue<SessionSchedulable> sessionQueue =
      new PriorityQueue<SessionSchedulable>(initCapacity, comparator);
    sessionQueue.addAll(snapshotSessions);
    return sessionQueue;
  }
1062332
@Override
	public List<V> load(final int first, final int pageSize,
			final List<SortMeta> multiSortMeta,
			final Map<String, Object> filters) {

		final boolean filtersChanged = handleFilters(filters);
		final boolean sortOrderChanged = handleSortOrder(multiSortMeta);
		boolean notify = false;

		// clear cache
		if (filtersChanged || sortOrderChanged) {
			adaptee.clearCache();
			notify = filtersChanged || notifyOnSortOrderChanges;
		}

		adaptee.setPageSize(pageSize);
		final int size = adaptee.getSize();
		adaptee.setFirst(first >= size ? Math.max(0, size - 1) : first);
		setRowCount(size);

		// notify observers
		if (filtersChanged && clearSelectionOnFilterChanges) {
			adaptee.clearSelection();
		}
		if (notify) {
			adaptee.notify(ChangeEventType.DATA);
		}

		return adaptee.getData();
	}
1235082
public static <T> List<T> subList(List<T> list, int pageSize, int pageNo) {
        pageSize = (pageSize <= 0 ? 10 : pageSize);
        pageNo = (pageNo <= 0 ? 1 : pageNo);
        int begin = (pageSize * (pageNo - 1) > list.size() ? list.size() : pageSize * (pageNo - 1));
        int end = (pageSize * pageNo > list.size() ? list.size() : pageSize * pageNo);
        return new ArrayList<T>(list.subList(begin, end));
    }
1178823
private static void partialSort(
      final WordIterator[] a,
      final int maxChangedIndex,
      final int size,
      final Comparator<WordIterator> comp
  )
  {
    for (int i = maxChangedIndex; i >= 0; i--) {
      WordIterator it = a[i];
      for (int j = i + 1; j < size; j++) {
        WordIterator it2 = a[j];
        if (comp.compare(it, it2) <= 0) {
          break;
        }
        a[j - 1] = it2;
        a[j] = it;
      }
    }
  }
312857
List<PageEntry> getEntries(int firstIndex, int lastIndex) {
        Preconditions.checkArgument(firstIndex <= lastIndex, "firstIndex must be smaller than or equal to lastIndex.");
        ArrayList<PageEntry> result = new ArrayList<>();
        for (int i = firstIndex; i <= lastIndex; i++) {
            result.add(getEntryAt(i));
        }

        return result;
    }
805652
public static String sortIgnoreEmpty(String list, String sortType, String sortOrder, String delimiter) throws PageException {
	return _sort(toStringArray(listToArrayRemoveEmpty(list, delimiter)), sortType, sortOrder, delimiter);
    }
1249869
public static PageRequest of(final int page, final int size) {
    return PageRequest.of(page, size, Sort.unsorted());
  }
1283797
public static <T> Iterator<T> getSortedIterator (Iterable<T> coll, Comparator<T> comparator)
    {
        return getSortedIterator(coll.iterator(), comparator);
    }
824002
protected long scanPagesToSend(long maxClientReplicatedPageVersion, FastUnsafeOffHeapIntList pagesToSend)
    {
        long maxPageVersion = 0;
        boolean upgraded = false;
        for(int i=0;i<this.pageVersionList.size();i++)
        {
            if (pageVersionList.get(i) == 0 && !upgraded)
            {
                boolean originalLockWasReleased = this.readWriteLock.upgradeToWriteLock();
                this.currentPageVersion++;
                if (originalLockWasReleased)
                {
                    pagesToSend.clear();
                    for(int j=0;j<i;j++)
                    {
                        maxPageVersion = markAndAddPageIfRequired(maxClientReplicatedPageVersion, pagesToSend, maxPageVersion, j);
                    }
                }
                upgraded = true;
            }
            maxPageVersion = markAndAddPageIfRequired(maxClientReplicatedPageVersion, pagesToSend, maxPageVersion, i);
        }
        return maxPageVersion;
    }