Beispiel #1
0
 @Override
 public <K2> TreeMap<K2, V> mapKeys(
     Function<? super K, ? extends K2> keyMapper,
     BiFunction<? super V, ? super V, ? extends V> valueMerge) {
   final Comparator<K2> comparator = naturalComparator();
   return Collections.mapKeys(this, TreeMap.<K2, V>empty(comparator), keyMapper, valueMerge);
 }
Beispiel #2
0
 /**
  * Creates a {@code TreeMap} of the given entries using the given key comparator.
  *
  * @param <K> The key type
  * @param <V> The value type
  * @param entries Map entries
  * @param keyComparator A key comparator
  * @return A new TreeMap containing the given entries.
  */
 @SafeVarargs
 public static <K, V> TreeMap<K, V> ofEntries(
     Comparator<? super K> keyComparator,
     java.util.Map.Entry<? extends K, ? extends V>... entries) {
   Objects.requireNonNull(keyComparator, "keyComparator is null");
   Objects.requireNonNull(entries, "entries is null");
   RedBlackTree<Tuple2<K, V>> tree = RedBlackTree.empty(new EntryComparator<>(keyComparator));
   for (java.util.Map.Entry<? extends K, ? extends V> entry : entries) {
     tree = tree.insert(Tuple.of(entry.getKey(), entry.getValue()));
   }
   return tree.isEmpty() ? TreeMap.empty(keyComparator) : new TreeMap<>(tree);
 }
Beispiel #3
0
 /**
  * Creates a {@code TreeMap} of the given entries using the given key comparator.
  *
  * @param <K> The key type
  * @param <V> The value type
  * @param entries Map entries
  * @param keyComparator A key comparator
  * @return A new TreeMap containing the given entries.
  */
 @SuppressWarnings("unchecked")
 @SafeVarargs
 public static <K, V> TreeMap<K, V> ofEntries(
     Comparator<? super K> keyComparator, Tuple2<? extends K, ? extends V>... entries) {
   Objects.requireNonNull(keyComparator, "keyComparator is null");
   Objects.requireNonNull(entries, "entries is null");
   RedBlackTree<Tuple2<K, V>> tree = RedBlackTree.empty(new EntryComparator<>(keyComparator));
   for (Tuple2<? extends K, ? extends V> entry : entries) {
     tree = tree.insert((Tuple2<K, V>) entry);
   }
   return tree.isEmpty() ? TreeMap.empty(keyComparator) : new TreeMap<>(tree);
 }
Beispiel #4
0
 /**
  * Returns a singleton {@code TreeMap}, i.e. a {@code TreeMap} of one element.
  *
  * @param key A singleton map key.
  * @param value A singleton map value.
  * @param <K> The key type
  * @param <V> The value type
  * @param keyComparator The comparator used to sort the entries by their key.
  * @return A new Map containing the given entry
  */
 public static <K, V> TreeMap<K, V> of(Comparator<? super K> keyComparator, K key, V value) {
   Objects.requireNonNull(keyComparator, "keyComparator is null");
   return TreeMap.<K, V>empty(keyComparator).put(key, value);
 }
Beispiel #5
0
 /**
  * Returns a singleton {@code TreeMap}, i.e. a {@code TreeMap} of one entry using a specific key
  * comparator.
  *
  * @param <K> The key type
  * @param <V> The value type
  * @param entry A map entry.
  * @param keyComparator The comparator used to sort the entries by their key.
  * @return A new TreeMap containing the given entry.
  */
 public static <K, V> TreeMap<K, V> of(
     Comparator<? super K> keyComparator, Tuple2<? extends K, ? extends V> entry) {
   Objects.requireNonNull(keyComparator, "keyComparator is null");
   Objects.requireNonNull(entry, "entry is null");
   return TreeMap.<K, V>empty(keyComparator).put(entry);
 }