Example usage for com.google.common.collect MinMaxPriorityQueue.Builder create

List of usage examples for com.google.common.collect MinMaxPriorityQueue.Builder create

Introduction

In this page you can find the example usage for com.google.common.collect MinMaxPriorityQueue.Builder create.

Prototype

public static <E extends Comparable<E>> MinMaxPriorityQueue<E> create() 

Source Link

Document

Creates a new min-max priority queue with default settings: natural order, no maximum size, no initial contents, and an initial expected size of 11.

Usage

From source file:com.linkedin.pinot.core.query.aggregation.groupby.AggregationGroupByOperatorService.java

/**
 * Returns a MinMaxPriorityQueue with the given size limit, and ordering.
 * Will return null if the value to be inserted is not an instance of comparable.
 *
 * @param sampleObject To determine if the object is Comparable.
 * @param maxSize The max size for the heap.
 * @param reverseOrder True if sorting order to be reversed.
 * @return/*  w w w .ja  v a 2s .  c om*/
 */
private static MinMaxPriorityQueue<ImmutablePair<Serializable, String>> getMinMaxPriorityQueue(
        Serializable sampleObject, int maxSize, boolean reverseOrder) {
    if (!(sampleObject instanceof Comparable)) {
        return null;
    }

    Comparator<ImmutablePair<Serializable, String>> comparator = new GroupByResultComparator<ImmutablePair<Serializable, String>>()
            .newComparator(reverseOrder);

    MinMaxPriorityQueue.Builder<ImmutablePair<Serializable, String>> minMaxPriorityQueueBuilder = MinMaxPriorityQueue
            .orderedBy(comparator).maximumSize(maxSize);

    return minMaxPriorityQueueBuilder.create();
}