mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-06 21:58:03 +08:00
CollUtil.forEach 增加null 判断
This commit is contained in:
parent
1deed5d9cf
commit
0e31ba2fc5
@ -2560,6 +2560,9 @@ public class CollUtil {
|
|||||||
* @since 5.4.7
|
* @since 5.4.7
|
||||||
*/
|
*/
|
||||||
public static <T> void forEach(Iterable<T> iterable, Consumer<T> consumer) {
|
public static <T> void forEach(Iterable<T> iterable, Consumer<T> consumer) {
|
||||||
|
if(iterable == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
forEach(iterable.iterator(), consumer);
|
forEach(iterable.iterator(), consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2571,6 +2574,9 @@ public class CollUtil {
|
|||||||
* @param consumer {@link Consumer} 遍历的每条数据处理器
|
* @param consumer {@link Consumer} 遍历的每条数据处理器
|
||||||
*/
|
*/
|
||||||
public static <T> void forEach(Iterator<T> iterator, Consumer<T> consumer) {
|
public static <T> void forEach(Iterator<T> iterator, Consumer<T> consumer) {
|
||||||
|
if(iterator == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
consumer.accept(iterator.next(), index);
|
consumer.accept(iterator.next(), index);
|
||||||
@ -2586,6 +2592,9 @@ public class CollUtil {
|
|||||||
* @param consumer {@link Consumer} 遍历的每条数据处理器
|
* @param consumer {@link Consumer} 遍历的每条数据处理器
|
||||||
*/
|
*/
|
||||||
public static <T> void forEach(Enumeration<T> enumeration, Consumer<T> consumer) {
|
public static <T> void forEach(Enumeration<T> enumeration, Consumer<T> consumer) {
|
||||||
|
if(enumeration == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (enumeration.hasMoreElements()) {
|
while (enumeration.hasMoreElements()) {
|
||||||
consumer.accept(enumeration.nextElement(), index);
|
consumer.accept(enumeration.nextElement(), index);
|
||||||
@ -2603,6 +2612,9 @@ public class CollUtil {
|
|||||||
* @param kvConsumer {@link KVConsumer} 遍历的每条数据处理器
|
* @param kvConsumer {@link KVConsumer} 遍历的每条数据处理器
|
||||||
*/
|
*/
|
||||||
public static <K, V> void forEach(Map<K, V> map, KVConsumer<K, V> kvConsumer) {
|
public static <K, V> void forEach(Map<K, V> map, KVConsumer<K, V> kvConsumer) {
|
||||||
|
if(map == null){
|
||||||
|
return;
|
||||||
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Entry<K, V> entry : map.entrySet()) {
|
for (Entry<K, V> entry : map.entrySet()) {
|
||||||
kvConsumer.accept(entry.getKey(), entry.getValue(), index);
|
kvConsumer.accept(entry.getKey(), entry.getValue(), index);
|
||||||
|
Loading…
Reference in New Issue
Block a user