Пример #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));
 }