public synchronized double get(double q) {
        // clear the buffer
        insertBatch();
        compress();

        if (sample.size() == 0) {
            return Double.NaN;
        }

        int rankMin = 0;
        int desired = (int) (q * count);

        ListIterator<Item> it = sample.listIterator();
        Item prev, cur;
        cur = it.next();
        while (it.hasNext()) {
            prev = cur;
            cur = it.next();

            rankMin += prev.g;

            if (rankMin + cur.g + cur.delta > desired
                    + (allowableError(desired) / 2)) {
                return prev.value;
            }
        }

        // edge case of wanting max value
        return sample.getLast().value;
    }
public synchronized double get ( double q ) { insertBatch ( ) ; compress ( ) ; if ( sample . size ( ) == 0 ) { return Double . NaN ; } int rankMin = 0 ; int desired = ( int ) ( q * count ) ; ListIterator < Item > it = sample . listIterator ( ) ; Item prev , cur ; cur = it . next ( ) ; while ( it . hasNext ( ) ) { prev = cur ; cur = it . next ( ) ; rankMin += prev . g ; if ( rankMin + cur . g + cur . delta > desired + ( allowableError ( desired ) / 2 ) ) { return prev . value ; } } return sample . getLast ( ) . value ; }
Get the estimated value at the specified quantile.

@param q
Queried quantile, e.g. 0.50 or 0.99.
@return Estimated value at that quantile.