LinkedHashMap<K, V> filtered = new LinkedHashMap<K, V>(map);
Iterator<Map.Entry<K, V>> iterator = filtered.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry entry = iterator.next();
HasFacets item = entry.getKey() instanceof HasFacets ? (HasFacets) entry.getKey() : entry.getValue() instanceof HasFacets ? (HasFacets) entry.getValue() : null;
if (item != null && !filter.accept(item)) {
iterator.remove();
}
}