cz.cuni.amis.utils.maps
Class AbstractLazyMap<KEY,VALUE>

java.lang.Object
  extended by cz.cuni.amis.utils.maps.AbstractLazyMap<KEY,VALUE>
Type Parameters:
KEY - KeyType
VALUE - ValueType
All Implemented Interfaces:
java.util.Map<KEY,VALUE>
Direct Known Subclasses:
AbstractLocalWorldView.LazyCompositeObjectMap

public abstract class AbstractLazyMap<KEY,VALUE>
extends java.lang.Object
implements java.util.Map<KEY,VALUE>

Abstract implementation of a lazy map. The values are created on-demand by the create method if they are not cached already. The keySet is kept updated however, only the values are lazy-generated. If you need to iterate over the map, but you don't actually need all the values, iterate over the keySet.


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
AbstractLazyMap()
           
AbstractLazyMap(java.util.Map<KEY,VALUE> baseMap)
           
AbstractLazyMap(java.util.Set<KEY> entryKeySet)
           
 
Method Summary
 void addKey(KEY key)
           
 void clear()
           
 void clearCache()
          manually clears the cached objects
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
protected abstract  VALUE create(java.lang.Object key)
          Creates the Mapped object based on its key.
 java.util.Set<java.util.Map.Entry<KEY,VALUE>> entrySet()
           
 VALUE get(java.lang.Object key)
           
 boolean isEmpty()
           
 java.util.Set<KEY> keySet()
           
 VALUE put(KEY key, VALUE value)
           
 void putAll(java.util.Map<? extends KEY,? extends VALUE> m)
           
 VALUE remove(java.lang.Object key)
           
 void setKeySet(java.util.Set<KEY> newKeySet)
           
 int size()
           
 java.util.Collection<VALUE> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

AbstractLazyMap

public AbstractLazyMap()

AbstractLazyMap

public AbstractLazyMap(java.util.Set<KEY> entryKeySet)

AbstractLazyMap

public AbstractLazyMap(java.util.Map<KEY,VALUE> baseMap)
Method Detail

create

protected abstract VALUE create(java.lang.Object key)
Creates the Mapped object based on its key. Every LazyMap must implement this.

Parameters:
key -
Returns:

addKey

public void addKey(KEY key)

clear

public void clear()
Specified by:
clear in interface java.util.Map<KEY,VALUE>

clearCache

public void clearCache()
manually clears the cached objects


containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<KEY,VALUE>

setKeySet

public void setKeySet(java.util.Set<KEY> newKeySet)

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<KEY,VALUE>

entrySet

public java.util.Set<java.util.Map.Entry<KEY,VALUE>> entrySet()
Specified by:
entrySet in interface java.util.Map<KEY,VALUE>

get

public VALUE get(java.lang.Object key)
Specified by:
get in interface java.util.Map<KEY,VALUE>

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<KEY,VALUE>

keySet

public java.util.Set<KEY> keySet()
Specified by:
keySet in interface java.util.Map<KEY,VALUE>

put

public VALUE put(KEY key,
                 VALUE value)
Specified by:
put in interface java.util.Map<KEY,VALUE>

putAll

public void putAll(java.util.Map<? extends KEY,? extends VALUE> m)
Specified by:
putAll in interface java.util.Map<KEY,VALUE>

remove

public VALUE remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<KEY,VALUE>

size

public int size()
Specified by:
size in interface java.util.Map<KEY,VALUE>

values

public java.util.Collection<VALUE> values()
Specified by:
values in interface java.util.Map<KEY,VALUE>