优化AnyValue.merge方法
This commit is contained in:
@@ -642,7 +642,7 @@ public final class Application {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------ 读取配置中心 ------------------------------------
|
//------------------------------------ 读取配置项 ------------------------------------
|
||||||
final AnyValue resources = config.getAnyValue("resources");
|
final AnyValue resources = config.getAnyValue("resources");
|
||||||
if (resources != null) {
|
if (resources != null) {
|
||||||
resourceFactory.register(RESNAME_APP_GRES, AnyValue.class, resources);
|
resourceFactory.register(RESNAME_APP_GRES, AnyValue.class, resources);
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import org.redkale.util.*;
|
|||||||
/**
|
/**
|
||||||
* 配置源Agent, 在init方法内需要实现读取配置信息,如果支持配置更改通知,也需要在init里实现监听
|
* 配置源Agent, 在init方法内需要实现读取配置信息,如果支持配置更改通知,也需要在init里实现监听
|
||||||
*
|
*
|
||||||
|
* 配置项优先级: 本地配置 < 配置中心 < 环境变量
|
||||||
|
*
|
||||||
*
|
*
|
||||||
* 详情见: https://redkale.org
|
* 详情见: https://redkale.org
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -27,6 +27,15 @@ public abstract class AnyValue {
|
|||||||
*/
|
*/
|
||||||
public static final String XML_TEXT_NODE_NAME = "";
|
public static final String XML_TEXT_NODE_NAME = "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* merge两节点是否覆盖的判断函数
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static interface MergeReplacePredicate {
|
||||||
|
|
||||||
|
public boolean test(String name, AnyValue val1, AnyValue val2);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可读写的AnyValue默认实现类
|
* 可读写的AnyValue默认实现类
|
||||||
*
|
*
|
||||||
@@ -167,12 +176,13 @@ public abstract class AnyValue {
|
|||||||
/**
|
/**
|
||||||
* 将另一个对象合并过来
|
* 将另一个对象合并过来
|
||||||
*
|
*
|
||||||
* @param node0 代合并对象
|
* @param node0 代合并对象
|
||||||
|
* @param predicate 判断是否覆盖的函数
|
||||||
*
|
*
|
||||||
* @return AnyValue
|
* @return AnyValue
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public DefaultAnyValue merge(AnyValue node0) {
|
public DefaultAnyValue merge(AnyValue node0, MergeReplacePredicate predicate) {
|
||||||
if (node0 == null) return this;
|
if (node0 == null) return this;
|
||||||
if (node0 == this) throw new IllegalArgumentException();
|
if (node0 == this) throw new IllegalArgumentException();
|
||||||
DefaultAnyValue node = (DefaultAnyValue) node0;
|
DefaultAnyValue node = (DefaultAnyValue) node0;
|
||||||
@@ -193,9 +203,11 @@ public abstract class AnyValue {
|
|||||||
for (AnyValue item : ns) {
|
for (AnyValue item : ns) {
|
||||||
if (item == null) continue;
|
if (item == null) continue;
|
||||||
if (en.value.parentArrayIndex == ((DefaultAnyValue) item).parentArrayIndex) {
|
if (en.value.parentArrayIndex == ((DefaultAnyValue) item).parentArrayIndex) {
|
||||||
item.merge(en.value);
|
if (predicate == null || predicate.test(en.name, en.value, item)) {
|
||||||
ok = true;
|
item.merge(en.value, predicate);
|
||||||
break;
|
ok = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
@@ -969,7 +981,19 @@ public abstract class AnyValue {
|
|||||||
*
|
*
|
||||||
* @return AnyValue
|
* @return AnyValue
|
||||||
*/
|
*/
|
||||||
public abstract AnyValue merge(AnyValue node);
|
public AnyValue merge(AnyValue node) {
|
||||||
|
return merge(node, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将另一个对象合并过来
|
||||||
|
*
|
||||||
|
* @param node 代合并对象
|
||||||
|
* @param predicate 判断是否覆盖的函数
|
||||||
|
*
|
||||||
|
* @return AnyValue
|
||||||
|
*/
|
||||||
|
public abstract AnyValue merge(AnyValue node, MergeReplacePredicate predicate);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 回调子节点
|
* 回调子节点
|
||||||
|
|||||||
Reference in New Issue
Block a user