4
是否有任何優雅的方法可以將密鑰不在給定列表中的哈希映射中?我真的很感激,如果有人會給一個代碼片段。如果不是我可能會做這樣的事情:如果密鑰不在列表中,則從HashMap中移除
public HashMap<Integer, NameAndID> getTasksWithWordInFormula(Session session,
HashMap<Integer, NameAndID> taskMap, int sectionID, int topicID, int wordID) {
@SuppressWarnings("unchecked")
List<Integer> goodList = session.createCriteria(Frbw.class)
.add(Restrictions.in("id.formulaId", taskMap.keySet()))
.add(Restrictions.eq("sectionId", sectionID))
.add(Restrictions.eq("topicId", topicID))
.add(Restrictions.eq("wordId", wordID))
.setProjection(Projections.projectionList()
.add(Projections.property("id.formulaId")))
.setCacheable(true).setCacheRegion("query.DBParadox").list();
ArrayList<Integer> toRemove = new ArrayList<Integer>();
for (Integer formulaID : taskMap.keySet())
if (!goodList.contains(formulaID))
toRemove.add(formulaID);
for (Integer formulaID : toRemove)
taskMap.remove(formulaID);
return taskMap;
}
哇,剛纔我問:) – serge
這是否工作'值()的''代替的keySet()'? – Populus