java 8 地图可选<String, Set<String>>

java 8 Optional with Map<String, Set<String>>

我有一个 Map getProperties,其中 returns {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();

我想return基于BUILDING,NEW_BUILDING和OLD_BUIDLING

试试下面的代码:

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;
                }
            }
        }