Is there any elegant way to remove an item from a hash map where the key is not listed in the specified list of items? I would really appreciate if anyone would give a piece of code. If it werenβt for me, I probably would have done something like this:
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 source
share