imbajin commented on code in PR #105:
URL:
https://github.com/apache/incubator-hugegraph-commons/pull/105#discussion_r960716609
##########
hugegraph-common/src/main/java/com/baidu/hugegraph/config/OptionChecker.java:
##########
@@ -32,88 +33,55 @@
public final class OptionChecker {
public static <O> Predicate<O> disallowEmpty() {
- return new Predicate<O>() {
- @Override
- public boolean apply(@Nullable O o) {
- if (o == null) {
- return false;
- }
- if (o instanceof String) {
- return StringUtils.isNotBlank((String) o);
- }
- if (o.getClass().isArray() && (Array.getLength(o) == 0)) {
- return false;
- }
- if (o instanceof Iterable &&
- !((Iterable<?>) o).iterator().hasNext()) {
- return false;
- }
- return true;
+ return o -> {
+ if (o == null) {
+ return false;
}
+ if (o instanceof String) {
+ return StringUtils.isNotBlank((String) o);
+ }
+ if (o.getClass().isArray() && (Array.getLength(o) == 0)) {
+ return false;
+ }
+ return !(o instanceof Iterable) || ((Iterable<?>)
o).iterator().hasNext();
};
}
@SuppressWarnings("unchecked")
public static <O> Predicate<O> allowValues(O... values) {
- return new Predicate<O>() {
- @Override
- public boolean apply(@Nullable O o) {
- return o != null && Arrays.asList(values).contains(o);
- }
- };
+ return o -> o != null && Arrays.asList(values).contains(o);
}
@SuppressWarnings("unchecked")
public static <O> Predicate<List<O>> inValues(O... values) {
- return new Predicate<List<O>>() {
- @Override
- public boolean apply(@Nullable List<O> o) {
- return o != null && Arrays.asList(values).containsAll(o);
- }
- };
+ return o -> o != null && new
HashSet<>(Arrays.asList(values)).containsAll(o);
Review Comment:
use hashset to speed up (List.containsAll perf is poor)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]