org.zkoss.util
Class FilterMap<K,V>

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by org.zkoss.util.FilterMap<K,V>
All Implemented Interfaces:
Map<K,V>

public class FilterMap<K,V>
extends AbstractMap<K,V>

A map that allows the value to be evaluated before returning (so called filtering). For example, if you allow the value to have EL expressions and want to evaluate it before returning, then you could implement FilterMap.Filter to evaluate the value when the value is retrieved. Then, encapsulate the original map with this class. For example,


 return new FilterMap(map,
     new FilterMap.Filter() {
         public Object filter(Object key, Object value) {
             //evaluate the value and return the result
         }
     });

Notice that this map is readonly, and it is thread-safe if the give map and the filter are both thread safe.

Since:
5.0.7
Author:
tomyeh

Nested Class Summary
static interface FilterMap.Filter<V>
          Filters the given value (to evaluate when the value is retrieved).
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
FilterMap(Map<K,V> map, FilterMap.Filter<V> filter)
           
 
Method Summary
 boolean containsKey(Object key)
           
 Set<Map.Entry<K,V>> entrySet()
           
 boolean equals(Object o)
           
 V get(Object key)
           
 Map<K,V> getOrigin()
          Returns the original map being filtered.
 int hashCode()
           
 String toString()
           
 
Methods inherited from class java.util.AbstractMap
clear, clone, containsValue, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FilterMap

public FilterMap(Map<K,V> map,
                 FilterMap.Filter<V> filter)
Method Detail

getOrigin

public Map<K,V> getOrigin()
Returns the original map being filtered. That is, the map passed to the constructor.


get

public V get(Object key)
Specified by:
get in interface Map<K,V>
Overrides:
get in class AbstractMap<K,V>

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<K,V>
Overrides:
containsKey in class AbstractMap<K,V>

entrySet

public Set<Map.Entry<K,V>> entrySet()
Specified by:
entrySet in interface Map<K,V>
Specified by:
entrySet in class AbstractMap<K,V>

toString

public String toString()
Overrides:
toString in class AbstractMap<K,V>

hashCode

public int hashCode()
Specified by:
hashCode in interface Map<K,V>
Overrides:
hashCode in class AbstractMap<K,V>

equals

public boolean equals(Object o)
Specified by:
equals in interface Map<K,V>
Overrides:
equals in class AbstractMap<K,V>


Copyright © 2014. All rights reserved.