From d6042d142e94a5262142eeb3f4ceb0e7dbc51dce Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Mon, 31 Aug 2020 21:07:50 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BC=98=E5=8C=96]=E5=A2=9E=E5=8A=A0org.redka?= =?UTF-8?q?le.service.RetLabel.RetInfoTransfer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/service/RetLabel.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/org/redkale/service/RetLabel.java b/src/org/redkale/service/RetLabel.java index 094d6540e..0de46725f 100644 --- a/src/org/redkale/service/RetLabel.java +++ b/src/org/redkale/service/RetLabel.java @@ -10,6 +10,7 @@ import static java.lang.annotation.ElementType.*; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.reflect.*; import java.util.*; +import java.util.function.BiFunction; /** * 用于定义错误码的注解
@@ -42,10 +43,16 @@ public @interface RetLabel { RetLabel[] value(); } + public static interface RetInfoTransfer extends BiFunction { + + } + public static abstract class RetLoader { public static Map> loadMap(Class clazz) { final Map> rets = new HashMap<>(); + ServiceLoader loader = ServiceLoader.load(RetInfoTransfer.class); + RetInfoTransfer func = loader.findFirst().orElse(null); for (Field field : clazz.getFields()) { if (!Modifier.isStatic(field.getModifiers())) continue; if (field.getType() != int.class) continue; @@ -59,7 +66,7 @@ public @interface RetLabel { continue; } for (RetLabel info : infos) { - rets.computeIfAbsent(info.locale(), (k) -> new HashMap<>()).put(value, info.value()); + rets.computeIfAbsent(info.locale(), (k) -> new HashMap<>()).put(value, func == null ? info.value() : func.apply(value, info.value())); } } return rets;