我正在尝试检查地图中的值何时出现,但我不知道为什么containsValue()
没有正确检查它。
这是我的代码:
Map<String, String> usersMap = userAPI.getBuyersFromBUUPToRootMap(getParentBusinessUnitId());
//usersMap's [STDOUT] {super, root (rootSuper) - [EZMRootCmp]=3008, user, buyer A (buyer1) - [EZMBuyer]=1007, user, Obsvr (observer) - [EZMBuyer]=1006, user, Root (rootTest) - [EZMRootCmp]=3001, user, Test (test) - [EZMBuyer]=1001, zabuhab, Miguel (buyerAdmin1) - [EZMBuyer]=1008}
System.out.println(usersMap.values());
//[STDOUT] [3008, 1007, 1006, 3001, 1001, 1008]
System.out.println(usersMap.containsValue(getUserProfile().getUserId())); //[STDOUT] false
//getUserProfile().getUserId() [STDOUT] 1008
如您所见,getUserProfile().getUserId()
其值1008
在 Map 中,但它返回false
。
你知道为什么会这样吗?我该如何解决这种情况?我试图添加一个Long.valueOf(getUserProfile().getUserId())
;但它不断返回false
PS:我在 SO 中搜索了这样的问题,但对于这种情况并没有帮助
下面是我的完整代码:
UserAPI userAPI = ServiceLocator.getService(UserAPI.class);
Map<String, String> usersMap = userAPI.getBuyersFromBUUPToRootMap(getParentBusinessUnitId());
System.out.println(usersMap);
System.out.println("#######################");
System.out.println(usersMap.values());
System.out.println("##########valor para getAuctionHeaderDO().getPrimaryContact().getId() #############");
System.out.println(usersMap.containsValue(getAuctionHeaderDO().getPrimaryContact().getId()));
System.out.println("##########valor para getUserProfile().getUserId()#############");
System.out.println(getUserProfile().getUserId());
System.out.println(usersMap.containsValue(getUserProfile().getUserId()));
结果:
[STDOUT] {super, root (rootSuper) - [EZMRootCmp]=3008, user, buyer A (buyer1) - [EZMBuyer]=1007, user, Obsvr (observer) - [EZMBuyer]=1006, user, Root (rootTest) - [EZMRootCmp]=3001, user, Test (test) - [EZMBuyer]=1001, zabuhab, Miguel (buyerAdmin1) - [EZMBuyer]=1008}
[STDOUT] #######################
[STDOUT] [3008, 1007, 1006, 3001, 1001, 1008]
[STDOUT] ##########valor para getAuctionHeaderDO().getPrimaryContact().getId() #############
[STDOUT] false
[STDOUT] ##########valor para getUserProfile().getUserId()#############
[STDOUT] 1008
[STDOUT] false