gpt4 book ai didi

java - org.hamcrest.Matchers 用于同时匹配对象的不同属性

转载 作者:搜寻专家 更新时间:2023-10-31 19:49:41 25 4
gpt4 key购买 nike

我正在尝试通过 org.hamcrest.Matchers 匹配对象的两个不同属性。在这里:

List<LeaveApply> leaveApplyList = Lambda.select(
allLeaveApplyList,
Matchers.allOf(
Lambda.having(
Lambda.on(LeaveApply.class).getUser().getId(),
Matchers.equalTo(userId)),
Lambda.having(
Lambda.on(LeaveApply.class).getDate(),
Matchers.allOf(
Matchers.greaterThanOrEqualTo(fromDate),
Matchers.lessThanOrEqualTo(toDate)))
)
);

它给出了一个 LeaveApply 对象列表,其用户 ID 等于给定 ID,日期小于或等于 to-date 且大于或等于 from-date。这是工作。我想知道匹配不同属性字段的方法是否正确?

最佳答案

据我所知,它应该可以工作。您可以进行两项改进:使用静态导入使其更具可读性,并使用 having(...).and(...) 而不是使用 allOf:

import static ch.lambdaj.Lambda.*;
import static org.hamcrest.Matchers.*;

List<LeaveApply> leaveApplyList = select(allLeaveApplyList, having(on(LeaveApply.class).getUser().getId(), equalTo(userId)).and(on(LeaveApply.class).getDate(), allOf(greaterThanOrEqualTo(fromDate), lessThanOrEqualTo(toDate)))));

关于java - org.hamcrest.Matchers 用于同时匹配对象的不同属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5672455/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com