我有这个代码。所以我不明白为什么 删除哈希图中的旧数据-result.put(name,localMap)
class FilterServers {
// In this class, we filter our servers on our key word
static Map <String, Map <String, String>>
getValues(String keyWord, List <Map <String, Map <String, Monitor.Status>>> servers) {
Map <String, Map <String, String>> result = new ConcurrentHashMap<>();
Pattern pattern = Pattern.compile(keyWord, Pattern.CASE_INSENSITIVE);
Matcher keyMatcher;
Matcher valueMatcher;
for (Map <String, Map<String, Monitor.Status>> server : servers) {
Map <String, String> localMap = new ConcurrentHashMap<>();
boolean haveResult = false;
Set <String> serverName = server.keySet();
Optional <String> optional = serverName.stream().findAny();
String name = optional.get();
for (Map <String, Monitor.Status> subServer : server.values()) {
for (Map.Entry<String, Monitor.Status> entry: subServer.entrySet()) {
Monitor.Status targetValue = entry.getValue();
String targetKey = entry.getKey();
keyMatcher = pattern.matcher(targetKey);
valueMatcher = pattern.matcher(targetValue.getProblem());
if (keyMatcher.find() || valueMatcher.find()) {
localMap.put(targetKey, targetValue.getProblem());
haveResult = true;
}
}
}
if(haveResult){
result.put(name, localMap);
}
}
return result;
}
}
答案 0 :(得分:0)
我发现键(名称)中的字符串相同。并且由于哈希映射会摩擦已经具有相同键的旧值,因此将它们从我那里删除了。我只是交换了键和值