Environment增加forEach方法

This commit is contained in:
Redkale
2022-12-12 09:36:22 +08:00
parent 4a91e6eb18
commit 164dd3d8ea

View File

@@ -3,7 +3,7 @@
package org.redkale.util;
import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.*;
/**
* 环境变量, 只读版Properties
@@ -47,6 +47,11 @@ public class Environment implements java.io.Serializable {
properties.forEach((BiConsumer) action);
}
public void forEach(Predicate<String> predicate, BiConsumer<String, String> action) {
properties.entrySet().stream().filter(en -> predicate.test(en.getKey().toString()))
.forEach(en -> action.accept(en.getKey().toString(), en.getValue() == null ? null : en.getValue().toString()));
}
public boolean getBooleanProperty(String key) {
String val = properties.getProperty(key);
return "true".equalsIgnoreCase(val) || "1".equalsIgnoreCase(val);