From 164dd3d8eab45ee1f74cad023120bd862a769174 Mon Sep 17 00:00:00 2001 From: Redkale Date: Mon, 12 Dec 2022 09:36:22 +0800 Subject: [PATCH] =?UTF-8?q?Environment=E5=A2=9E=E5=8A=A0forEach=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/redkale/util/Environment.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/redkale/util/Environment.java b/src/main/java/org/redkale/util/Environment.java index 0807ec022..5ffd6a432 100644 --- a/src/main/java/org/redkale/util/Environment.java +++ b/src/main/java/org/redkale/util/Environment.java @@ -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 predicate, BiConsumer 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);