From 038d07f3376795a8bc69a3dda31f2aba481e2bf3 Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 11 Aug 2021 10:37:06 +0800 Subject: [PATCH] =?UTF-8?q?BeanRelation=E5=A2=9E=E5=8A=A0lastList=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E6=8C=87=E5=AE=9A=E4=B8=AD=E6=96=AD=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E6=B3=95=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cn/estsh/i3plus/pojo/aps/common/BeanRelation.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/common/BeanRelation.java b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/common/BeanRelation.java index 4dcf88c..9057dad 100644 --- a/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/common/BeanRelation.java +++ b/modules/i3plus-pojo-aps/src/main/java/cn/estsh/i3plus/pojo/aps/common/BeanRelation.java @@ -204,10 +204,17 @@ public class BeanRelation { public static List lastList(BaseBean bean, Enum... holders) { List result = new ArrayList<>(); - lastListImpl(result, bean, bean, holders, 0); + lastListImpl(result, bean, bean, null, holders, 0); return result; } - private final static boolean lastListImpl(List result, BaseBean bean, BaseBean self, + + public static List lastList(BaseBean bean, Predicate pred, Enum... holders) { + List result = new ArrayList<>(); + lastListImpl(result, bean, bean, pred, holders, 0); + return result; + } + + private final static boolean lastListImpl(List result, BaseBean bean, BaseBean self, Predicate pred, Enum[] holders, int index) { if (index >= holders.length) { if (self == bean) { @@ -215,15 +222,18 @@ public class BeanRelation { } index = 0; self = bean; + if (pred != null && pred.test((T)bean)) { + return true; + } } boolean bNotLast = true; List nextBeans = list(bean, holders[index]); for (BaseBean nextBean : nextBeans) { - if (lastListImpl(result, nextBean, self, holders, index + 1)) { + if (lastListImpl(result, nextBean, self, pred, holders, index + 1)) { result.add((T)nextBean); - bNotLast = false; } + bNotLast = false; } return index == 0 && bNotLast; }