@@ -0,0 +1,1744 @@
+import java.util.Comparator;%0Aimport java.util.Map;%0Aimport java.util.concurrent.ConcurrentHashMap;%0Aimport com.google.common.collect.MinMaxPriorityQueue;%0A%0A// test MinMaxPriorityQueue%0Apublic class TestMinMaxPriorityQueue %7B%0A  private final static Map%3CLong, Long%3E%0A    bucketsLastAccessedTime = new ConcurrentHashMap%3C%3E();%0A%0A  //bucket keys in the order they are accessed%0A  private static final Comparator%3CLong%3E cmp = new Comparator%3CLong%3E() %7B%0A    @Override%0A    public int compare(Long bucketId1, Long bucketId2) %7B%0A      return Long.compare(bucketsLastAccessedTime.get(bucketId1),%0A                          bucketsLastAccessedTime.get(bucketId2));%0A    %7D%0A  %7D;%0A%0A  private static final MinMaxPriorityQueue.Builder%3CLong%3E%0A    builder = MinMaxPriorityQueue.orderedBy(cmp);%0A  private static final MinMaxPriorityQueue%3CLong%3E%0A    bucketHeap = builder.create();%0A%0A  static void test() throws Exception %7B%0A    long keys%5B%5D = %7B1L, 2L, 3L, 4L%7D;%0A    for ( long key : keys ) %7B%0A      bucketsLastAccessedTime.put(key, System.currentTimeMillis());%0A      bucketHeap.add(key);%0A    %7D%0A%0A    // dump map and queue%0A    System.out.format(%22bucketsLastAccessedTime = %25s%25nbucketHeap = %25s%25n%22,%0A                      bucketsLastAccessedTime, bucketHeap);%0A%0A    // relax for a bit, then insert same keys but with different timestamps%0A    Thread.sleep(1000);%0A%0A    for ( long key : keys ) %7B%0A      bucketsLastAccessedTime.put(key, System.currentTimeMillis());%0A      bucketHeap.add(key);%0A    %7D%0A%0A    // dump map and queue%0A    System.out.format(%22Later:%25nbucketsLastAccessedTime = %25s%25nbucketHeap = %25s%25n%22,%0A                      bucketsLastAccessedTime, bucketHeap);%0A  %7D  // test%0A%0A  public static void main(String args%5B%5D) throws Exception %7B%0A    test();%0A    System.out.println(%22Done%22);%0A  %7D  // main%0A%7D%0A

Add TestMinMaxPriorityQueue