优化代码

dev
ZhouXY108 2024-05-28 09:35:04 +08:00
parent d3b19c6cb0
commit 9ccb12f956
2 changed files with 5 additions and 12 deletions

View File

@ -57,9 +57,7 @@ public abstract class AbstractMapWrapper<K, V, T extends AbstractMapWrapper<K, V
} }
public final T putAll(Map<? extends K, ? extends V> m) { public final T putAll(Map<? extends K, ? extends V> m) {
for (Entry<? extends K, ? extends V> entry : m.entrySet()) { m.forEach(this::put);
put(entry.getKey(), entry.getValue());
}
return getSelf(); return getSelf();
} }
@ -183,9 +181,7 @@ public abstract class AbstractMapWrapper<K, V, T extends AbstractMapWrapper<K, V
} }
public Builder<K, V, T> putAll(Map<? extends K, ? extends V> m) { public Builder<K, V, T> putAll(Map<? extends K, ? extends V> m) {
for (Entry<? extends K, ? extends V> entry : m.entrySet()) { m.forEach(this::put);
put(entry.getKey(), entry.getValue());
}
return this; return this;
} }

View File

@ -16,6 +16,7 @@
package xyz.zhouxy.plusone.commons.util; package xyz.zhouxy.plusone.commons.util;
import java.util.Arrays;
import java.util.function.Supplier; import java.util.function.Supplier;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
@ -37,17 +38,13 @@ public class PreconditionsExt {
public static <T, E extends Throwable> void checkAllNotNull(Iterable<T> values) throws E { public static <T, E extends Throwable> void checkAllNotNull(Iterable<T> values) throws E {
Preconditions.checkNotNull(values); Preconditions.checkNotNull(values);
for (T item : values) { values.forEach(Preconditions::checkNotNull);
Preconditions.checkNotNull(item);
}
} }
@SafeVarargs @SafeVarargs
public static <T, E extends Throwable> void checkAllNotNull(T... values) throws E { public static <T, E extends Throwable> void checkAllNotNull(T... values) throws E {
Preconditions.checkNotNull(values); Preconditions.checkNotNull(values);
for (T item : values) { Arrays.stream(values).forEach(Preconditions::checkNotNull);
Preconditions.checkNotNull(item);
}
} }
private PreconditionsExt() { private PreconditionsExt() {