我有一个Map getProperties,它返回{BUILDING=a,b,c},{NEW_BUILDING=a,b,c,d,e},{OLD_BUILDING=d,e}。
我想根据这个值在BUILDING、NEW_BUILDING和OLD_BUILDING之间切换。
我正在尝试这样的方法
return Optional.ofNullable(properties.get("BUILDING")).map(a -> {
if(a.contains(code)) {
return callMethod;
} else {
return null;
}
}).get();我想返回建筑,NEW_BUILDING和OLD_BUIDLING
发布于 2022-04-19 02:29:12
试试下面的代码:
Set<Map.Entry<String, Set<String>>> entries = properties.entrySet();
for (Map.Entry<String, Set<String>> entry : entries) {
Set<String> value = entry.getValue();
if (value.contains(code)) {
switch (entry.getKey()) {
case "BUILDING":
return callBuidingMethod;
case "OLD_BUILDING":
return callNewBuilding;
case "NEW_BUILDING":
return callOldBuilding;
default:
return null;
}
}
}https://stackoverflow.com/questions/71918818
复制相似问题