ScopedMap implements ScopeSubscriber, Map<K, V> { public Collection<V> values() { final Collection<Stack<ScopedMapItem<V>>> stacks = map.values(); final Collection<V> values = new java.util.ArrayList<V>(); for (Stack<ScopedMapItem<V>> stack : stacks) { if (!stack.empty()) { final ScopedMapItem<V> item = stack.peek(); final V value = item.getValue(); values.add(value); } } return values; } ScopedMap(final ScopeObserver scopeObserver); void close(); void enterScope(final Scope previous, final Scope next); void exitScope(final Scope previous, final Scope next); int size(); boolean isEmpty(); boolean containsKey(final Object key); boolean containsValue(final Object value); V get(final Object key); V put(final K key, final V value); V remove(final Object key); void putAll(final Map<? extends K, ? extends V> t); void clear(); Set<K> keySet(); Collection<V> values(); Set<Map.Entry<K, V>> entrySet(); @Override boolean equals(final Object o); @Override int hashCode();  }
@Test public void testValues() { final ScopedMap<String, String> map = new ScopedMap<String, String>(observer); Assert.assertNull(map.put("key1", "value1")); Assert.assertEquals("value1", map.get("key1")); Assert.assertNull(map.put("key2", "value2")); Assert.assertEquals("value1", map.get("key1")); Assert.assertEquals("value2", map.get("key2")); final Collection<String> values1 = map.values(); Assert.assertEquals(2, values1.size()); Assert.assertTrue(values1.contains("value1")); Assert.assertTrue(values1.contains("value2")); map.enterScope(Scope.SESSION, Scope.DOCUMENT); Assert.assertEquals("value1", map.get("key1")); Assert.assertEquals("value2", map.get("key2")); final Collection<String> values2 = map.values(); Assert.assertEquals(2, values2.size()); Assert.assertTrue(values2.contains("value1")); Assert.assertTrue(values2.contains("value2")); Assert.assertEquals("value2", map.put("key2", "value3")); Assert.assertEquals("value1", map.get("key1")); Assert.assertEquals("value3", map.get("key2")); final Collection<String> values3 = map.values(); Assert.assertEquals(2, values3.size()); Assert.assertTrue(values3.contains("value1")); Assert.assertTrue(values3.contains("value3")); map.exitScope(Scope.DOCUMENT, Scope.SESSION); Assert.assertEquals("value1", map.get("key1")); Assert.assertEquals("value2", map.get("key2")); final Collection<String> values4 = map.values(); Assert.assertEquals(2, values4.size()); Assert.assertTrue(values4.contains("value1")); Assert.assertTrue(values4.contains("value2")); }