示例#1
0
 /**
  * Returns a TreeMap containing {@code n} values of a given Function {@code f} over a range of
  * integer values from 0 to {@code n - 1}.
  *
  * @param <K> The key type
  * @param <V> The value type
  * @param keyComparator The comparator used to sort the entries by their key
  * @param n The number of elements in the TreeMap
  * @param f The Function computing element values
  * @return A TreeMap consisting of elements {@code f(0),f(1), ..., f(n - 1)}
  * @throws NullPointerException if {@code keyComparator} or {@code f} are null
  */
 @SuppressWarnings("unchecked")
 public static <K, V> TreeMap<K, V> tabulate(
     Comparator<? super K> keyComparator,
     int n,
     Function<? super Integer, ? extends Tuple2<? extends K, ? extends V>> f) {
   Objects.requireNonNull(keyComparator, "keyComparator is null");
   Objects.requireNonNull(f, "f is null");
   return ofEntries(
       keyComparator,
       Collections.tabulate(n, (Function<? super Integer, ? extends Tuple2<K, V>>) f));
 }