Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
looly committed Jun 15, 2021
1 parent ad40ca5 commit 40dcdf5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1171,11 +1171,14 @@ public static <T> Collection<T> edit(Collection<T> collection, Editor<T> editor)
*
* @param <T> 集合元素类型
* @param collection 集合
* @param filter 过滤器
* @param filter 过滤器,{@link null}返回原集合
* @return 过滤后的数组
* @since 3.1.0
*/
public static <T> Collection<T> filterNew(Collection<T> collection, Filter<T> filter) {
if(null == collection || null == filter){
return collection;
}
return edit(collection, t -> filter.accept(t) ? t : null);
}

Expand Down
10 changes: 8 additions & 2 deletions hutool-core/src/main/java/cn/hutool/core/map/MapUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,14 @@ public static <K, V> Map<K, V> edit(Map<K, V> map, Editor<Entry<K, V>> editor) {
* @param <K> Key类型
* @param <V> Value类型
* @param map Map
* @param filter 编辑器接口
* @param filter 编辑器接口,{@link null}返回原Map
* @return 过滤后的Map
* @since 3.1.0
*/
public static <K, V> Map<K, V> filter(Map<K, V> map, Filter<Entry<K, V>> filter) {
if(null == map || null == filter){
return map;
}
return edit(map, t -> filter.accept(t) ? t : null);
}

Expand All @@ -674,12 +677,15 @@ public static <K, V> Map<K, V> filter(Map<K, V> map, Filter<Entry<K, V>> filter)
* @param <K> Key类型
* @param <V> Value类型
* @param map 原始Map
* @param keys 键列表
* @param keys 键列表,{@link null}返回原Map
* @return Map 结果,结果的Map类型与原Map保持一致
* @since 4.0.10
*/
@SuppressWarnings("unchecked")
public static <K, V> Map<K, V> filter(Map<K, V> map, K... keys) {
if(null == map || null == keys){
return map;
}
Map<K, V> map2 = ObjectUtil.clone(map);
if (isEmpty(map2)) {
return map2;
Expand Down
3 changes: 3 additions & 0 deletions hutool-core/src/main/java/cn/hutool/core/util/ArrayUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ public static <T> T[] edit(T[] array, Editor<T> editor) {
* @since 3.2.1
*/
public static <T> T[] filter(T[] array, Filter<T> filter) {
if(null == array || null == filter){
return array;
}
return edit(array, t -> filter.accept(t) ? t : null);
}

Expand Down

0 comments on commit 40dcdf5

Please sign in to comment.