Skip to content

Commit

Permalink
Implement Traversable#reject
Browse files Browse the repository at this point in the history
  • Loading branch information
valery1707 committed Nov 8, 2017
1 parent b60ec83 commit a7c9d8c
Show file tree
Hide file tree
Showing 36 changed files with 465 additions and 24 deletions.
36 changes: 30 additions & 6 deletions vavr/src/main/java/io/vavr/collection/AbstractMultimap.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,40 +253,64 @@ public M filter(Predicate<? super Tuple2<K, V>> predicate) {
}
}

@Override
public M reject(Predicate<? super Tuple2<K, V>> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filter(predicate.negate());
}

@Override
public M filter(BiPredicate<? super K, ? super V> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filter(t -> predicate.test(t._1, t._2));
}

@Override
public M reject(BiPredicate<? super K, ? super V> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return reject(t -> predicate.test(t._1, t._2));
}

@Override
public M filterKeys(Predicate<? super K> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filter(t -> predicate.test(t._1));
}

@Override
public M rejectKeys(Predicate<? super K> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return reject(t -> predicate.test(t._1));
}

@Override
public M filterValues(Predicate<? super V> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filter(t -> predicate.test(t._2));
}

@Override
public M removeAll(BiPredicate<? super K, ? super V> predicate) {
public M rejectValues(Predicate<? super V> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filter(predicate.negate());
return reject(t -> predicate.test(t._2));
}

@Override
@Deprecated
public M removeAll(BiPredicate<? super K, ? super V> predicate) {
return reject(predicate);
}

@Override
@Deprecated
public M removeKeys(Predicate<? super K> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filterKeys(predicate.negate());
return rejectKeys(predicate);
}

@Override
@Deprecated
public M removeValues(Predicate<? super V> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filterValues(predicate.negate());
return rejectValues(predicate);
}

@SuppressWarnings("unchecked")
Expand Down
6 changes: 6 additions & 0 deletions vavr/src/main/java/io/vavr/collection/Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,12 @@ public Array<T> filter(Predicate<? super T> predicate) {
}
}

@Override
public Array<T> reject(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filter(predicate.negate());
}

@Override
public <U> Array<U> flatMap(Function<? super T, ? extends Iterable<? extends U>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
Expand Down
10 changes: 10 additions & 0 deletions vavr/src/main/java/io/vavr/collection/BitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ default BitSet<T> dropUntil(Predicate<? super T> predicate) {
@Override
BitSet<T> filter(Predicate<? super T> predicate);

@Override
BitSet<T> reject(Predicate<? super T> predicate);

@Override
default <U> SortedSet<U> flatMap(Comparator<? super U> comparator, Function<? super T, ? extends Iterable<? extends U>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
Expand Down Expand Up @@ -823,6 +826,13 @@ public BitSet<T> filter(Predicate<? super T> predicate) {
return (bitSet.length() == length()) ? this : bitSet;
}

@Override
public BitSet<T> reject(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
final BitSet<T> bitSet = createFromAll(iterator().reject(predicate));
return (bitSet.length() == length()) ? this : bitSet;
}

@Override
public <C> Map<C, BitSet<T>> groupBy(Function<? super T, ? extends C> classifier) {
return Collections.groupBy(this, classifier, this::createFromAll);
Expand Down
6 changes: 6 additions & 0 deletions vavr/src/main/java/io/vavr/collection/CharSeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,12 @@ public CharSeq filter(Predicate<? super Character> predicate) {
}
}

@Override
public CharSeq reject(Predicate<? super Character> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filter(predicate.negate());
}

@Override
public <U> IndexedSeq<U> flatMap(Function<? super Character, ? extends Iterable<? extends U>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
Expand Down
29 changes: 26 additions & 3 deletions vavr/src/main/java/io/vavr/collection/HashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -564,21 +564,41 @@ public HashMap<K, V> filter(BiPredicate<? super K, ? super V> predicate) {
return Maps.filter(this, this::createFromEntries, predicate);
}

@Override
public HashMap<K, V> reject(BiPredicate<? super K, ? super V> predicate) {
return Maps.reject(this, this::createFromEntries, predicate);
}

@Override
public HashMap<K, V> filter(Predicate<? super Tuple2<K, V>> predicate) {
return Maps.filter(this, this::createFromEntries, predicate);
}

@Override
public HashMap<K, V> reject(Predicate<? super Tuple2<K, V>> predicate) {
return Maps.reject(this, this::createFromEntries, predicate);
}

@Override
public HashMap<K, V> filterKeys(Predicate<? super K> predicate) {
return Maps.filterKeys(this, this::createFromEntries, predicate);
}

@Override
public HashMap<K, V> rejectKeys(Predicate<? super K> predicate) {
return Maps.rejectKeys(this, this::createFromEntries, predicate);
}

@Override
public HashMap<K, V> filterValues(Predicate<? super V> predicate) {
return Maps.filterValues(this, this::createFromEntries, predicate);
}

@Override
public HashMap<K, V> rejectValues(Predicate<? super V> predicate) {
return Maps.rejectValues(this, this::createFromEntries, predicate);
}

@Override
public <K2, V2> HashMap<K2, V2> flatMap(BiFunction<? super K, ? super V, ? extends Iterable<Tuple2<K2, V2>>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
Expand Down Expand Up @@ -755,8 +775,9 @@ public HashMap<K, V> remove(K key) {
}

@Override
@Deprecated
public HashMap<K, V> removeAll(BiPredicate<? super K, ? super V> predicate) {
return Maps.removeAll(this, this::createFromEntries, predicate);
return reject(predicate);
}

@Override
Expand All @@ -777,13 +798,15 @@ public HashMap<K, V> removeAll(Iterable<? extends K> keys) {
}

@Override
@Deprecated
public HashMap<K, V> removeKeys(Predicate<? super K> predicate) {
return Maps.removeKeys(this, this::createFromEntries, predicate);
return rejectKeys(predicate);
}

@Override
@Deprecated
public HashMap<K, V> removeValues(Predicate<? super V> predicate) {
return Maps.removeValues(this, this::createFromEntries, predicate);
return rejectValues(predicate);
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions vavr/src/main/java/io/vavr/collection/HashSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,12 @@ public HashSet<T> filter(Predicate<? super T> predicate) {
}
}

@Override
public HashSet<T> reject(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filter(predicate.negate());
}

@Override
public <U> HashSet<U> flatMap(Function<? super T, ? extends Iterable<? extends U>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
Expand Down
3 changes: 3 additions & 0 deletions vavr/src/main/java/io/vavr/collection/IndexedSeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ default boolean endsWith(Seq<? extends T> that) {
@Override
IndexedSeq<T> filter(Predicate<? super T> predicate);

@Override
IndexedSeq<T> reject(Predicate<? super T> predicate);

@Override
<U> IndexedSeq<U> flatMap(Function<? super T, ? extends Iterable<? extends U>> mapper);

Expand Down
6 changes: 6 additions & 0 deletions vavr/src/main/java/io/vavr/collection/Iterator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,12 @@ public T getNext() {
}
}

@Override
default Iterator<T> reject(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filter(predicate.negate());
}

@Override
default Option<T> findLast(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
Expand Down
3 changes: 3 additions & 0 deletions vavr/src/main/java/io/vavr/collection/LinearSeq.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ static <T> LinearSeq<T> narrow(LinearSeq<? extends T> linearSeq) {
@Override
LinearSeq<T> filter(Predicate<? super T> predicate);

@Override
LinearSeq<T> reject(Predicate<? super T> predicate);

@Override
<U> LinearSeq<U> flatMap(Function<? super T, ? extends Iterable<? extends U>> mapper);

Expand Down
29 changes: 26 additions & 3 deletions vavr/src/main/java/io/vavr/collection/LinkedHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -588,21 +588,41 @@ public LinkedHashMap<K, V> filter(BiPredicate<? super K, ? super V> predicate) {
return Maps.filter(this, this::createFromEntries, predicate);
}

@Override
public LinkedHashMap<K, V> reject(BiPredicate<? super K, ? super V> predicate) {
return Maps.reject(this, this::createFromEntries, predicate);
}

@Override
public LinkedHashMap<K, V> filter(Predicate<? super Tuple2<K, V>> predicate) {
return Maps.filter(this, this::createFromEntries, predicate);
}

@Override
public LinkedHashMap<K, V> reject(Predicate<? super Tuple2<K, V>> predicate) {
return Maps.reject(this, this::createFromEntries, predicate);
}

@Override
public LinkedHashMap<K, V> filterKeys(Predicate<? super K> predicate) {
return Maps.filterKeys(this, this::createFromEntries, predicate);
}

@Override
public LinkedHashMap<K, V> rejectKeys(Predicate<? super K> predicate) {
return Maps.rejectKeys(this, this::createFromEntries, predicate);
}

@Override
public LinkedHashMap<K, V> filterValues(Predicate<? super V> predicate) {
return Maps.filterValues(this, this::createFromEntries, predicate);
}

@Override
public LinkedHashMap<K, V> rejectValues(Predicate<? super V> predicate) {
return Maps.rejectValues(this, this::createFromEntries, predicate);
}

@Override
public <K2, V2> LinkedHashMap<K2, V2> flatMap(BiFunction<? super K, ? super V, ? extends Iterable<Tuple2<K2, V2>>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
Expand Down Expand Up @@ -794,8 +814,9 @@ public LinkedHashMap<K, V> remove(K key) {
}

@Override
@Deprecated
public LinkedHashMap<K, V> removeAll(BiPredicate<? super K, ? super V> predicate) {
return Maps.removeAll(this, this::createFromEntries, predicate);
return reject(predicate);
}

@Override
Expand All @@ -808,13 +829,15 @@ public LinkedHashMap<K, V> removeAll(Iterable<? extends K> keys) {
}

@Override
@Deprecated
public LinkedHashMap<K, V> removeKeys(Predicate<? super K> predicate) {
return Maps.removeKeys(this, this::createFromEntries, predicate);
return rejectKeys(predicate);
}

@Override
@Deprecated
public LinkedHashMap<K, V> removeValues(Predicate<? super V> predicate) {
return Maps.removeValues(this, this::createFromEntries, predicate);
return rejectValues(predicate);
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions vavr/src/main/java/io/vavr/collection/LinkedHashSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,12 @@ public LinkedHashSet<T> filter(Predicate<? super T> predicate) {
return filtered.length() == length() ? this : filtered;
}

@Override
public LinkedHashSet<T> reject(Predicate<? super T> predicate) {
Objects.requireNonNull(predicate, "predicate is null");
return filter(predicate.negate());
}

@Override
public <U> LinkedHashSet<U> flatMap(Function<? super T, ? extends Iterable<? extends U>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
Expand Down
6 changes: 6 additions & 0 deletions vavr/src/main/java/io/vavr/collection/List.java
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,12 @@ default List<T> filter(Predicate<? super T> predicate) {
}
}

@Override
default List<T> reject(Predicate<? super T> predicate){
Objects.requireNonNull(predicate, "predicate is null");
return filter(predicate.negate());
}

@Override
default <U> List<U> flatMap(Function<? super T, ? extends Iterable<? extends U>> mapper) {
Objects.requireNonNull(mapper, "mapper is null");
Expand Down
Loading

0 comments on commit a7c9d8c

Please sign in to comment.