AttributesMap implements Map<String, Object> { public AttributesMap filter(Set<String> keys) { final ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); for (Entry<String, Object> entry : entrySet()) { if (keys.contains(entry.getKey())) { builder.put(entry); } } return new AttributesMap(builder.build()); } private  AttributesMap(ImmutableMap<String, Object> values); static Builder newBuilder(); static AttributesMap empty(); String getString(String name); String getString(String name, String defaultValue); Long getNumber(String name); Long getNumber(String name, long defaultValue); Boolean getBoolean(String name); Boolean getBoolean(String name, boolean defaultValue); Class<?> getType(String name); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(Object o); @Override boolean containsValue(Object o); @Override Object get(Object o); @Override Object put(String s, Object o); @Override Object remove(Object o); @Override void putAll(Map<? extends String, ?> map); @Override void clear(); @Override Set<String> keySet(); @Override Collection<Object> values(); @Override Set<Entry<String, Object>> entrySet(); AttributesMap filter(Set<String> keys);  }
@Test public void testFilter() { assertEquals(map.entrySet(), map.filter(map.keySet()).entrySet()); assertTrue(map.filter(Sets.<String>newHashSet()).isEmpty()); }