示例#1
0
 @Override
 public Tuple2<HashMap<K, V>, HashMap<K, V>> partition(Predicate<? super Tuple2<K, V>> predicate) {
   Objects.requireNonNull(predicate, "predicate is null");
   final Tuple2<Iterator<Tuple2<K, V>>, Iterator<Tuple2<K, V>>> p =
       iterator().partition(predicate);
   return Tuple.of(HashMap.ofAll(p._1), HashMap.ofAll(p._2));
 }
示例#2
0
 @Override
 public HashMap<K, V> takeRight(int n) {
   if (trie.size() <= n) {
     return this;
   } else {
     return HashMap.ofAll(trie.iterator().takeRight(n));
   }
 }
示例#3
0
 @Override
 public HashMap<K, V> dropRight(int n) {
   if (n <= 0) {
     return this;
   }
   if (n >= length()) {
     return empty();
   }
   return HashMap.ofAll(iterator().dropRight(n));
 }
示例#4
0
 @Override
 public HashMap<K, V> merge(Map<? extends K, ? extends V> that) {
   Objects.requireNonNull(that, "that is null");
   if (isEmpty()) {
     return HashMap.ofAll(that);
   } else if (that.isEmpty()) {
     return this;
   } else {
     return that.foldLeft(this, (map, entry) -> !map.containsKey(entry._1) ? map.put(entry) : map);
   }
 }
示例#5
0
 @Override
 public <U extends V> HashMap<K, V> merge(
     Map<? extends K, U> that, BiFunction<? super V, ? super U, ? extends V> collisionResolution) {
   Objects.requireNonNull(that, "that is null");
   Objects.requireNonNull(collisionResolution, "collisionResolution is null");
   if (isEmpty()) {
     return HashMap.ofAll(that);
   } else if (that.isEmpty()) {
     return this;
   } else {
     return that.foldLeft(
         this,
         (map, entry) -> {
           final K key = entry._1;
           final U value = entry._2;
           final V newValue =
               map.get(key).map(v -> (V) collisionResolution.apply(v, value)).orElse(value);
           return map.put(key, newValue);
         });
   }
 }
示例#6
0
 @Override
 public HashMap<K, V> takeWhile(Predicate<? super Tuple2<K, V>> predicate) {
   Objects.requireNonNull(predicate, "predicate is null");
   final HashMap<K, V> taken = HashMap.ofAll(iterator().takeWhile(predicate));
   return taken.length() == length() ? this : taken;
 }
示例#7
0
 @Override
 public HashMap<K, V> scan(
     Tuple2<K, V> zero,
     BiFunction<? super Tuple2<K, V>, ? super Tuple2<K, V>, ? extends Tuple2<K, V>> operation) {
   return HashMap.ofAll(scanLeft(zero, operation));
 }
示例#8
0
 @Override
 public HashMap<K, V> dropWhile(Predicate<? super Tuple2<K, V>> predicate) {
   Objects.requireNonNull(predicate, "predicate is null");
   return HashMap.ofAll(iterator().dropWhile(predicate));
 }
示例#9
0
 @Override
 public <U> HashMap<K, V> distinctBy(Function<? super Tuple2<K, V>, ? extends U> keyExtractor) {
   Objects.requireNonNull(keyExtractor, "keyExtractor is null");
   return HashMap.ofAll(iterator().distinctBy(keyExtractor));
 }
示例#10
0
 @Override
 public HashMap<K, V> distinctBy(Comparator<? super Tuple2<K, V>> comparator) {
   Objects.requireNonNull(comparator, "comparator is null");
   return HashMap.ofAll(iterator().distinctBy(comparator));
 }