!758 优化Opt.ofEmptyAble(), 避免无意义的判断;

Merge pull request !758 from emptypoint/v6-Opt-update
This commit is contained in:
Looly 2022-08-19 00:51:11 +00:00 committed by Gitee
commit 3da46bbc02
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -31,7 +31,6 @@ import cn.hutool.core.text.StrUtil;
import java.util.Objects;
import java.util.Optional;
import java.util.Collection;
import java.util.Collections;
import java.util.NoSuchElementException;
import java.util.function.Consumer;
import java.util.function.Function;
@ -109,7 +108,7 @@ public class Opt<T> {
* @since 5.7.17
*/
public static <T, R extends Collection<T>> Opt<R> ofEmptyAble(final R value) {
return CollUtil.isEmpty(value) || Objects.equals(Collections.frequency(value, null), value.size()) ? empty() : new Opt<>(value);
return CollUtil.isEmpty(value) || CollUtil.getFirstNoneNull(value) == null ? empty() : new Opt<>(value);
}
/**