コード例 #1
0
  /**
   * Get the keys of this vector sorted by the value of the items stored for each key.
   *
   * @param decreasing If {@code true}, sort in decreasing order.
   * @return The sorted list of keys of this vector.
   */
  public LongArrayList keysByValue(boolean decreasing) {
    long[] skeys = keySet().toLongArray();

    LongComparator cmp;
    // Set up the comparator. We use the key as a secondary comparison to get
    // a reproducible sort irrespective of sorting algorithm.
    if (decreasing) {
      cmp =
          new AbstractLongComparator() {
            @Override
            public int compare(long k1, long k2) {
              int c = Double.compare(get(k2), get(k1));
              if (c != 0) {
                return c;
              } else {
                return Longs.compare(k1, k2);
              }
            }
          };
    } else {
      cmp =
          new AbstractLongComparator() {
            @Override
            public int compare(long k1, long k2) {
              int c = Double.compare(get(k1), get(k2));
              if (c != 0) {
                return c;
              } else {
                return Longs.compare(k1, k2);
              }
            }
          };
    }

    LongArrays.quickSort(skeys, cmp);
    return LongArrayList.wrap(skeys);
  }