This commit is contained in:
Looly 2020-05-13 14:43:29 +08:00
parent 1abab026dd
commit 76a47b3c54
2 changed files with 35 additions and 0 deletions

View File

@ -326,6 +326,39 @@ public class CollUtil {
return result;
}
/**
* 计算集合的单差集即只返回集合1中有但是集合2中没有的元素例如
*
* <pre>
* subtractToList([1,2,3,4],[2,3,4,5]) - [1]
* </pre>
*
* @param coll1 集合1
* @param coll2 集合2
* @param <T> 元素类型
* @return 单差集
* @since 5.3.5
*/
public static <T> List<T> subtractToList(Collection<T> coll1, Collection<T> coll2) {
if (isEmpty(coll1)) {
return ListUtil.empty();
}
if (isEmpty(coll2)) {
return ListUtil.list(true, coll2);
}
//将被交数用链表储存防止因为频繁扩容影响性能
final List<T> result = new LinkedList<>();
Set<T> set = new HashSet<>(coll2);
for (T t : coll1) {
if (false == set.contains(t)) {
result.add(t);
}
}
return result;
}
/**
* 判断指定集合是否包含指定值如果集合为空null或者空返回{@code false}否则找到元素返回{@code true}
*

View File

@ -54,6 +54,8 @@ public class RootAction implements Action {
response.write(file);
}
}
} else{
response.write(file);
}
}